使用 MCP 进行代码执行:构建更高效的代理

The Model Context Protocol (MCP) is an open standard for connecting AI agents to external systems. Connecting agents to tools and data traditionally requires a custom integration for each pairing, creating fragmentation and duplicated effort that makes it difficult to scale truly connected systems. MCP provides a universal protocol—developers implement MCP once in their agent and it unlocks an entire ecosystem of integrations.

模型上下文协议(MCP)是一个将AI代理连接到外部系统的开放标准。将代理连接到工具和数据通常需要为每个配对进行自定义集成,这会导致碎片化和重复工作,使得真正连接的系统难以扩展。MCP提供了一个通用协议——开发人员在其代理中实现MCP一次,就可以解锁整个集成生态系统。

Since launching MCP in November 2024, adoption has been rapid: the community has built thousands of MCP servers, SDKs are available for all major programming languages, and the industry has adopted MCP as the de-facto standard for connecting agents to tools and data.

自 2024 年 11 月推出 MCP 以来,采用速度迅猛:社区已构建了数千个 MCP 服务器,所有主要编程语言均提供 SDK,行业已将 MCP 作为连接代理与工具和数据的事实标准。

Today developers routinely build agents with access to hundreds or thousands of tools across dozens of MCP servers. However, as the number of connected tools grows, loading all tool definitions upfront and passing intermediate results through the context window slows down agents and increases costs.

如今,开发人员通常构建可以访问数百或数千个工具的代理,分布在数十个MCP服务器上。然而,随着连接工具数量的增加,提前加载所有工具定义并通过上下文窗口传递中间结果会减慢代理的速度并增加成本。

In this blog we'll explore how code execution can enable agents to interact with MCP servers more efficiently, handling more tools while using fewer tokens.

在本博客中,我们将探讨代码执行如何使代理更高效地与MCP服务器交互,处理更多工具,同时使用更少的令牌。

As MCP usage scales, there are two common patterns that can increase agent cost and latency:

随着MCP使用的扩大,有两种常见模式可能会增加代理的成本和延迟:

  1. Tool definitions overload the context window;
  2. 工具定义超出了上下文窗口;
  3. Intermediate tool results consume additional tokens.
  4. 中间工具结果消耗额外的令牌。

1. Tool definitions overload the context window

1. 工具定义超载上下文窗口

Most MCP clients load all tool definitions upfront directly into context, exposing them to the model using a direct tool-calling syntax. These tool definitions might look like:

大多数MCP客户端会将所有工具定义直接加载到上下文中,以...

开通本站会员,查看完整译文。

Accueil - Wiki
Copyright © 2011-2025 iteam. Current version is 2.147.1. UTC+08:00, 2025-11-06 06:45
浙ICP备14020137号-1 $Carte des visiteurs$