> Discover all available pages from the documentation index: https://mastra.ai/llms.txt

# Connections

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.

- [**Model Context Protocol (MCP)**](https://mastra.ai/docs/connections/mcp): Connect agents to external tools and resources, or expose Mastra agents, tools, workflows, prompts, and resources to MCP-compatible systems.
- [**Agent-to-Agent (A2A)**](https://mastra.ai/docs/connections/a2a): Expose or consume remote agents across service, framework, vendor, and language boundaries.
- [**Agent Client Protocol (ACP)**](https://mastra.ai/docs/connections/acp): Run compatible coding-agent processes, such as Claude Code, Cline, or OpenCode, as Mastra tools or subagents.
- [**SDK agents**](https://mastra.ai/docs/connections/sdk-agents): Register Claude, Cursor, or OpenAI SDK-backed agents while the provider SDK retains control of the runtime, tools, permissions, and agent loop.

## 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 started

Start with the boundary you need to cross. Use [A2A](https://mastra.ai/docs/connections/a2a) for remote agent endpoints, [ACP](https://mastra.ai/docs/connections/acp) for coding-agent processes, [SDK agents](https://mastra.ai/docs/connections/sdk-agents) for provider-owned runtimes, or [MCP](https://mastra.ai/docs/connections/mcp) for tools and resources.

**A2A**:

```typescript
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)
```

**ACP**:

```typescript
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)
```

**SDK agents**:

```typescript
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)
```

**MCP**:

```typescript
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()
}
```