April 22, 2026 Agents

使用 MCP 到达生产系统的构建Agent

Agent的作用取决于它们能够到达的系统。团队倾向于采用三种方法将其连接到外部系统:直接 API 调用、CLI 和 MCP。这篇文章列出了每种方法的适合位置、为什么生产Agent倾向于登陆 MCP 以及有效构建这些集成的模式。

将Agent连接到外部系统

我们通常会看到将Agent连接到外部系统的三种路径:直接 API 调用、CLI 和 MCP。每个都在某个地方有意义,具体取决于您正在构建的内容。关键区别在于Agent和服务之间是否存在公共层,以及该层的覆盖范围。

直接拨打 API

Agent直接调用您的 API - 通过编写在代码执行沙箱内发出 HTTP 请求的代码,或通过通用函数调用工具。这是大多数团队开始的地方,对于一个Agent与一项服务通信,或者少量不需要跨Agent平台重用的集成来说,它工作得很好。挑战开始大规模出现。由于Agent和服务之间没有公共层,每个Agent-服务对都成为具有自己的身份验证处理、工具描述和边缘情况的定制集成,即 M×N 集成问题。

命令行界面 (CLI)

Agent在 shell 中运行您的命令行工具。这是快速、轻量级的,并且依赖于预先存在的工具。它非常适合本地环境和沙盒容器——任何有文件系统和 shell 的地方。这提供了一个公共层,但很薄。 CLI 在到达不公开容器的移动、Web 或云托管平台时遇到了严格限制,并且身份验证由 CLI 自己的机制(通常是磁盘上的凭证文件)处理。这最适合本地环境中快速、宽松的集成。

Model Context Protocol (MCP)

MCP 提供公共层作为协议。该Agent连接到一个服务器,该服务器公开系统的功能,并具有标准化的身份验证、发现和丰富的语义。一台远程服务器可以在任何部署环境中到达任何兼容的客户端(Claude、ChatGPT、Cursor、VS Code 等)。

它需要更多的前期投资。回报是集成是可移植的,并提供功能丰富的Agent集成所需的语义。

生产Agent在云端运行

生产Agent越来越多地在云中运行,因此它们可以连续扩展和运营。他们需要访问的系统也是云托管的:您的数据所在、工作被跟踪以及基础设施运行的地方。通常这些系统是远程的并且支持身份验证,其中 MCP 提供公共层。

我们已经在采用中看到了这一点。 MCP SDK 的每月下载量最近超过了 3 亿次,高于年初的 1 亿次,在企业和流行Agent平台中得到了广泛采用。每天都有数百万人使用 MCP 和 Claude,该协议支撑着我们最近发布的大部分内容,包括 Claude Cowork 、 Claude Managed Agents 和 Claude Code 中的通道。随着 MCP 继续支持生产Agent系统,我们正在分享构建这些集成的模式:从构建高级服务器到上下文高效的客户端,以及技能补充协议的地方。

构建有效的 MCP 服务器

我们的目录中有超过 200 个 MCP 服务器,每天有数百万人使用。通过与基于该协议的企业和开发人员密切合作,我们发现了一些设计模式,这些模式决定了Agent如何可靠地使用服务器。

构建远程服务器以实现最大范围

远程服务器为您提供分发 - 它是跨 Web、移动和云托管Agent运行的唯一配置,并且是每个主要客户端都经过优化以使用的配置。构建远程服务器,以便Agent可以在任何运行的地方使用您的系统。

围绕意图而不是端点对工具进行分组

更少、描述更清楚的工具始终优于详尽的 API 镜像。不要将 API 包装到 MCP 服务器中,围绕意图进行一对一的分组工具,这样Agent就可以通过几次调用来完成任务,而不是将许多原语拼接在一起。单个 create_issue_from_thread 工具胜过 get_thread + parse_messages + create_issue + link_attachment。请参阅为Agent编写有效的工具以了解有关完整模式的更多信息。

当表面很大时进行代码编排设计

如果您的服务需要数百个不同的操作,例如 Cloudflare、AWS 或 Kubernetes,则意图分组的工具集可能无法涵盖它。相反,公开一个接受代码的瘦工具表面:Agent编写一个简短的脚本,您的服务器在沙箱中针对您的 API 运行它,并且仅返回结果。 Cloudflare 的 MCP 服务器是参考示例 - 两个工具(搜索和执行)覆盖大约 1K 令牌中的约 2,500 个端点。

在有帮助的地方提供丰富的语义

MCP Apps 是第一个官方协议扩展,允许工具返回交互式界面,例如图表、表单或仪表板,所有这些都在聊天界面中内联呈现。与仅返回文本的服务器相比,搭载 MCP 应用程序的服务器往往具有更高的采用率和保留率。使用它可以在重要的时刻将产品的 UI 呈现在Agent或最终用户面前 - Claude.ai、Claude Cowork 和许多其他顶级 AI 工具都支持该扩展。

启发让您的服务器暂停中间工具调用以询问用户输入。表单模式发送一个简单的模式,客户端呈现一个本机表单——用它来请求丢失的参数、确认破坏性操作或消除选项的歧义。 URL 模式将用户交给浏览器 — 使用它来完成下游 OAuth、进行付款或收集任何不应传输 MCP 客户端的凭证。两者都让用户保持在流程中,而不是将他们发送到设置页面。广泛支持表单模式; Claude Code 支持 URL 模式,更多客户端正在开发中。

依靠标准化身份验证

标准化身份验证使 MCP 对于云托管Agent来说非常实用。如果您的服务器需要 OAuth,最新的 MCP 规范支持用于客户端注册的 CIMD(客户端 ID 元数据文档),它为用户提供快速的首次身份验证流程,并减少意外的重新身份验证提示。这是我们推荐的身份验证方法,MCP SDK、Claude.ai 和 Claude Code 支持该功能,并且正在整个行业广泛采用。用户授权后,下一个问题是云托管Agent如何在运行时保存和重用这些令牌。 Claude Managed Agents 中的保管库涵盖了这一点:注册用户的 OAuth 令牌一次,在会话创建时通过 ID 引用保管库,平台将正确的凭据注入每个 MCP 连接并代表您刷新它们 - 无需构建秘密存储,每次调用无需传递令牌。

使 MCP 客户端更加上下文高效

MCP 标准化了 AI Agent(客户端)如何连接到所需的工具和数据源(服务器)并使用它们。服务器安全地公开一系列功能,而客户端则编排它们并管理上下文。如果您正在构建 MCP 客户端,请使用渐进式披露模式使其上下文高效。

通过工具搜索按需加载工具定义

工具搜索推迟将所有工具加载到上下文中,而不是预先加载它们。这允许Agent在运行时搜索目录,并在需要时引入相关工具。在我们的测试中,工具搜索往往会将工具定义标记减少 85% 以上,同时保持较高的选择准确性。

通过编程工具调用处理工具结果代码

Programmatic tool calling processes tool results in a code-execution sandbox, rather than returning them raw to the model. This lets the agent loop, filter, and aggregate across calls in code, with only the final output reaching context. In our testing, this reduces token usage by roughly 37% on complex multi-step workflows.

这些模式一起自然地跨多个服务器组合:更精简的上下文、更少的往返、更快的响应。请参阅高级工具的使用以获取完整的详细信息。

Pairing MCP servers with skills

Skills and MCP are complementary . MCP gives an agent access to tools and data from external systems, while skills teach an agent the procedural knowledge of how to use those tools to accomplish real work. The most capable agents use both, and skills make MCP servers scale beyond a handful of connections. There are two general patterns for combining them:

Bundle skills and MCP servers as a plugin

Plugins for Claude are a useful abstraction that allow developers to bundle skills, MCP servers, hooks, LSP servers, and specialized subagents in one easily-consumable distribution method. Using this approach is the best way to unify multiple context providers with minimal friction. Combining MCP servers with skills allows Claude to act more like a domain-specialist. Grab your tools via MCP, and give Claude the skills to orchestrate workflows end-to-end. See our data plugin for Cowork as an example, which consists of 10 skills and 8 MCP servers for apps like Snowflake, Databricks, BigQuery, Hex and more.

Distribute skills from an MCP server

It's increasingly common for providers to publish a skill alongside their MCP server, so the agent gets both the raw capabilities and an opinionated playbook for using them well. Canva , Notion , Sentry , and more do this today in Claude, listing the skill next to their connector in our web directory .

To make that pairing portable across every client, the MCP community is actively working on an extension for delivering skills directly from servers. This way the client inherits the relevant expertise automatically, versioned with the API it depends on. We expect this pattern to see broad adoption as the extension stabilizes.

The compounding layer

We opened with three paths for connecting agents to external systems. In practice, mature integrations will ship all three: the API as the foundation, a CLI for local-first environments, and MCP for cloud-based agents.

As production agents move to the cloud, MCP becomes the critical layer, and it’s the one that compounds. Today, a remote server reaches every compatible client across any deployment environment, with auth, interactivity, and rich semantics handled by the protocol. As more clients adopt the spec and more extensions land in it, that same server gets more capable without you shipping anything new.

When building an integration, if your goal is to have production agents in the cloud reach your system, build an MCP server and make it excellent using the patterns above. Every integration built on MCP strengthens the ecosystem: fewer edge cases to solve alone, fewer bespoke integrations to maintain.

Acknowledgements

Thanks to Den Delimarsky, David Soria Parra, Henry Shi, Felix Rieseberg, Conor Kelly, Molly Vorwerck, Andy Schumeister, Kevin Garcia, Amie Rotherham, Matt Samuels, Angela Jiang, Katelyn Lesse, AJ Rebeiro and Jess Yan for their contributions to this blog.

来源:https://claude.com/blog/building-agents-that-reach-production-systems-with-mcp