关于 mcp-client
mcp-client 是用于连接和操作 MCP 服务的通用客户端技能,通过按需加载工具架构,减少一次性将大量信息载入上下文。它支持列出已配置服务和工具,并调用工具。
主要功能
- 01按需获取工具架构
- 02列出已配置的 MCP 服务
- 03查看工具及其参数架构
- 04通过参数调用工具
- 05支持多种传输配置
适用场景
- 01检查已配置的 MCP 服务
- 02了解某个服务提供的工具及参数
- 03调用 Zapier 或其他配置服务的工具
- 04连接本地 stdio 或远程 MCP 服务
MCP 相关
它通过配置连接 MCP 服务,支持命令行 stdio、SSE 和 Streamable HTTP 等传输方式。客户端可发现工具架构并执行工具调用。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ coleam00/ second-brain-skills --skill mcp-client安装后在 Claude Code 中输入/mcp-client确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/example-mcp-config.jsonmcp-servers.mdpython-mcp-sdk.mdscripts/mcp_client.py详细介绍
通用 MCP 客户端
连接任意 MCP 服务,采用渐进式披露方式——按需加载工具架构,而不是一开始就把数千个词元全部塞入上下文。
技能位置
此技能位于:.claude/skills/mcp-client/
脚本路径: .claude/skills/mcp-client/scripts/mcp_client.py
配置
脚本会按以下顺序查找配置:
MCP_CONFIG_PATH环境变量(自定义路径)references/mcp-config.json(此技能的配置文件,推荐使用)- 项目根目录中的
.mcp.json ~/.claude.json
你的配置文件: .claude/skills/mcp-client/references/mcp-config.json
编辑此文件以添加 API 密钥。示例文件(example-mcp-config.json)作为参考模板保留。
如果用户尚未提供 Zapier API 密钥,请向他们索取。
运行命令
所有命令都使用脚本 .claude/skills/mcp-client/scripts/mcp_client.py:
# List configured servers
python .claude/skills/mcp-client/scripts/mcp_client.py servers
# List tools from a server
python .claude/skills/mcp-client/scripts/mcp_client.py tools <server_name>
# Call a tool
python .claude/skills/mcp-client/scripts/mcp_client.py call <server> <tool> '{"arg": "value"}'
工作流
- 检查配置是否存在 - 运行
servers命令。如果出错,请创建.mcp.json - 列出服务 - 查看已配置的 MCP 服务
- 列出工具 - 获取特定服务的工具架构
- 调用工具 - 使用参数执行工具
命令参考
| 命令 | 说明 |
|---|---|
servers | 列出所有已配置的 MCP 服务 |
tools <server> | 列出工具及其完整参数架构 |
call <server> <tool> '<json>' | 使用参数执行工具 |
示例:Zapier
# 1. List servers to confirm Zapier is configured
python .claude/skills/mcp-client/scripts/mcp_client.py servers
# 2. List Zapier tools
python .claude/skills/mcp-client/scripts/mcp_client.py tools zapier
# 3. Call a Zapier tool
python .claude/skills/mcp-client/scripts/mcp_client.py call zapier <tool_name> '{"param": "value"}'
示例:Sequential Thinking
# 1. List tools
python .claude/skills/mcp-client/scripts/mcp_client.py tools sequential-thinking
# 2. Use sequential thinking
python .claude/skills/mcp-client/scripts/mcp_client.py call sequential-thinking sequentialthinking '{"thought": "Breaking down the problem...", "thoughtNumber": 1, "totalThoughts": 5, "nextThoughtNeeded": true}'
配置格式
配置文件格式(references/mcp-config.json):
{
"mcpServers": {
"zapier": {
"url": "https://mcp.zapier.com/api/v1/connect",
"api_key": "your-api-key"
},
"sequential-thinking": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-sequential-thinking"]
}
}
}
传输方式检测:
url+api_key→ 使用 Bearer 身份验证的 FastMCP(Zapier)command+args→ stdio(如 sequential-thinking 等本地服务)- 以
/sse结尾的url→ SSE 传输 - 以
/mcp结尾的url→ Streamable HTTP
错误处理
错误会以 JSON 格式返回:
{"error": "message", "type": "configuration|validation|connection"}
configuration- 未找到配置文件。请创建.mcp.jsonvalidation- 服务名称或工具名称无效connection- 无法连接到服务
依赖项
pip install mcp fastmcp
参考资料
references/example-mcp-config.json- 配置文件模板references/mcp-servers.md- 常见服务配置references/python-mcp-sdk.md- Python SDK 文档
评论
支持 Markdown