mcp2cli 用于把远端 MCP Server 暴露的工具,动态转换成本地命令行子命令。
它在启动时通过 tools/list 自动发现工具,并根据工具的 JSON Schema 生成参数与帮助信息。
- 通过 JSON 配置连接 MCP Streamable HTTP 服务端。
- 启动时自动发现工具并生成二级命令(例如
weather cityInfo)。 - 动态生成详细帮助,包括参数、输入 Schema、返回 Schema。
- 根据工具输入 Schema 做本地参数校验(含必填、类型、枚举)。
- 调用 MCP 工具并输出 JSON 结果。
- 支持安装 wrapper 命令(软链接)并自动关联配置文件。
go build -o mcp2cli ./cmd/mcp2cli或使用 Makefile:
make build
make test安装最新版:
curl -fsSL https://raw.githubusercontent.com/hengyunabc/mcp2cli/refs/heads/master/scripts/install-release.sh | bash安装指定版本:
curl -fsSL https://raw.githubusercontent.com/hengyunabc/mcp2cli/refs/heads/master/scripts/install-release.sh | VERSION=v0.1.0 bash安装脚本支持的环境变量:OWNER、REPO、BINARY、VERSION、INSTALL_DIR。
示例配置见 examples/weather.json。
./mcp2cli --config examples/weather.json --help
./mcp2cli --config examples/weather.json tools
./mcp2cli --config examples/weather.json cityInfo --help
./mcp2cli --config examples/weather.json cityInfo --name hkmcp2cli install weather --url https://example.com/mcp --token <token>安装后会生成:
~/.mcp2cli/bin/weather(指向mcp2cli的软链接)~/.mcp2cli/configs/weather.json
然后把 ~/.mcp2cli/bin 加入 PATH:
export PATH="$HOME/.mcp2cli/bin:$PATH"之后可直接调用:
weather --help
weather tools
weather cityInfo --help
weather cityInfo --name hk当以 weather 形式运行时,会自动读取 ~/.mcp2cli/configs/weather.json。
导入已有配置文件:
mcp2cli install weather --from-config /path/to/weather.json查看已安装 wrapper:
mcp2cli list删除 wrapper(默认同时删除配置):
mcp2cli remove weather仅删除 wrapper,保留配置:
mcp2cli remove weather --keep-config完整示例:
{
"name": "weather",
"server": {
"url": "https://example.com/mcp",
"transport": "streamable_http",
"timeout_seconds": 30
},
"auth": {
"type": "bearer",
"token": "${WEATHER_MCP_TOKEN}"
},
"cli": {
"description": "Weather MCP CLI",
"include_return_schema_in_help": true,
"pretty_json": false
}
}字段说明:
server.url:MCP 服务地址(必填)。server.transport:目前仅支持streamable_http。server.timeout_seconds:超时秒数,默认30。auth.type:可选,支持bearer。auth.token:当auth.type=bearer时必填。cli.description:CLI 描述文本。cli.include_return_schema_in_help:是否在帮助中显示返回 Schema,默认true。cli.pretty_json:是否美化 JSON 输出,默认false。
配置文件支持环境变量展开(例如 "${WEATHER_MCP_TOKEN}")。
mcp2cli --help
mcp2cli version
mcp2cli install --help
mcp2cli list
mcp2cli remove --help如果已安装 wrapper(如 weather):
weather --help
weather tools
weather <toolName> --help
weather <toolName> --arg valueMCP2CLI_CONFIG:可指定默认配置文件路径(等价于--config)。MCP2CLI_HOME:自定义安装根目录(默认~/.mcp2cli)。
0:成功1:通用错误2:参数校验错误3:连接或协议错误4:工具执行错误5:配置错误6:内部错误