跳转到内容

MCP 适配器

ctxctl mcp 是一个可选适配器,把同样五个命令作为 MCP 工具经 stdio 提供。CLI 始终是规范接口;适配器运行时,CLI 的行为没有任何改变。

工具 包装的命令
ctxctl_outline outline <file>
ctxctl_symbol symbol <file> --name <s>
ctxctl_read read <file> --lines N-M
ctxctl_deps deps <file>
ctxctl_exec exec <cmd> [--keep <pat>]

结果以纯文本返回,附带与 CLI 相同的 saved% 统计,包装为 { content: [{ type: "text", text }] }。失败(文件不存在、符号未找到、参数错误)以 isError: true 结果返回,绝不是协议错误。被包裹的命令以非零码退出时,ctxctl_exec 调用会在文本前加上 exit code N

把 ctxctl 添加到任何支持启动 stdio 服务器的 MCP 客户端:

{
"mcpServers": {
"ctxctl": {
"command": "ctxctl",
"args": ["mcp"]
}
}
}

这种写法适用于 opencode、Cursor、Claude Desktop 以及其他 MCP 原生客户端。

  • 基于 stdio 的换行分隔 JSON-RPC 2.0。
  • initializeprotocolVersion: "2025-03-26"、工具能力与服务器信息(name: "ctxctl")响应。
  • 通知(没有 id 的消息)不会产生响应。
  • 畸形 JSON 返回 JSON-RPC 错误 -32700;带 id 但缺少 method 的消息返回 -32600(无效请求);未知方法返回 -32601
  • 配置解析与 CLI 完全一致,包括 --config
  • stdin 干净 EOF 时服务器以 0 退出。