Docs
Refer friends. Keep the rewards coming!Your friend can unlock up to 10M tokens · earn up to 30% revenue share.
+500K TokensGenerate link

MCP 服务安装实战 (Archive)

Archived original-language source from the legacy CrabClaw docs. This page is intentionally not machine-translated.

本教程将带你体验三种方式为 Crab Claw 智能体添加 MCP 工具能力——自然语言安装、Git 链接部署、跨工具导入。

前置条件

  • Crab Claw 已安装并运行
  • Node.js 18+(用于 npm 类 MCP 服务)
  • Git(用于 Git 链接安装)

场景一:自然语言安装 PostgreSQL 查询工具

第一步:描述需求

在聊天中直接告诉智能体你需要什么:

shell
> 我需要一个能查询 PostgreSQL 数据库的工具
> 我需要一个能查询 PostgreSQL 数据库的工具

智能体分析意图后自动执行安装:

shell
🔍 分析需求: 数据库查询 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 列出所有表

请配置数据库连接信息以开始使用。

第二步:配置连接参数

shell
> 数据库地址是 postgresql://user:pass@localhost:5432/mydb
> 数据库地址是 postgresql://user:pass@localhost:5432/mydb

智能体自动将连接信息写入配置:

json
{
  "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"
        }
      }
    }
  }
}

第三步:使用新能力

shell
> 查看数据库里有哪些表
> 查询 users 表最近注册的 10 个用户
> 统计每个月的新增用户数
> 查看数据库里有哪些表
> 查询 users 表最近注册的 10 个用户
> 统计每个月的新增用户数

智能体自动调用 MCP 工具完成查询,结果直接展示在对话中。

场景二:Git 链接一键部署

方式 A:在聊天中

shell
> 帮我安装这个 MCP 服务: https://github.com/modelcontextprotocol/server-github
> 帮我安装这个 MCP 服务: https://github.com/modelcontextprotocol/server-github

智能体自动完成:

shell
📥 克隆仓库: 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 命令

bash
crabclaw mcp install https://github.com/modelcontextprotocol/server-filesystem
crabclaw mcp install https://github.com/modelcontextprotocol/server-filesystem

输出:

shell
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_search
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_search

场景三:从 Claude Desktop 导入

如果你已经在 Claude Desktop 中配置了 MCP 服务,一键迁移:

bash
crabclaw mcp import
crabclaw mcp import

输出:

shell
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.

也可以在聊天中操作:

shell
> 把我 Claude Desktop 里的 MCP 服务导入过来
> 把我 Claude Desktop 里的 MCP 服务导入过来

管理已安装的 MCP 服务

查看状态

shell
> 列出我安装的所有 MCP 服务
> 列出我安装的所有 MCP 服务

或:

bash
crabclaw mcp list
crabclaw mcp list

输出:

shell
MCP Servers (3 installed):
 postgres 3 tools, running
 github 8 tools, running
  ⏹️ filesystem 4 tools, stopped
MCP Servers (3 installed):
 postgres 3 tools, running
 github 8 tools, running
  ⏹️ filesystem 4 tools, stopped

启停管理

shell
> 暂停 postgres MCP 服务
> 重新启动 filesystem 服务
> 更新 github MCP 到最新版
> 卸载 filesystem MCP
> 暂停 postgres MCP 服务
> 重新启动 filesystem 服务
> 更新 github MCP 到最新版
> 卸载 filesystem MCP

对应 CLI:

bash
crabclaw mcp stop postgres
crabclaw mcp start filesystem
crabclaw mcp update github
crabclaw mcp uninstall filesystem
crabclaw mcp stop postgres
crabclaw mcp start filesystem
crabclaw mcp update github
crabclaw mcp uninstall filesystem

验证能力树注册

安装后可以验证工具是否正确注册到能力树:

shell
> 诊断 mcp_postgres_query 的能力树状态
> 诊断 mcp_postgres_query 的能力树状态

智能体调用 capability_manage,输出:

shell
Tool: mcp_postgres_query
  Tree Node: dynamic/mcp_postgres_query
  Type: dynamic (MCP)
  Min Tier: task_write
  Approval: plan_confirm
  Bindable: true
  Status: active
Tool: 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

相关文档:MCP 自动化 · 能力树与权限 · 插件开发