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 exampleUsage 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.6-sol',
tools: {
codeAgentTool,
},
})
ParametersParameters的直接链接
id:
description:
command:
args?:
env?:
cwd?:
session?:
cwd or process.cwd() and an empty MCP server list.initialize?:
authMethodId?:
persistSession?:
false to stop the process after each prompt completes.onPermissionRequest?:
createClient?:
extMethod and extNotification handlers.workspace?:
createACPTool() passes the current Mastra workspace from the execution context when one is available; otherwise the ACP connection falls back to a local filesystem workspace. Use AcpAgent when you need to provide an explicit workspace instance.model?:
session/set_model method.Input schemaInput schema的直接链接
task:
Output schemaOutput schema的直接链接
output:
Suspend and resume schemaSuspend 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 payloadSuspend payload的直接链接
permissionRequest:
Resume payloadResume payload的直接链接
optionId?:
outcome: "selected".outcome?:
Session lifecycleSession lifecycle的直接链接
Each tool execution creates an ACP connection and starts the configured command. It initializes the ACP client and creates an ACP session before sending 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 handlingPermission 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 or inspect the permission title. It can also route the decision to your own approval flow.
Extension methodsExtension methods的直接链接
Some ACP agents call custom extension methods on the client, outside the standard ACP request set. The default client rejects unknown methods with a "Method not found" error, which can abort the agent's turn.
Pass createClient to extend or replace the default client. The callback receives the default client and returns the client used for the connection:
import { createACPTool } from '@mastra/acp'
export const codeAgentTool = createACPTool({
id: 'code-agent',
description: 'Use an ACP-compatible coding agent',
command: 'acp-agent',
args: ['--stdio'],
createClient: defaultClient =>
Object.assign(defaultClient, {
async extMethod(method: string, params: Record<string, unknown>) {
return {}
},
async extNotification(method: string, params: Record<string, unknown>) {},
}),
})
Return a fully custom Client implementation when you need to change the standard handlers as well. The Client type is re-exported from @mastra/acp.