Connections overview
Connections let Mastra work with remote agents, coding agents, provider software development kit (SDK) runtimes, and external tools and resources. Choose a connection type based on which system owns the agent runtime and what you need to exchange.
- Agent-to-Agent (A2A): Expose or consume remote agents across service, framework, vendor, and language boundaries.
- Agent Client Protocol (ACP): Run compatible coding-agent processes as Mastra tools or subagents.
- SDK agents: Register Claude, Cursor, or OpenAI SDK-backed agents while the provider SDK retains control of the runtime, tools, permissions, and agent loop.
- Model Context Protocol (MCP): Connect agents to external tools and resources, or expose Mastra agents, tools, workflows, prompts, and resources to MCP-compatible systems.
When to use connectionsDirect link to When to use connections
Use connections when you need to:
- Delegate work to an agent running in another service or runtime.
- Run a coding agent against a project workspace.
- Add a provider-native agent without replacing its SDK runtime or agent loop.
- Connect agents to external tools and resources or publish Mastra capabilities to other systems.
Get startedDirect link to Get started
Start with the boundary you need to cross. Use A2A for remote agent endpoints, ACP for coding-agent processes, SDK agents for provider-owned runtimes, or MCP for tools and resources.
- A2A
- ACP
- SDK agents
- MCP
import { A2AAgent } from '@mastra/core/a2a'
const agent = new A2AAgent({
url: 'https://agent.example.com/.well-known/agent-card.json',
})
const result = await agent.generate('Summarize the latest report')
console.log(result.text)
import { AcpAgent } from '@mastra/acp'
const agent = new AcpAgent({
id: 'coding-agent',
description: 'Inspects and edits code',
command: 'claude',
args: ['--acp'],
persistSession: false,
})
const result = await agent.generate('Review this project')
console.log(result.text)
import { OpenAISDKAgent } from '@mastra/openai'
const agent = new OpenAISDKAgent({
id: 'openai-agent',
description: 'Answers project questions',
sdkOptions: {
name: 'Project assistant',
model: 'gpt-5',
},
})
const result = await agent.generate('Explain agent loops in one sentence')
console.log(result.text)
import { MCPClient } from '@mastra/mcp'
const client = new MCPClient({
id: 'wikipedia-client',
servers: {
wikipedia: {
command: 'npx',
args: ['-y', 'wikipedia-mcp'],
},
},
})
try {
const tools = await client.listTools()
console.log(Object.keys(tools))
} finally {
await client.disconnect()
}