mcp-to-skill
Converts an MCP server into a zero-dependency skill package so AI agents can invoke tools directly via Bash commands,
without launching an MCP process or injecting all tool definitions upfront.
Step 1: Get MCP information
Determine the input type:
A — User provided a command string / local path / URL:
Confirm the command is available, proceed to Step 2.
B — User pasted tool schema JSON:
Save the JSON to a temp file, skip Step 2, go directly to Step 3.
Use the Write tool to save the pasted JSON to /tmp/mcp-schema-input.json.
In Step 3, use --schema-json /tmp/mcp-schema-input.json.
C — User hasn't specified, wants to pick from registered MCPs:
List the MCPs currently registered with the agent and let the user choose.
In Claude Code: run INLINECODE2
Language preference:
If the user specifies a language for the generated skill (e.g. "generate in Chinese", "用中文生成"),
note it and apply it to all generated files in Step 5. Default is English.
Step 2: Run mcp_inspector.py (only for input type A or C)
Locate mcp_inspector.py: it is in the same directory as this SKILL.md.
Determine the absolute path of that directory from the path information provided by the agent framework when loading this skill, then run:
CODEBLOCK0
Example output:
CODEBLOCK1
Use the Read tool to read /tmp/mcp-inspector-output.json and extract: server_name, source_path (may be null), tools[].
Step 3: AI analysis — infer equivalent commands
Read the inspector output (or the schema file from Step 1B).
If source_path is not null:
Use Read / Grep tools to read the source files, locate the implementation for each tool, and extract:
- - HTTP endpoint (URL, method, headers, body structure)
- or CLI invocation pattern
If source_path is null:
Infer reasonable equivalent commands based solely on each tool's description and inputSchema.
Write a command draft for each tool with a confidence marker:
- -
[VERIFIED] — confirmed by source code (only when source is available) - INLINECODE11 — AI-inferred, logically sound but untested (max level when source_path is null)
- INLINECODE12 — cannot be auto-generated, leave a placeholder with explanation
Step 4: Test read-only commands
For each [INFERRED] command that is a read-only operation (GET request, query), execute it with the Bash tool:
- - Pass → upgrade to INLINECODE14
- Fail → keep
[INFERRED], add a comment above the command noting the failure reason - Write operations (POST/PUT/DELETE, file modifications) — skip testing, keep INLINECODE16
- INLINECODE17 items — do not test
Step 5: Generate skill package
Create the skill directory in the user's current working directory (or a user-specified path):
CODEBLOCK2
Progressive disclosure rules:
- - tool count ≤ 8: write all tools into the SKILL.md quick-reference section
- tool count > 8: SKILL.md lists only the 8 most common tools; the rest go into
helpers/tools-extended.md; add a note at the bottom of SKILL.md: "More tools: see helpers/tools-extended.md"
SKILL.md frontmatter template:
CODEBLOCK3
Config file separation (secret safety):
INLINECODE19 — public config only, safe to commit:
CODEBLOCK4
INLINECODE20 — secrets only, must be gitignored:
CODEBLOCK5
INLINECODE21 — secrets template, safe to commit, for onboarding:
CODEBLOCK6
INLINECODE22 — contents:
CODEBLOCK7
Read order for scripts: secrets.json → environment variable (e.g. X_API_TOKEN). If both are empty, error and prompt user to copy the example file and fill it in.
Important: config.json and secrets.json are read on every tool call (not cached at startup).
Language: Generate all text content in the language specified in Step 1. Default is English.
If skill-creator is loaded in the agent context:
Pass the analysis results (tool list + inferred commands + confidence markers) to skill-creator to generate SKILL.md.
Step 6: Register skill with the current AI agent
Goal: register the generated skill directory so it is immediately available. Probe in order and use the first that works:
- 1. Check if
npx skills is available:
which npx && npx skills --version 2>/dev/null
If available: INLINECODE28
- 2. Check if running in Claude Code:
claude --version 2>/dev/null
If available: symlink to
~/.claude/skills/<skill-name>:
ln -sf <skill-path> ~/.claude/skills/<skill-name>
Note:
/add-dir is an interactive slash command and cannot be called via Bash.
- 3. If neither applies: output the skill path and tell the user how to register manually:
> "Skill generated at
<path>. Please register it with your AI agent.
> Claude Code users: run
/add-dir <path>
> npx skills users: run
npx skills add <path> -g"
Step 7: Ask about removing the original MCP (optional)
Only prompt when Step 1 was type A or C (not pasted schema):
"MCP <server-name> has been converted to a skill. Would you like to remove the MCP configuration from your AI agent?"
- - User confirms → assist with removal (agent decides how)
- User declines or no response → skip, skill and MCP can coexist
mcp-to-skill
将MCP服务器转换为零依赖的技能包,使AI代理可以直接通过Bash命令调用工具,
无需启动MCP进程或预先注入所有工具定义。
步骤1:获取MCP信息
确定输入类型:
A — 用户提供了命令字符串/本地路径/URL:
确认命令可用,继续执行步骤2。
B — 用户粘贴了工具模式JSON:
将JSON保存到临时文件,跳过步骤2,直接进入步骤3。
使用写入工具将粘贴的JSON保存到/tmp/mcp-schema-input.json。
在步骤3中,使用--schema-json /tmp/mcp-schema-input.json。
C — 用户未指定,希望从已注册的MCP中选择:
列出当前已向代理注册的MCP,让用户选择。
在Claude Code中:运行claude mcp list
语言偏好:
如果用户指定了生成技能的语言(例如generate in Chinese、用中文生成),
请记录并在步骤5中应用于所有生成的文件。默认为英文。
步骤2:运行mcp_inspector.py(仅适用于输入类型A或C)
定位mcp_inspector.py:它与此SKILL.md位于同一目录中。
根据代理框架加载此技能时提供的路径信息,确定该目录的绝对路径,然后运行:
bash
确保已安装mcp SDK
pip show mcp > /dev/null 2>&1 || pip install mcp
python /path/to/skill-dir/mcp_inspector.py --output /tmp/mcp-inspector-output.json
示例输出:
✓ 已写入 /tmp/mcp-inspector-output.json:12个工具,来源:/tmp/mcp-to-skill-cache/server-github
使用读取工具读取/tmp/mcp-inspector-output.json并提取:servername、sourcepath(可能为null)、tools[]。
步骤3:AI分析——推断等效命令
读取检查器输出(或步骤1B中的模式文件)。
如果source_path不为null:
使用读取/搜索工具读取源文件,定位每个工具的实现,并提取:
- - HTTP端点(URL、方法、请求头、请求体结构)
- 或CLI调用模式
如果source_path为null:
仅根据每个工具的description和inputSchema推断合理的等效命令。
为每个工具编写命令草稿,并附带置信度标记:
- - [VERIFIED] — 通过源代码确认(仅在源代码可用时)
- [INFERRED] — AI推断,逻辑合理但未经测试(source_path为null时的最高级别)
- [TODO] — 无法自动生成,留下占位符并附上说明
步骤4:测试只读命令
对于每个属于只读操作(GET请求、查询)的[INFERRED]命令,使用Bash工具执行:
- - 通过 → 升级为[VERIFIED]
- 失败 → 保留[INFERRED],在命令上方添加注释说明失败原因
- 写入操作(POST/PUT/DELETE、文件修改)— 跳过测试,保留[INFERRED]
- [TODO]项 — 不进行测试
步骤5:生成技能包
在用户当前工作目录(或用户指定的路径)中创建技能目录:
/
SKILL.md
config.json # 公共配置(可安全提交)
secrets.json # 密钥(已加入gitignore,切勿提交)
secrets.json.example # 密钥模板(可安全提交)
.gitignore
helpers/ (按需创建,不要预先创建空目录)
tools-extended.md (当工具数量 > 8时)
.py / .sh (当逻辑无法在单个命令中实现时)
渐进式披露规则:
- - 工具数量 ≤ 8:将所有工具写入SKILL.md的快速参考部分
- 工具数量 > 8:SKILL.md仅列出8个最常用的工具;其余工具放入helpers/tools-extended.md;在SKILL.md底部添加注释:更多工具:参见 helpers/tools-extended.md
SKILL.md前置元数据模板:
yaml
name: <服务器名称>
description: |
[使用时机]:<从工具描述中总结使用场景>
[功能]:<核心能力>
[不包含]:<明确排除的场景>
[依赖]:<运行时依赖;如无依赖则写无运行时依赖>
配置文件分离(密钥安全):
config.json — 仅包含公共配置,可安全提交:
json
{
endpoint: <从源代码提取的基础URL,或留作占位符>
}
secrets.json — 仅包含密钥,必须加入gitignore:
json
{
auth_token: <实际令牌>
}
secrets.json.example — 密钥模板,可安全提交,用于新用户上手:
json
{
auth_token: your-api-token-here
}
.gitignore — 内容:
secrets.json
脚本读取顺序: secrets.json → 环境变量(例如XAPITOKEN)。如果两者都为空,则报错并提示用户复制示例文件并填写。
重要提示:config.json和secrets.json在每次工具调用时读取(不在启动时缓存)。
语言: 使用步骤1中指定的语言生成所有文本内容。默认为英文。
如果技能创建器已加载到代理上下文中:
将分析结果(工具列表 + 推断命令 + 置信度标记)传递给技能创建器以生成SKILL.md。
步骤6:向当前AI代理注册技能
目标:注册生成的技能目录,使其立即可用。按顺序尝试,使用第一个有效的方法:
- 1. 检查npx skills是否可用:
bash
which npx && npx skills --version 2>/dev/null
如果可用:npx skills add <技能路径> -g -y
- 2. 检查是否在Claude Code中运行:
bash
claude --version 2>/dev/null
如果可用:创建符号链接到~/.claude/skills/<技能名称>:
bash
ln -sf <技能路径> ~/.claude/skills/<技能名称>
注意:/add-dir是交互式斜杠命令,无法通过Bash调用。
- 3. 如果以上均不适用:输出技能路径并告知用户如何手动注册:
> 技能已生成在<路径>。请将其注册到您的AI代理。
> Claude Code用户:运行/add-dir <路径>
> npx skills用户:运行npx skills add <路径> -g
步骤7:询问是否移除原始MCP(可选)
仅在步骤1为类型A或C(非粘贴模式)时提示:
MCP<服务器名称>已转换为技能。是否要从AI代理中移除MCP配置?
- - 用户确认 → 协助移除(由代理决定如何操作)
- 用户拒绝或无响应 → 跳过,技能和MCP可以共存