搜索模式和代码模式
代理连接时会读取完整的工具列表。对于小型 API,这种形式很合适:每个端点对应一个工具,并附有其架构。对于大型 API,仅工具列表就可能在代理执行任何操作之前占满其上下文。GitHub 的公开规范包含 1,209 个操作;将其列为独立工具时约需 403,000 个 token,而在搜索模式下约需 1,500 个 token。
MCP Studio 中的 代理如何查看工具 设置决定了工具列表的形式。
| 模式 | 代理列出的内容 |
|---|---|
| Automatic | 阈值以内列出所有工具,超过阈值后使用搜索。这是默认设置 |
| Every tool | 每个端点对应一个工具,不受规模限制 |
| Search | 少量用于查找、描述和调用端点的工具 |
| Code | 两个用于针对你的 SDK 编写并运行短脚本的工具 |
文档工具在所有模式下都会列出。
搜索模式
代理会使用以下工具,而不是端点列表:
| 工具 | 作用 |
|---|---|
search_tools | 用几句话描述工具的用途来查找工具。接受 query、group、limit 和 offset。默认返回 10 个,最多返回 25 个 |
describe_tool | 按名称返回最多五个工具的完整架构 |
call_tool | 按名称传入参数调用其中一个工具 |
list_tool_groups | 列出操作的组织方式,并为每种方式提供几个示例 |
显示效果
这是一个真实会话,使用的 API 有 281 个操作。代理进行搜索:
search_tools { "query": "create a file", "limit": 3 }
78 operations of 281 match "create a file" (showing 1 to 3):
createFile · POST /files · Upload a file that can be used across various
endpoints. · requires: body · asks the user first
CreateContainerFile · POST /containers/{container_id}/files · Create a
Container File · requires: containerId · asks the user first
createVectorStoreFile · POST /vector_stores/{vector_store_id}/files · Create a
vector store file. · requires: vectorStoreId, body · asks the user first
Next: describe_tool with the names you need, then call_tool. Pass offset 3 for more.然后读取它想要的工具:
describe_tool { "names": ["createFile"] }
## createFile
POST /files · group: Files · asks the user to approve each call · can change or delete data
Upload a file that can be used across various endpoints...最后使用 call_tool 调用它。
通过 call_tool 发出的调用遵循与直接调用相同的权限、审批提示和限制,并以工具的真实名称显示在用量中。链式工具也可以用同样的方式搜索和调用。
Switch to search above可设置 Automatic 的阈值。初始值为 40 个可见工具。
代理只能通过工具的名称和描述找到工具。请用人们实际使用的词语编写这些内容。
代码模式
在代码模式下,代理会列出 describe_sdk,以显示 SDK 的方法;还会列出 run_code,用于运行简短的 TypeScript 或 Python 脚本,并提供现成的 client:
const open = await client.invoices.list({ status: "open" });
return open.filter((invoice) => invoice.dueDate < "2026-11-01").length;列表、筛选器和十几个后续调用会作为一个答案返回,并且只有该答案会进入代理的上下文。
脚本在沙盒中运行,唯一的出口是 SDK。脚本中的每次 SDK 调用都遵循与工具调用相同的流程:权限、审批提示、练习答案、错误指南和用量。因此,脚本无法执行工具无法执行的操作,并且会请求工具会请求的所有内容。
| 限制 | 值 |
|---|---|
| 每次运行的 SDK 调用次数 | 50 |
| 每次运行的审批提示次数 | 10 |
| 脚本长度 | 20,000 个字符 |
| 运行时间 | 30 秒。等待 API 响应的时间不计入其中 |
| 内存 | 64 MB |
| 打印输出 | 8 KB |
| 返回结果 | 24 KB |
使用 Turn on code mode 启用代码模式,并在 Code mode languages 下选择语言。Starter 套餐起即可使用代码模式。如果沙盒无法在某台机器上启动,服务器会退回到搜索模式。
按连接选择
连接者可以为自己的连接覆盖你的选择:
- 托管:在服务器 URL 中添加
?tool_mode=search(或all、code、auto)。 - 本地:
--tool-mode search或OCTRI_TOOL_MODE=search。
他们的选择优先于你的选择,而你的选择优先于 Automatic。