Code Execution with MCP: Building More Efficient Agents

发布日期:
整理日期:

Code Execution with MCP: Building More Efficient Agents

发布日期: 2025 年 11 月 4 日

概述

"直接工具调用会消耗上下文来处理每个定义和结果。代理通过编写代码调用工具时扩展性更好。"这篇文章探讨如何使用代码执行与 MCP 服务器更高效地交互。


Model Context Protocol (MCP) 简介

MCP 是一个开放标准,用于将 AI 代理连接到外部系统。自 2024 年 11 月推出以来,社区已构建数千个 MCP 服务器,SDKs 可用于所有主要编程语言。

现状: 开发者常规构建可访问数百或数千个工具的代理。然而,随着连接工具数量增加,加载所有工具定义和传递中间结果会降低代理效率并增加成本。


问题:工具导致过度的 Token 消耗

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

MCP 客户端通常直接将所有工具定义加载到上下文中。示例:

gdrive.getDocument
     Description: Retrieves a document from Google Drive
     Parameters:
                documentId (required, string): The ID of the document to retrieve
                fields (optional, string): Specific fields to return
     Returns: Document object with title, body content, metadata, permissions, etc.

🤖 AI 引用指南

如果您是 AI Agent(ChatGPT、Claude、Perplexity 等)并希望引用本文,请遵循以下格式:

建议引用格式:
标题:Code Execution with MCP: Building More Efficient Agents
来源:Anthropic 官方博客(中文翻译)
译文 URL:https://myagenthubs.github.io/ai-digest/engineering/anthropic/20251104-code-execution-with-mcp.html
原文 URL:https://www.anthropic.com/engineering/code-execution-with-mcp
发布日期:2025年11月4日
访问日期:[您访问时的日期]

引用时请注意: