代码模式 MCP — 将所有 MCP 服务器合并在 search() + execute() 之后
概览
停止注册数十个MCP服务器。注册时,将所有服务器全部聚合在 。 你的AI代理编写TypeScript,在每台连接的服务器上发现并调用工具——具备完整的类型安全、沙盒执行和自动响应截断。 灵感来自Cloudflare对代码模式MCP的做法。 MCP工具的爆炸式增长是真实存在的。每增加一个服务器,你的代理上下文中会增加5到30个工具。6台服务器意味着模型每回合都得解析180个工具定义。 CMCP则颠倒了模型:你得到的不是N个工具,而是: 代理编写代码是为了与工具交互,而不是 JSON 块。这意味着: - 上下文中(2 vs hundreds)—— 无需重启 Claude 或 Codex 即可添加服务器 - —— 在一次执行中串联多个工具调用 —— —— 从 JSON Schema 自动生成的 TypeScript 声明 —— 代码运行在 QuickJS 引擎中,内存限制为 64 MB 就这些。重启Claude,你会看到带有搜索和执行工具的代码模式MCP。
概述(AI 翻译)
停止注册数十个MCP服务器。注册一个代理,将所有服务器聚合在2个工具之后。
你的AI代理编写TypeScript,在每台连接的服务器上发现并调用工具——具备完整的类型安全、沙盒执行和自动响应截断。
灵感来自Cloudflare对代码模式MCP的做法。
为什么
MCP工具的爆炸式增长是真实存在的。每增加一个服务器,你的代理上下文中会增加5到30个工具。6台服务器意味着模型每回合都得解析180个工具定义。
CMCP则颠倒了模式:你得到的不是N个工具,而是2:
| 工具 | 目的 |
|---|---|
search() |
通过编写TypeScript过滤代码发现工具 |
execute() |
调用任何带有非同步代码的服务器工具 |
代理编写代码是为了与工具交互,而不是 JSON 块。这意味着:
- 在上下文中工具定义减少99%(2个对数百个)
- 热重载 — 无需重启 Claude 或 Codex 即可添加服务器
- Composable — 在一次执行中串联多个工具调用
- Type-safe — 由 JSON Schema 自动生成的 TypeScript 声明
- 沙盒 — 代码运行在 QuickJS 引擎中,内存限制为 64 MB
快速开始
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
cmcp — Code Mode MCP
Stop registering dozens of MCP servers. Register one proxy that aggregates them all behind just 2 tools.
Your AI agent writes TypeScript to discover and call tools across every connected server — with full type safety, sandboxed execution, and automatic response truncation.
Inspired by Cloudflare’s approach to code-mode MCP.
Why
The MCP tool explosion is real. Every new server adds 5-30 tools to your agent’s context. With 6 servers that’s potentially 180 tool definitions the model has to parse on every turn.
cmcp flips the model: instead of N tools, you get 2:
| Tool | Purpose |
|---|---|
search() |
Discover tools by writing TypeScript filter code |
execute() |
Call tools across any server with typed async code |
The agent writes code to interact with tools, not JSON blobs. This means:
- 99% fewer tool definitions in context (2 vs hundreds)
- Hot-reload — add servers without restarting Claude or Codex
- Composable — chain multiple tool calls in a single execution
- Type-safe — auto-generated TypeScript declarations from JSON Schema
- Sandboxed — code runs in a QuickJS engine with a 64 MB memory limit
Quick start
# Install
cargo install --path .
# Add servers (same syntax you already know)
cmcp add canva https://mcp.canva.com/mcp
cmcp add --transport stdio github -- npx -y @modelcontextprotocol/server-github
# Register the proxy with Claude
cmcp install
That’s it. Restart Claude and you’ll see code-mode-mcp with the search and execute tools.
Copy-paste from any MCP README
Most MCP server docs give you a claude mcp add or codex mcp add command. Just prepend cmcp:
# Claude syntax — just prepend cmcp
cmcp claude mcp add chrome-devtools --scope user npx chrome-devtools-mcp@latest
cmcp claude mcp add --transport http canva https://mcp.canva.com/mcp
# Codex syntax — same idea
cmcp codex mcp add my-server -- npx docs-server@latest
cmcp codex mcp add api-server --url https://api.example.com --bearer-token-env-var API_TOKEN
How it works
search — discover tools
The agent writes TypeScript to filter the tool catalog:
// Find screenshot-related tools
return tools.filter(t => t.name.includes("screenshot"));
// Find all tools from a specific server
return tools.filter(t => t.server === "chrome-devtools");
// Get a summary of available servers
const servers = [...new Set(tools.map(t => t.server))];
return servers.map(s => ({
server: s,
tools: tools.filter(t => t.server === s).map(t => t.name)
}));
execute — call tools
Each server is a typed global object. The agent calls tools with await:
// Navigate and take a screenshot
await chrome_devtools.navigate_page({ url: "https://example.com" });
const screenshot = await chrome_devtools.take_screenshot({ format: "png" });
return screenshot;
// Chain multiple servers in one call
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →