Token导航 LogoToken导航TokenDH.com
研究检索external-servicegithub未标认证来源可访问许可证需确认审计提醒

code-mode编码模式

Agent Skill

code-mode 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

428

周安装

18

GitHub Stars

20

下载量

150
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:code-mode(编码模式)
来源仓库:https://github.com/chenhunghan/code-mode-skill
仓库路径:skills/code-mode
安装命令:
npx skills add https://github.com/chenhunghan/code-mode-skill --skill code-mode
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/chenhunghan/code-mode-skill --skill code-mode

简介

code-mode 将大 API 响应转为小型处理脚本执行,减少 LLM 上下文 token 消耗与性能下降。

  • 适用于 Kubernetes、GitHub、Stripe 等海量数据源的查询场景,仅将脚本 stdout 送入模型。
  • MCP 服务器在沙箱中运行用户脚本,支持 Python/JS/TS,确保原始数据不出本地环境。
  • 使用前请确认 MCP 服务端已启用 code mode 并配置好安全策略,避免任意代码执行风险。
  • 本模式显著降低 token 开销,但对脚本编写能力要求较高;建议封装常用查询模板供团队复用。

SKILL.md

Code Mode for MCP Servers

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 the LLM already knows the response schema from training data — it can write the extraction script in one shot without inspecting the data.

Typical results: 65–99% context reduction.

Inspiration


How This Skill Works

This is an interactive planning skill. Work with the user step-by-step:

  1. Understand their MCP server (language, framework, what tools return large data)
  2. Select a sandbox that fits their server language and security needs
  3. Plan the implementation together
  4. Implement the code mode tool, sandbox executor, and benchmark
  5. Verify with benchmarks comparing before/after context sizes

Do not jump ahead. Confirm each step with the user before proceeding.


Step 1: Understand the Existing MCP Server

Ask the user (or discover by reading their codebase):

  • Server language: TypeScript/JavaScript, Python, Go, Rust, or other?
  • MCP framework: XMCP, FastMCP, mcp-go, custom, etc.?
  • Which tools return large responses? (e.g. list users, get pods, search issues)
  • What APIs do they call? Well-known APIs (SCIM, K8s, GitHub, Stripe) are ideal candidates because the LLM already knows the schema.
  • What languages should the sandbox support for script execution? Usually JavaScript is sufficient. Python is a common second choice.

Summarize your understanding back to the user and confirm before moving on.


Step 2: Select a Sandbox

The sandbox must be isolated from the host filesystem and network by default and secure by default. Present the user with options that match their server language, using the reference in references/sandbox-options.md.

Quick Selection Guide

If the server is TypeScript/JavaScript:

SandboxScript LanguageIsolationSizeNotes
quickjs-emscriptenJavaScriptWASM (no fs/net)~1MBLightweight, actively maintained, best default
pyodidePythonWASM (no fs/net)~20MBFull CPython in WASM, heavier
isolated-vmJavaScriptV8 isolate (no fs/net)~5MB nativeFast, separate V8 heap, not WASM

If the server is Python:

SandboxScript LanguageIsolationSizeNotes
RestrictedPythonPythonAST-restricted compileTinyCompiles to restricted bytecode, no I/O by default
pyodide (in-process WASM)PythonWASM~20MBHeavier but stronger isolation than RestrictedPython
quickjs (via quickjs PyPI)JavaScriptWASM/nativeSmallRun JS from Python

If the server is Go:

SandboxScript LanguageIsolationSizeNotes
gojaJavaScriptPure Go interpreterZero CGONo fs/net, widely used (used by Grafana)
WazeroWASM guest (JS/Python compiled to WASM)WASM runtime, pure GoZero CGOStrongest isolation, runs any WASM module
starlark-goStarlark (Python dialect)Pure Go interpreterZero CGODeterministic, no I/O, used by Bazel

If the server is Rust:

SandboxScript LanguageIsolationSizeNotes
boa_engineJavaScriptPure Rust interpreterNo unsafe depsES2024 support, embeddable
wasmtime / wasmerWASM guestWASM runtimeStrongRun any WASM module, strongest isolation
deno_coreJavaScript/TypeScriptV8-basedLargerFull V8, powerful but heavier
rustpythonPythonPure Rust interpreterModerateLess mature but functional

Read references/sandbox-options.md for detailed tradeoffs on each option.

Present 2–3 options to the user (filtered to their server language), explain the tradeoffs briefly, and let them choose. If they're unsure, recommend the lightest WASM-based option for their language.


Step 3: Plan the Implementation

Once the sandbox is selected, create a concrete plan with the user. The plan should cover these components:

3a. Code Mode Tool

A new MCP tool (e.g. code_mode or <domain>_code_mode) that accepts:

  • command or args: The underlying API call / query to execute (e.g. kubectl args, SCIM endpoint + params, GraphQL query)
  • code: The processing script the LLM writes
  • language (optional): Script language, defaults to javascript

The tool handler:

  1. Executes the underlying API call (reusing existing logic)
  2. Passes the raw response as a DATA variable into the sandbox
  3. Runs the script in the sandbox
  4. Returns only the script's stdout, plus a size measurement line: [code-mode: 18.0KB -> 6.2KB (65.5% reduction)]

3b. Sandbox Executor

A utility module that:

  • Initializes the chosen sandbox runtime
  • Injects DATA (the raw API response as a string) into the sandbox
  • Executes the user-provided script
  • Captures stdout and returns it
  • Enforces a timeout (e.g. 10 seconds)
  • Handles errors gracefully (script syntax errors, runtime errors)

3c. Wiring

  • Register the new tool in the MCP server's tool list
  • Optionally gate behind an env var (ask the user if they want this)

3d. Benchmark

A benchmark script that compares tool output size vs. code-mode output size across realistic scenarios. See references/benchmark-pattern.md for the template.

Present the plan to the user and confirm before implementing.


Step 4: Implement

Follow the confirmed plan. Implement in this order:

  1. Install the sandbox dependency (e.g. npm i quickjs-emscripten)
  2. Create the executor module — the sandbox wrapper
  3. Create the code mode tool — the MCP tool handler
  4. Wire it into the server — register the tool
  5. Create the benchmark script

Keep the implementation minimal — don't over-abstract. The executor and tool can each be a single file.

Implementation Tips

  • The DATA variable should always be a string (JSON-serialized). The script is responsible for parsing it if needed (JSON.parse(DATA) in JS, json.loads(DATA) in Python).
  • Include the reduction measurement in every response so the user/LLM can see the savings: [code-mode: {before}KB -> {after}KB ({pct}% reduction)]
  • Set a reasonable default timeout (10s) and memory limit if the sandbox supports it.
  • Return clear error messages if the script fails — the LLM will use the error to fix its script on the next call.

Step 5: Benchmark and Verify

After implementation, run the benchmark to verify code mode actually reduces context size. Read references/benchmark-pattern.md for the full template.

The benchmark should:

  1. Generate or fetch realistic test data — use faker/mock data if no live API is available, or hit a real endpoint if the user has one.
  2. Run each scenario through both paths:

- Regular tool response (full JSON) - Code mode with a representative extraction script

  1. Print a comparison table showing before/after sizes and reduction %
  2. Print a total across all scenarios

Present the benchmark results to the user. Typical expectations:

  • Simple list extractions: 60–80% reduction
  • Filtered queries (e.g. "only inactive users"): 90–99% reduction
  • Aggregations (e.g. "count per department"): 95–99% reduction

Reference Files

  • references/sandbox-options.md — Detailed comparison of all sandbox options by server language, with security analysis and setup instructions
  • references/benchmark-pattern.md — Benchmark script template and methodology

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.81%
按下载量换算51

Claude

31.21%
按下载量换算47

Cursor

20.04%
按下载量换算30

Gemini CLI

9.65%
按下载量换算14

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills