MCP 服务安装实战
用自然语言和 Git 链接为智能体添加数据库查询、GitHub 操作等新能力
本教程将带你体验三种方式为 Crab Claw 智能体添加 MCP 工具能力——自然语言安装、Git 链接部署、跨工具导入。
前置条件
- Crab Claw 已安装并运行
- Node.js 18+(用于 npm 类 MCP 服务)
- Git(用于 Git 链接安装)
场景一:自然语言安装 PostgreSQL 查询工具
第一步:描述需求
在聊天中直接告诉智能体你需要什么:
> 我需要一个能查询 PostgreSQL 数据库的工具> 我需要一个能查询 PostgreSQL 数据库的工具智能体分析意图后自动执行安装:
🔍 分析需求: 数据库查询 → PostgreSQL
📦 找到匹配: @modelcontextprotocol/server-postgres
⚙️ 安装中: npx -y @modelcontextprotocol/server-postgres
✅ 安装完成
已注册 3 个新工具:
- mcp_postgres_query → 执行 SQL 查询
- mcp_postgres_schema → 查看数据库结构
- mcp_postgres_tables → 列出所有表
请配置数据库连接信息以开始使用。🔍 分析需求: 数据库查询 → PostgreSQL
📦 找到匹配: @modelcontextprotocol/server-postgres
⚙️ 安装中: npx -y @modelcontextprotocol/server-postgres
✅ 安装完成
已注册 3 个新工具:
- mcp_postgres_query → 执行 SQL 查询
- mcp_postgres_schema → 查看数据库结构
- mcp_postgres_tables → 列出所有表
请配置数据库连接信息以开始使用。第二步:配置连接参数
> 数据库地址是 postgresql://user:pass@localhost:5432/mydb> 数据库地址是 postgresql://user:pass@localhost:5432/mydb智能体自动将连接信息写入配置:
{
"mcp": {
"servers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"
}
}
}
}
}{
"mcp": {
"servers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/mydb"
}
}
}
}
}第三步:使用新能力
> 查看数据库里有哪些表
> 查询 users 表最近注册的 10 个用户
> 统计每个月的新增用户数> 查看数据库里有哪些表
> 查询 users 表最近注册的 10 个用户
> 统计每个月的新增用户数智能体自动调用 MCP 工具完成查询,结果直接展示在对话中。
场景二:Git 链接一键部署
方式 A:在聊天中
> 帮我安装这个 MCP 服务: https://github.com/modelcontextprotocol/server-github> 帮我安装这个 MCP 服务: https://github.com/modelcontextprotocol/server-github智能体自动完成:
📥 克隆仓库: server-github
📋 检测项目类型: Node.js (package.json)
📦 安装依赖: npm install
🔗 解析 MCP manifest
🚀 启动 MCP server (stdio)
✅ 注册到能力树
已注册工具:
- mcp_github_create_issue
- mcp_github_search_repos
- mcp_github_create_pr
- mcp_github_list_files
...
需要配置 GitHub Token 才能使用,请提供你的 Personal Access Token。📥 克隆仓库: server-github
📋 检测项目类型: Node.js (package.json)
📦 安装依赖: npm install
🔗 解析 MCP manifest
🚀 启动 MCP server (stdio)
✅ 注册到能力树
已注册工具:
- mcp_github_create_issue
- mcp_github_search_repos
- mcp_github_create_pr
- mcp_github_list_files
...
需要配置 GitHub Token 才能使用,请提供你的 Personal Access Token。方式 B:CLI 命令
crabclaw mcp install https://github.com/modelcontextprotocol/server-filesystemcrabclaw mcp install https://github.com/modelcontextprotocol/server-filesystem输出:
Installing MCP server from https://github.com/modelcontextprotocol/server-filesystem
Cloning... ✓
Detecting project type... Node.js
Installing dependencies... ✓
Starting server... ✓
Registered 4 tools: mcp_fs_read, mcp_fs_write, mcp_fs_list, mcp_fs_searchInstalling MCP server from https://github.com/modelcontextprotocol/server-filesystem
Cloning... ✓
Detecting project type... Node.js
Installing dependencies... ✓
Starting server... ✓
Registered 4 tools: mcp_fs_read, mcp_fs_write, mcp_fs_list, mcp_fs_search场景三:从 Claude Desktop 导入
如果你已经在 Claude Desktop 中配置了 MCP 服务,一键迁移:
crabclaw mcp importcrabclaw mcp import输出:
Found MCP config from Claude Desktop:
✓ server-postgres (3 tools)
✓ server-github (8 tools)
✓ server-filesystem (4 tools)
Imported 3 MCP servers with 15 tools total.
All tools registered to capability tree.Found MCP config from Claude Desktop:
✓ server-postgres (3 tools)
✓ server-github (8 tools)
✓ server-filesystem (4 tools)
Imported 3 MCP servers with 15 tools total.
All tools registered to capability tree.也可以在聊天中操作:
> 把我 Claude Desktop 里的 MCP 服务导入过来> 把我 Claude Desktop 里的 MCP 服务导入过来管理已安装的 MCP 服务
查看状态
> 列出我安装的所有 MCP 服务> 列出我安装的所有 MCP 服务或:
crabclaw mcp listcrabclaw mcp list输出:
MCP Servers (3 installed):
✅ postgres — 3 tools, running
✅ github — 8 tools, running
⏹️ filesystem — 4 tools, stoppedMCP Servers (3 installed):
✅ postgres — 3 tools, running
✅ github — 8 tools, running
⏹️ filesystem — 4 tools, stopped启停管理
> 暂停 postgres MCP 服务
> 重新启动 filesystem 服务
> 更新 github MCP 到最新版
> 卸载 filesystem MCP> 暂停 postgres MCP 服务
> 重新启动 filesystem 服务
> 更新 github MCP 到最新版
> 卸载 filesystem MCP对应 CLI:
crabclaw mcp stop postgres
crabclaw mcp start filesystem
crabclaw mcp update github
crabclaw mcp uninstall filesystemcrabclaw mcp stop postgres
crabclaw mcp start filesystem
crabclaw mcp update github
crabclaw mcp uninstall filesystem验证能力树注册
安装后可以验证工具是否正确注册到能力树:
> 诊断 mcp_postgres_query 的能力树状态> 诊断 mcp_postgres_query 的能力树状态智能体调用 capability_manage,输出:
Tool: mcp_postgres_query
Tree Node: dynamic/mcp_postgres_query
Type: dynamic (MCP)
Min Tier: task_write
Approval: plan_confirm
Bindable: true
Status: activeTool: mcp_postgres_query
Tree Node: dynamic/mcp_postgres_query
Type: dynamic (MCP)
Min Tier: task_write
Approval: plan_confirm
Bindable: true
Status: active安全说明
- MCP 工具注册后遵循能力树的审批门控(
task_write级查询需plan_confirm) - 敏感凭证通过
env运行时注入,不落盘明文 - 网络访问受沙箱网络策略约束
- 你可以随时用
crabclaw mcp stop停止任何 MCP 服务
常见问题
安装失败:npm not found?
- 确认 Node.js 已安装:
node --version - 部分 MCP 服务需要 Python:
python3 --version
工具调用返回错误?
- 检查环境变量是否配置(如 DATABASE_URL、GITHUB_TOKEN)
- 查看 MCP 服务日志:
crabclaw mcp status <name>
能力树中看不到新工具?
- MCP 工具以
mcp_前缀注册到dynamic/分支 - 确认服务正在运行:
crabclaw mcp list