logo
0
0
WeChat Login

MCP 环境初始化指南

本文档指导你如何从零开始搭建 MCP 运行环境。


📋 前置要求

  • Linux/macOS/Windows 系统
  • 管理员权限(用于安装软件)
  • 网络连接

1️⃣ 安装 Node.js

MCP 服务器大多基于 Node.js 运行,需要 Node.js 22+ 版本。

方法一:使用 NVM(推荐)

# 安装 NVM curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash # 重新加载 shell source ~/.bashrc # 或 source ~/.zshrc # 安装 Node.js 22 nvm install 22 nvm use 22 nvm alias default 22 # 验证安装 node --version # 应显示 v22.x.x npm --version # 应显示 10.x.x

方法二:直接安装

Ubuntu/Debian:

# 添加 NodeSource 源 curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - # 安装 Node.js sudo apt-get install -y nodejs # 验证 node --version npm --version

macOS:

# 使用 Homebrew 安装 brew install node@22 # 验证 node --version npm --version

Windows:

  1. 访问 https://nodejs.org/
  2. 下载 Node.js 22 LTS 版本
  3. 运行安装程序,按提示完成安装
  4. 打开 PowerShell 验证:node --version

2️⃣ 安装 uv(Python 工具)

部分 MCP 服务器使用 Python 的 uv 工具运行。

# Linux/macOS curl -LsSf https://astral.sh/uv/install.sh | sh # 重新加载 shell source ~/.bashrc # 或 source ~/.zshrc # 验证安装 uv --version

Windows:

# 使用 PowerShell powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # 验证 uv --version

3️⃣ 安装和配置 SearXNG

SearXNG 是一个隐私保护的搜索引擎,可以被 MCP 调用。

方法一:使用 Docker(推荐)

# 安装 Docker(如果未安装) # 参考:https://docs.docker.com/get-docker/ # 拉取 SearXNG 镜像 docker pull searxng/searxng # 创建配置文件目录 mkdir -p ~/searxng # 运行 SearXNG 容器 docker run -d \ --name searxng \ -p 8080:8080 \ -v ~/searxng:/etc/searxng \ searxng/searxng # 验证:浏览器访问 http://localhost:8080

方法二:本地安装

# 克隆仓库 git clone https://github.com/searxng/searxng.git ~/searxng cd ~/searxng # 安装依赖 python3 -m venv venv source venv/bin/activate pip install -e . # 运行 python -m searx.webapp # 服务将在 http://localhost:8080 启动

配置 SearXNG

编辑配置文件 ~/searxng/settings.yml

server: bind_address: "0.0.0.0" port: 8080 search: safe_search: 0 autocomplete: 'duckduckgo' # 启用需要的搜索引擎 engines: - name: bing disabled: false - name: baidu disabled: false - name: duckduckgo disabled: false

重启容器生效:

docker restart searxng

4️⃣ 安装 MCP 服务器依赖

全局安装 bazi-mcp(可选但推荐)

npm install -g bazi-mcp

其他 MCP 服务器

其他 MCP 服务器会通过 npx 自动下载,无需手动安装。


5️⃣ 配置 MCP 客户端

安装 Claude Desktop(推荐)

  1. 访问 https://claude.ai/download
  2. 下载并安装 Claude Desktop
  3. 打开设置 → Developer → Edit Config

复制配置文件

# 创建配置目录(macOS 示例) mkdir -p ~/Library/Application\ Support/Claude # 复制配置文件 cp /path/to/mcp.json.example ~/Library/Application\ Support/Claude/claude_desktop_config.json # 编辑配置文件,修改路径为你自己的

配置文件位置:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

修改配置文件中的路径

打开配置文件,修改以下内容:

{ "mcpServers": { "searxng": { "command": "/path/to/your/npx", "env": { "SEARXNG_INSTANCES": "http://localhost:8080" } } } }

需要修改的路径:

  1. searxng.command - npx 的完整路径(运行 which npx 查看)
  2. novel-filesystem 中的目录路径
  3. sqlite 中的数据库路径

6️⃣ 创建必要目录

# 创建小说工作目录 mkdir -p ~/novels mkdir -p ~/writing # 或者使用配置中的路径 mkdir -p /workspace/novels mkdir -p /workspace/writing

7️⃣ 验证安装

测试 Node.js

node --version npm --version npx --version

测试 SearXNG

# 访问 http://localhost:8080 # 或运行 curl http://localhost:8080

测试 MCP 服务器

重启 Claude Desktop 后,尝试以下命令:

"搜索今天的新闻" "给我排一个 1990年5月15日早上8点的八字" "掷一个 20 面骰子"

🛠️ 故障排查

问题 1:npx 命令找不到

解决:

# 检查 node 安装 which node which npx # 如果找不到,添加环境变量 export PATH="$HOME/.nvm/versions/node/v22.x.x/bin:$PATH"

问题 2:SearXNG 无法访问

解决:

# 检查容器状态 docker ps # 查看日志 docker logs searxng # 检查端口是否被占用 netstat -tlnp | grep 8080

问题 3:MCP 服务器报错

解决:

  1. 检查配置文件 JSON 格式是否正确
  2. 检查命令路径是否正确
  3. 检查文件/目录权限
  4. 查看 Claude Desktop 日志:
    • macOS: ~/Library/Logs/Claude/
    • Windows: %APPDATA%\Claude\logs\

📚 下一步

环境搭建完成后,查看 README.md 了解所有 MCP 的功能和使用方法。


🔗 参考链接

About

codebuddy skills,rules,agents,mcp配置

Language
Makefile100%