
Claude 代码技能:在任何 MCP 服务器上添加代码模式,可减少 65-99% 的上下文
概览
一个代理技能,帮助你添加到任何MCP服务器——这样LLM就能编写小型处理脚本,在沙盒运行时针对大型API响应,只有脚本的紧凑输出进入上下文窗口。适用于任何支持代理技能的AI代理。 当MCP工具返回大型API响应(例如列出500个Kubernetes播客、200个SCIM用户或数千个GitHub问题)时,整个负载都会进入LLM的上下文窗口——消耗令牌并降低性能。 代码模式则相反:LLM不将原始数据导入上下文,而是编写一个小型处理脚本。MCP服务器在原始数据中运行脚本,只有脚本的标准输出进入上下文。 这在知名API(SCIM、Kubernetes、GitHub、Stripe、Slack、AWS等)中尤其有效,因为LLM已经通过训练数据知道响应模式。 灵感来自Cloudflare代码模式和claude上下文模式。 这是一个 .
概述(AI 翻译)
这是一个代理技能,帮助你在任何MCP服务器上添加代码模式——这样LLM就能编写小型处理脚本,在沙箱运行时对应大型API响应,只有脚本的紧凑输出进入上下文窗口。适用于任何支持代理技能的AI代理。
典型结果:65–99%的上下文缩减。
什么是代码模式?
当MCP工具返回大型API响应(例如列出500个Kubernetes播客、200个SCIM用户或数千个GitHub问题)时,整个负载都会进入LLM的上下文窗口——消耗令牌并降低性能。
代码模式则相反:LLM不将原始数据倾倒到上下文中,而是编写一个小型处理脚本。MCP服务器在*沙箱运行时**中对原始数据运行脚本,只有脚本的标准输出进入上下文。
这在知名API(SCIM、Kubernetes、GitHub、Stripe、Slack、AWS等)中尤其有效,因为LLM已经通过训练数据知道响应模式。
灵感来自Cloudflare代码模式和claude上下文模式。
这项技能的作用
这是一项互动式规划技能。它会一步步与你合作,帮助你:
本页由 AI 翻译,技术细节请以原文为准。
README
Code Mode Skill
An agent skill that helps you add code mode to any MCP server — so LLMs can write small processing scripts that run against large API responses in a sandboxed runtime, and only the script’s compact output enters the context window. Works with any AI agent that supports agent skills.
Typical result: 65–99% context reduction.
What is Code Mode?
When an MCP tool returns a large API response (e.g. listing 500 Kubernetes pods, 200 SCIM users, or thousands of GitHub issues), that entire payload enters the LLM’s context window — consuming tokens and degrading performance.
Code mode flips the approach: instead of dumping raw data into context, the LLM writes a small processing script. The MCP server runs the script in a sandboxed runtime against the raw data, and only the script’s stdout enters context.
This works especially well with well-known APIs (SCIM, Kubernetes, GitHub, Stripe, Slack, AWS, etc.) because LLMs already know the response schemas from training data.
Inspired by Cloudflare Code Mode and claude-context-mode.
What This Skill Does
This is an interactive planning skill. It works with you step-by-step to:
- Understand your MCP server (language, framework, which tools return large data)
- Select a sandbox that fits your server language and security requirements
- Plan the implementation together
- Implement the code mode tool, sandbox executor, and wiring
- Benchmark before/after context sizes to verify the reduction
Supported Server Languages
| Server Language | Sandbox Options |
|---|---|
| TypeScript/JavaScript | quickjs-emscripten (WASM), pyodide (WASM), isolated-vm (V8) |
| Python | RestrictedPython, pyodide (WASM), quickjs bindings |
| Go | goja, Wazero (WASM), starlark-go |
| Rust | boa_engine, wasmtime/wasmer (WASM), deno_core |
All sandbox options are isolated from the host filesystem and network by default.
Install
npx skills add chenhunghan/code-mode-skill
Or manually copy the SKILL.md and references/ directory into your agent’s skills directory.
Usage
Just ask your agent to add code mode to your MCP server:
- “I want to add code mode to my MCP server to reduce token usage”
- “Add a sandboxed code execution tool to my TypeScript MCP server”
- “My get-users tool returns 50KB+ responses, help me reduce context size”
The skill will guide you through the process interactively.
License
MIT
推荐工具
换一个关键词,或者移除筛选条件。
安装
npx skillfish add chenhunghan/code-mode-skill