createACPTool()
The createACPTool() function creates a Mastra tool that sends a task string to an Agent Client Protocol (ACP)-compatible coding agent and returns the final ACP response as output. Use it when a parent agent should decide when to call the ACP agent as a tool.
If you want to register the ACP agent as a Mastra subagent instead, use the AcpAgent class.
Usage exampleDirect link to Usage example
Create a code editing tool and register it on a parent agent:
import { createACPTool } from '@mastra/acp'
import { Agent } from '@mastra/core/agent'
const codeAgentTool = createACPTool({
id: 'code-agent',
description: 'Use an ACP-compatible coding agent to inspect and edit code',
command: 'acp-agent',
args: ['--stdio'],
cwd: process.cwd(),
})
export const codeSupervisor = new Agent({
id: 'code-supervisor',
name: 'Code Supervisor',
instructions: 'Use the code-agent tool when a task requires repository inspection or code edits.',
model: 'openai/gpt-5.5',
tools: {
codeAgentTool,
},
})
ParametersDirect link to Parameters
id:
description:
command:
args?:
env?:
cwd?:
session?:
initialize?:
authMethodId?:
persistSession?:
onPermissionRequest?:
workspace?:
model?:
Input schemaDirect link to Input schema
task:
Output schemaDirect link to Output schema
output:
Suspend and resume schemaDirect link to Suspend and resume schema
createACPTool() defines suspend and resume schemas for permission request payloads. Permission decisions are returned through onPermissionRequest; by default, @mastra/acp selects the first option returned by the ACP agent, or cancels when no option is available.
Suspend payloadDirect link to Suspend payload
permissionRequest:
Resume payloadDirect link to Resume payload
optionId?:
outcome?:
Session lifecycleDirect link to Session lifecycle
Each tool execution creates an ACP connection, starts the configured command, initializes the ACP client, creates an ACP session, and sends the task with ACP session/prompt.
By default, persistSession is true for the ACP connection created during tool execution. Set persistSession: false when the ACP process should stop as soon as that prompt completes.
Use AcpAgent when you need a reusable ACP subagent instance with explicit session lifecycle control across calls.
Permission handlingDirect link to Permission handling
ACP agents may ask the client to choose a permission option before they continue. By default, @mastra/acp selects the first option returned by the ACP agent, or cancels when no option is available.
Pass onPermissionRequest to inspect the request and return your own permission response:
import { createACPTool } from '@mastra/acp'
export const codeAgentTool = createACPTool({
id: 'code-agent',
description: 'Use an ACP-compatible coding agent',
command: 'acp-agent',
args: ['--stdio'],
async onPermissionRequest(request) {
const allowOption = request.options.find(option => option.name === 'Allow')
if (!allowOption) {
return { outcome: { outcome: 'cancelled' } }
}
return {
outcome: {
outcome: 'selected',
optionId: allowOption.optionId,
},
}
},
})
Use this callback to enforce local policy, inspect the permission title, or route the decision to your own approval flow.