跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

Connections

Connections 让 Mastra 能够与远程 agents、编码 agents、提供器软件开发工具包(SDK)运行时以及外部工具和资源协作。请根据哪个系统拥有 agent 运行时以及你需要交换什么来选择合适的连接类型。

  • Model Context Protocol (MCP):将 agents 连接到外部工具和资源,或将 Mastra agents、工具、workflows、提示词和资源暴露给兼容 MCP 的系统。
  • Agent-to-Agent (A2A):跨服务、框架、供应商和语言边界暴露或使用远程 agents。
  • Agent Client Protocol (ACP):将兼容的编码 agent 进程(例如 Claude Code、Cline 或 OpenCode)作为 Mastra 工具或 subagents 运行。
  • SDK agents:注册由 Claude、Cursor 或 OpenAI SDK 支持的 agents,同时由提供器 SDK 保留对运行时、工具、权限和 agent 循环的控制。

何时使用 connections
何时使用 connections的直接链接

在以下情况下使用 connections:

  • 将工作委派给运行在另一个服务或运行时中的 agent。
  • 针对项目 workspace 运行编码 agent。
  • 添加提供器原生 agent,而不替换其 SDK 运行时或 agent 循环。
  • 将 agents 连接到外部工具和资源,或向其他系统发布 Mastra 能力。

开始使用
开始使用的直接链接

从你需要跨越的边界开始。远程 agent 端点使用 A2A,编码 agent 进程使用 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)
On this page