关于 mcp-cli
mcp-cli 是用于发现 MCP 服务及其工具的命令行客户端,可查看工具参数和架构并调用工具。它还支持通过 Shell 串联调用,并以不同退出码区分客户端、服务端和网络错误。
主要功能
- 01列出已配置的服务和工具
- 02查看工具参数及 JSON 架构
- 03按名称搜索工具
- 04使用参数或标准输入 JSON 调用工具
- 05在 Shell 工作流中串联调用
适用场景
- 01查找可用的 MCP 工具
- 02调用前检查工具架构
- 03使用 JSON 输入运行工具
- 04将一个工具的输出传给后续调用
MCP 相关
该命令行客户端连接已配置的 MCP 服务,以发现和检查其中的工具,并根据提供的参数调用工具。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ philschmid/ mcp-cli --skill mcp-cli安装后在 Claude Code 中输入/mcp-cli确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
install.shREADME.mdbiome.jsonLICENSECHANGELOG.md.gitignorebun.lockmcp_servers.jsonpackage.json.github/workflows/release.ymlci.ymlscripts/release.shgenerate-system-instructions.tssrc/client.tsconfig.tsdaemon-client.tsdaemon.tserrors.tsindex.tsoutput.tsversion.tssrc/commands/grep.tscall.tsinfo.tslist.tstests/cli-errors.test.tsclient.test.tsconfig.test.tsfilter.test.tserrors.test.ts详细介绍
MCP-CLI
通过命令行访问 MCP 服务。MCP 支持与 GitHub、文件系统、数据库和 API 等外部系统交互。
命令
| 命令 | 输出 |
|---|---|
mcp-cli | 列出所有服务和工具 |
mcp-cli info <server> | 显示服务的工具和参数 |
mcp-cli info <server> <tool> | 获取工具的 JSON 架构 |
mcp-cli grep "<pattern>" | 按名称搜索工具 |
mcp-cli call <server> <tool> | 调用工具(无参数时从 stdin 读取 JSON) |
mcp-cli call <server> <tool> '<json>' | 使用参数调用工具 |
两种格式均可使用: <server> <tool> 或 <server>/<tool>
工作流
- 发现:
mcp-cli→ 查看可用服务 - 探索:
mcp-cli info <server>→ 查看带参数的工具 - 检查:
mcp-cli info <server> <tool>→ 获取完整的 JSON 架构 - 执行:
mcp-cli call <server> <tool> '<json>'→ 使用参数运行
示例
# List all servers
mcp-cli
# With descriptions
mcp-cli -d
# See server tools
mcp-cli info filesystem
# Get tool schema (both formats work)
mcp-cli info filesystem read_file
mcp-cli info filesystem/read_file
# Call tool
mcp-cli call filesystem read_file '{"path": "./README.md"}'
# Pipe from stdin (no '-' needed!)
cat args.json | mcp-cli call filesystem read_file
# Search for tools
mcp-cli grep "*file*"
# Output is raw text (pipe-friendly)
mcp-cli call filesystem read_file '{"path": "./file"}' | head -10
高级链式调用
# Chain: search files → read first match
mcp-cli call filesystem search_files '{"path": ".", "pattern": "*.md"}' \
| head -1 \
| xargs -I {} mcp-cli call filesystem read_file '{"path": "{}"}'
# Loop: process multiple files
mcp-cli call filesystem list_directory '{"path": "./src"}' \
| while read f; do mcp-cli call filesystem read_file "{\"path\": \"$f\"}"; done
# Conditional: check before reading
mcp-cli call filesystem list_directory '{"path": "."}' \
| grep -q "README" \
&& mcp-cli call filesystem read_file '{"path": "./README.md"}'
# Multi-server aggregation
{
mcp-cli call github search_repositories '{"query": "mcp", "per_page": 3}'
mcp-cli call filesystem list_directory '{"path": "."}'
}
# Save to file
mcp-cli call github get_file_contents '{"owner": "x", "repo": "y", "path": "z"}' > output.txt
注意: call 会直接输出原始文本内容(提取文本无需使用 jq)
选项
| 标志 | 用途 |
|---|---|
-d | 包含描述 |
-c <path> | 指定配置文件 |
常见错误
| 错误命令 | 错误 | 修复方法 |
|---|---|---|
mcp-cli server tool | AMBIGUOUS_COMMAND | 使用 call server tool 或 info server tool |
mcp-cli run server tool | UNKNOWN_SUBCOMMAND | 使用 call 替代 run |
mcp-cli list | UNKNOWN_SUBCOMMAND | 使用 info 替代 list |
mcp-cli call server | MISSING_ARGUMENT | 添加工具名称 |
mcp-cli call server tool {bad} | INVALID_JSON | 使用带引号的有效 JSON |
退出代码
0:成功1:客户端错误(参数错误、缺少配置)2:服务端错误(工具执行失败)3:网络错误
评论
支持 Markdown