一声棒喝,本不立文字
偏要著録,已是二义

X · 研究者一手

@_philschmid 如何在你的 AI Agents 中正确使用 MCP servers

@_philschmid How to correctly use MCP servers with your AI Agents

二〇二六年五月九日 · 英文原文

文章说明 MCP servers 未失效,但盲目启用会扩大 context、增加成本并降低性能。提出两种使用模式:Inline Tool Injection 通过 prompt 中 @github、@slack 等 @mention 按需注入 tools;Subagent MCP Servers 在 subagents 配置中声明 MCP servers,并用 allowed_tools 限定最小权限,适用于固定依赖 GitHub、Zendesk 等工具的场景。

MCP servers 并没有死。但盲目启用它们会让你的 context 膨胀,导致成本更高、性能更差。不同于 Agent Skills,MCP servers 默认不自带 progressive disclosure。你需要自行选择当前任务所需的 tools。下面是两种已验证的模式,用于正确使用 MCP servers 并避免膨胀。

1. 显式 MCP Servers:Inline Tool Injection

MCP servers 保持 opt-in。Servers 在你的 prompt 中通过 @mention 引用,agent 会在 model request 之前解析、获取并注入这些 tools。

在 prompt 中写 @github 或 @slack 会触发 agent:

除非被请求,否则什么都不会加载。tool surface 保持很小。

适用场景:MCP 使用是偶发的、由用户驱动的。有人提出一个需要 Slack 或 GitHub 数据的问题,他们 @mention 对应 server,它只会为这次 request 被拉取进来。这样可以降低成本,并避免在不需要外部集成的任务中引入 tool 噪音。

2. Subagent MCP Servers

MCP servers 在 subagents 定义中声明,并在运行时自动可用,同时可用的还有 read_file 或 bash 等 native tools。

每个 subagent 都有自己的配置,用来声明其 model、tools……以及可选的 MCP servers。你可以使用 allowed_tools 将 MCP servers 限定到特定 tools。

main agent 注册 subagents。被调用时,每个 subagent 会连接到它声明的 MCP servers,并将这些 tools 与 native tools 合并。

allowed_tools 让你无需 fork MCP server,就能实现最小权限范围控制。

适用场景:use case 决定所需 tools。code review agent 总是需要 GitHub,support agent 总是需要 Zendesk。MCP servers 是 agent 身份的一部分,而不是用户每次 request 选择加入的东西。allowed_tools 让每个 agent 只限定在它实际需要的范围内。

译自 X · 研究者一手 · 录于 二〇二六年五月九日