MCP代码执行
     
使用渐进加载模式将任何MCP服务器转换为可执行的、类型安全的TypeScript工具。实现 98%的代币节省 只装载你需要的东西。
\[!提示\] 受...启发 Anthropic的工程博客文章 关于使用MCP执行代码。
问题
传统的MCP集成从服务器加载所有工具(约30000个令牌),即使您只需要一两个。这浪费了上下文窗口空间并减慢了AI代理的速度。
解决方案
渐进式加载为每个工具生成一个TypeScript文件(每个约500-1500个令牌)。AI代理通过简单的方法只发现和加载他们需要的东西 ls 和 cat 命令。
结果: 98%的代币节省 + 自主执行 + 型式安全
安装
来自crates.io(推荐)
cargo install mcp-execution-cliPre-built binaries
下载自 :
# macOS (Apple Silicon)
curl -L https://github.com/bug-ops/mcp-execution/releases/latest/download/mcp-execution-cli-macos-arm64.tar.gz | tar xz
# macOS (Intel)
curl -L https://github.com/bug-ops/mcp-execution/releases/latest/download/mcp-execution-cli-macos-amd64.tar.gz | tar xz
# Linux (x86_64)
curl -L https://github.com/bug-ops/mcp-execution/releases/latest/download/mcp-execution-cli-linux-amd64.tar.gz | tar xz
# Linux (ARM64)
curl -L https://github.com/bug-ops/mcp-execution/releases/latest/download/mcp-execution-cli-linux-arm64.tar.gz | tar xz
# Windows (x86_64)
# Download mcp-execution-cli-windows-amd64.zip from releases pageFrom source
git clone https://github.com/bug-ops/mcp-execution
cd mcp-execution
cargo install --path crates/mcp-cliAs a library
将单个板条箱添加到您的项目中:
cargo add mcp-execution-core # Foundation types
cargo add mcp-execution-introspector # MCP server analysis
cargo add mcp-execution-codegen # TypeScript generation
cargo add mcp-execution-files # Virtual filesystem
cargo add mcp-execution-skill # SKILL.md generation或添加到 Cargo.toml:
[dependencies]
mcp-execution-core = "0.7"
mcp-execution-introspector = "0.7"
mcp-execution-codegen = "0.7"\[!重要\] 需要Rust 1.91或更高版本才能从源代码构建。
用法
生成TypeScript工具
# 1. Configure MCP server in ~/.claude/mcp.json
# 2. Generate tools
mcp-execution-cli generate --from-config github
# Output: ~/.claude/servers/github/
# - createIssue.ts
# - updateIssue.ts
# - ... (one file per tool)渐进式加载
# List available tools
ls ~/.claude/servers/github/
# Load only what you need (98% token savings!)
cat ~/.claude/servers/github/createIssue.ts
# Execute autonomously
node ~/.claude/servers/github/createIssue.ts --repo="owner/repo" --title="Bug"\[!注意\] 每个工具文件都包含完整的TypeScript接口和JSDoc文档。
主要特点
| 特性 | 描述 |
|---|---|
| 98%的代币节省 | 加载1个工具(约500个令牌)与所有工具(约30000个令牌) |
| 自主执行 | 生成的文件直接通过Node.js CLI运行 |
| 类型安全 | 来自MCP JSON模式的完整TypeScript接口 |
| 迅速的 | 比目标快526倍(10个工具为0.19ms) |
| 100%MCP兼容 | 通过以下方式与所有MCP服务器配合使用 rmcp SDK |
| 经过彻底测试 | 626次测试,通过率100% |
工作区板条箱
| 板条箱 | 描述 |
|---|---|
| mcp执行核心 | 基础类型、特征和错误处理 |
| mcp执行内省者 | 使用rmcp SDK进行MCP服务器分析 |
| mcp执行代码生成器 | 使用渐进加载生成TypeScript代码 |
| mcp执行文件 | 用于代码组织的虚拟文件系统 |
| mcp执行技巧 | Claude代码的SKILL.md生成 |
| mcp执行服务器 | 用于渐进式加载生成的MCP服务器 |
| mcp执行cli | 命令行界面 |
依赖图:
mcp-execution-cli → {mcp-execution-codegen, mcp-execution-introspector, mcp-execution-files, mcp-execution-core, mcp-execution-skill}
mcp-execution-server → {mcp-execution-codegen, mcp-execution-introspector, mcp-execution-files, mcp-execution-core, mcp-execution-skill}
mcp-execution-codegen → {mcp-execution-introspector, mcp-execution-core}
mcp-execution-files → mcp-execution-codegen
mcp-execution-introspector → {rmcp, mcp-execution-core}
mcp-execution-skill → mcp-execution-coreCLI命令
看 mcp-cli自述文件 供充分参考。
# Generate TypeScript tools from config (recommended)
mcp-execution-cli generate --from-config github
# Preview what would be generated without writing to disk
mcp-execution-cli generate --from-config github --dry-run
# Introspect MCP server from config
mcp-execution-cli introspect --from-config github
# Introspect with detailed schemas
mcp-execution-cli introspect --from-config github --detailed
# Manual configuration (alternative)
mcp-execution-cli introspect docker --arg=run --arg=-i --env=TOKEN=xxx
# Shell completions
mcp-execution-cli completions bash\[!提示\] 使用--from-config从加载服务器设置~/.claude/mcp.json而不是手动参数。
演出
| 指标 | 目标 | 已实现 |
|---|---|---|
| 10个工具生成 | \ \[!注意\] |
所有发展如下 微软Rust指南.
MSRV政策
支持的最低Rust版本: 1.91
MSRV的增加被认为是次要的版本升级。
许可证
根据以下任一许可 Apache许可证2.0 或 MIT许可证 由您选择。
