MCP客户端工具

mcpkit是一个轻量级MCP客户端,可将任何MCP服务器转换为CLI命令和代理技能,减少上下文膨胀。

  • by balakumardev
  • TypeScript
  • 本地部署
  • 9 星标
  • 更新于
在 GitHub 查看 balakumardev/mcpx

使用说明

麦普基特

MCP客户端,将任何MCP服务器转换为CLI命令+轻量级代理技能——零上下文膨胀。

支持的代理: Claude Code、Cursor、Windsurf、Augment Code、OpenAI Codex CLI、OpenClaw

为什么

AI编码代理每次都会将完整的MCP工具模式加载到上下文中,浪费令牌。mcpkit解决了这个问题——它连接到任何MCP服务器,生成按需技能文件,并为代理提供一个简单的 mcpkit call CLI调用工具。代理仅在相关时读取技能,并通过CLI调用工具,而不是将模式保存在内存中。

安装

npm install -g @balakumar.dev/mcpkit

需要Node.js>=20。

快速开始

# Install from a command string
mcpkit install "npx -y @modelcontextprotocol/server-filesystem /tmp" --name filesystem

# Install from standard JSON format
mcpkit install '{"mcpServers":{"github":{"command":"npx","args":["-y","@modelcontextprotocol/server-github"],"env":{"GITHUB_TOKEN":"..."}}}}'

# Install from a .json file
mcpkit install ./my-servers.json

# Install for specific agents
mcpkit install "npx -y @modelcontextprotocol/server-filesystem /tmp" --name filesystem --agent claude-code --agent cursor

# Install at project level instead of global
mcpkit install "npx -y @modelcontextprotocol/server-filesystem /tmp" --name filesystem --scope project

命令

mcpkit install <server-spec>

将MCP服务器工具作为代理技能文件安装。

Arguments:
  server-spec          Command string, URL, JSON string, or .json file path

Options:
  -n, --name <name>    Custom server name
  -a, --agent <agent>  Target agent (repeatable: --agent claude-code --agent cursor)
  --scope <scope>      global or project (default: global)
  -e, --env <env>      Environment variables for stdio (repeatable: -e KEY=VALUE)
  -d, --description    Custom skill description (overrides auto-generated)
  --header <header>    HTTP headers (repeatable: --header "Key: Value")
  --auth <type>        Authentication type (oauth)
  --dry-run            Preview generated files without writing

输入格式:

格式 示例
命令字符串 "npx -y @modelcontextprotocol/server-filesystem /tmp"
HTTP网址 "https://mcp.example.com/api"
SSE URL "https://mcp.example.com/sse"
内联JSON '{"mcpServers":{"name":{...}}}'
JSON文件 ./servers.json

JSON格式支持标准 mcpServers Claude Desktop、Cursor等使用的结构:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
      "env": {}
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": { "GITHUB_TOKEN": "ghp_..." }
    }
  }
}

mcpkit call <server> <tool> [params]

调用已注册服务器上的工具。这就是生成的技能文件教代理运行的内容。对于OAuth服务器,令牌会自动使用。

默认情况下, mcpkit call 连接到服务器,运行一次工具,打印结果,然后断开连接。

  • 使用 --chain 在同一MCP会话中顺序运行多个工具调用。当稍后的工具调用依赖于前一个工具调用返回的数据时,这很有用。
  • 对于 stdio 服务器配置为 runtime.mode: persistent,正常 mcpkit call 自动启动或重用后台运行时,并立即返回工具结果。这使得面向代理的命令形状保持不变,同时在幕后重用一个长期存在的MCP会话。
  • 使用 --keepalive 用于手动阻塞会话,使stdio服务器进程保持活动状态,直到 Ctrl+C这主要用于调试或一次性手动工作流;它与自动后台运行时路径是分开的。
mcpkit call filesystem read_file '{"path":"/tmp/example.txt"}'
mcpkit call github search_repositories '{"query":"mcpkit"}'
mcpkit call postman list_collections '{}'   # OAuth tokens applied automatically

# Reuse one session for multiple tool calls
mcpkit call myserver login '{}' --chain 'search:{"query":"hello","token":"$prev.token"}'

# Auto-start and reuse a background stdio runtime for future calls
mcpkit install "npx -y @browsermcp/mcp" -n browsermcp --runtime persistent --runtime-idle-timeout 900
mcpkit call browsermcp create_session '{}'
mcpkit call browsermcp browser_snapshot '{}'

# Keep a stdio server process alive after the initial call in the foreground
mcpkit call browsermcp create_session '{}' --keepalive

当使用 --chain,可以用引用前一个JSON结果中的值 $prev.field。如果之前的结果是纯文本而不是JSON,则可以作为 $prev._text.

mcpkit runtime <subcommand>

检查或停止由管理的持久stdio运行时 mcpkit.

mcpkit runtime status
mcpkit runtime status browsermcp
mcpkit runtime stop browsermcp

mcpkit list [server]

列出特定服务器上已注册的服务器或工具。

mcpkit list                # Show all registered servers
mcpkit list filesystem     # Show tools on filesystem server

mcpkit view <name>

显示已注册服务器的完整配置——传输、环境变量、标头、身份验证和元数据。

mcpkit view postman            # Formatted output
mcpkit view postman --yaml     # Raw YAML entry

mcpkit edit <name>

修改已注册服务器的配置,而无需重新安装。

Options:
  --env <KEY=VALUE>          Add/update env var (stdio only, repeatable)
  --remove-env <KEY>         Remove env var (stdio only, repeatable)
  --header <Key: Value>      Add/update header (http/sse only, repeatable)
  --remove-header <KEY>      Remove header (http/sse only, repeatable)
  --auth <type>              Set auth type (oauth or none)
  --description <text>       Set server description
  --name <new-name>          Rename the server
mcpkit edit myapi --auth oauth              # Enable OAuth on existing server
mcpkit edit myapi --auth none               # Remove OAuth
mcpkit edit myapi --header "X-Custom: val"  # Add a header
mcpkit edit github --env GITHUB_TOKEN=ghp_xxx
mcpkit edit github --name gh                # Rename

mcpkit update [name]

重新发现工具并重新生成技能文件。自动处理服务器的OAuth重新身份验证 auth: oauth.

mcpkit update              # Update all servers
mcpkit update filesystem   # Update one server

mcpkit sync [name]

重新生成丢失的技能文件并重新检测新安装的代理。不像 update,跳过技能文件已存在的服务器(使用 --force 以覆盖)。

mcpkit sync                # Sync all — only regenerates missing skill files
mcpkit sync github         # Sync a specific server
mcpkit sync --force        # Regenerate all skill files
mcpkit sync --dry-run      # Preview what would be synced

mcpkit remove <name>

卸载服务器--删除技能文件和注册表项。

mcpkit remove filesystem
mcpkit remove filesystem --agent cursor   # Remove only from Cursor

mcpkit auth <name>

管理服务器的OAuth身份验证。

mcpkit auth postman             # Run OAuth flow
mcpkit auth postman --status    # Check if authenticated
mcpkit auth postman --reset     # Clear tokens and re-authenticate

认证

Env Var扩建

标头和stdio环境值支持 ${VAR_NAME} 语法。变量按原样存储在注册表中,并在调用时从您的环境中解析:

mcpkit install https://api.example.com --header "Authorization: Bearer \${MY_API_KEY}"
# servers.yaml stores: Authorization: Bearer ${MY_API_KEY}
# At call time: resolves to the actual value from process.env

OAuth

对于需要OAuth的MCP服务器(例如Postman、Linear、Vercel),请使用 --auth oauth 标志:

# Install with OAuth — browser opens for authorization during install
mcpkit install https://mcp.postman.com/mcp --auth oauth -n postman

# Tools are discovered after auth, and calls use cached tokens automatically
mcpkit call postman list_collections '{}'

将OAuth添加到现有服务器:

# If you already installed a server without --auth, enable it later
mcpkit edit postman --auth oauth
mcpkit auth postman

管理OAuth令牌:

mcpkit auth postman --status    # Check if authenticated
mcpkit auth postman --reset     # Clear tokens and re-authenticate
mcpkit auth postman             # Run OAuth flow (re-auth or first-time)

OAuth凭据存储在 ~/.mcpkit/credentials.json 具有受限的文件权限(模式0600)。令牌过期时会自动刷新。这 call, update,以及 install 所有命令都透明地处理OAuth——如果缓存了令牌,则使用它们;如果过期,系统将提示您重新授权。

范围:全球vs项目

范围 标志 行为
全球 --scope global (默认) 用户级别,适用于所有项目
项目 --scope project 每个项目,已签入repo

技能去向何方

所有代理商都使用 agentskills.io 网站 开放标准-a SKILL.md 技能目录中的文件。

代理 全球 项目
克劳德代码 ~/.claude/skills/mcpkit-<name>/SKILL.md .claude/skills/mcpkit-<name>/SKILL.md
光标 ~/.cursor/skills/mcpkit-<name>/SKILL.md .cursor/skills/mcpkit-<name>/SKILL.md
风帆冲浪 ~/.codeium/windsurf/skills/mcpkit-<name>/SKILL.md .windsurf/skills/mcpkit-<name>/SKILL.md
扩充 ~/.augment/skills/mcpkit-<name>/SKILL.md .augment/skills/mcpkit-<name>/SKILL.md
Codex CLI ~/.codex/skills/mcpkit-<name>/SKILL.md .agents/skills/mcpkit-<name>/SKILL.md
OpenClaw ~/.openclaw/skills/mcpkit-<name>/SKILL.md skills/mcpkit-<name>/SKILL.md

为什么不直接使用工具搜索?

Claude Code中存在工具搜索,但问题是可靠性。它使用regex/BM25按需查找工具,但会遗漏一些东西。工具调用不会发生,因为搜索与正确的工具名称不匹配。

有效的设置:在MCP配置中始终保持基本MCP(您在每个会话中使用的MCP)打开。你需要的东西,比如浏览器自动化、谷歌工作区等,可以通过mcpkit作为技能进行安装。一项技能会在系统提示中添加约2行,并清楚地描述何时使用它。代理每一次都会看到它并可靠地触发它。不涉及搜索。

另一件事是工具搜索仅适用于Claude Code。如果你使用Cursor、Codex或Windsurf,你根本没有它。mcpkit从同一个安装中为所有人生成技能。

因此,它不会与工具搜索竞争。它更像是:将您的核心MCP保持为MCP,其余部分使用mcpkit,这样它们就很轻,可以跨代理使用,而不会使您的上下文膨胀。

运作原理

  1. 解决 --mcpkit从加载保存的服务器配置 ~/.mcpkit/servers.yaml
  2. 连接 --对于一次性服务器,mcpkit直接使用stdio、HTTP或SSE连接;对于持久性stdio服务器,它会自动启动或重用本地后台运行时
  3. 发现 --电话 tools/list 获取所有可用的工具及其模式
  4. 生成 --使用工具文档和 mcpkit call 例子
  5. 注册 --将服务器配置保存到 ~/.mcpkit/servers.yaml 用于未来的通话

当代理遇到与技能匹配的任务时,它会读取技能文件并运行:

mcpkit call <server> <tool> '{"param": "value"}'

mcpkit从注册表中查找服务器传输,然后进行一次性连接或将调用转发到配置的持久运行时,并返回结果。

代理自动检测

如果没有 --agent 如果提供了标志,mcpkit会通过检查其配置目录来检测安装了哪些代理(~/.claude/, .cursor/, ~/.codex/, .windsurf/, ~/.augment/, ~/.openclaw/).回落到 claude-code 如果没有检测到。

注册表

服务器配置存储在 ~/.mcpkit/servers.yaml:

version: 1
servers:
  filesystem:
    name: filesystem
    transport:
      type: stdio
      command: npx
      args:
        - -y
        - "@modelcontextprotocol/server-filesystem"
        - /tmp
    toolCount: 14
    agents:
      - claude-code
    createdAt: "2025-01-01T00:00:00.000Z"
    updatedAt: "2025-01-01T00:00:00.000Z"
  postman:
    name: postman
    transport:
      type: http
      url: https://mcp.postman.com/mcp
      auth: oauth
    toolCount: 126
    agents:
      - claude-code
    createdAt: "2025-01-01T00:00:00.000Z"
    updatedAt: "2025-01-01T00:00:00.000Z"

许可证

麻省理工学院