本文档指导你如何从零开始搭建 MCP 运行环境。
MCP 服务器大多基于 Node.js 运行,需要 Node.js 22+ 版本。
# 安装 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:
node --version部分 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
SearXNG 是一个隐私保护的搜索引擎,可以被 MCP 调用。
# 安装 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/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
npm install -g bazi-mcp
其他 MCP 服务器会通过 npx 自动下载,无需手动安装。
# 创建配置目录(macOS 示例)
mkdir -p ~/Library/Application\ Support/Claude
# 复制配置文件
cp /path/to/mcp.json.example ~/Library/Application\ Support/Claude/claude_desktop_config.json
# 编辑配置文件,修改路径为你自己的
配置文件位置:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json打开配置文件,修改以下内容:
{
"mcpServers": {
"searxng": {
"command": "/path/to/your/npx",
"env": {
"SEARXNG_INSTANCES": "http://localhost:8080"
}
}
}
}
需要修改的路径:
searxng.command - npx 的完整路径(运行 which npx 查看)novel-filesystem 中的目录路径sqlite 中的数据库路径# 创建小说工作目录
mkdir -p ~/novels
mkdir -p ~/writing
# 或者使用配置中的路径
mkdir -p /workspace/novels
mkdir -p /workspace/writing
node --version npm --version npx --version
# 访问 http://localhost:8080
# 或运行
curl http://localhost:8080
重启 Claude Desktop 后,尝试以下命令:
"搜索今天的新闻" "给我排一个 1990年5月15日早上8点的八字" "掷一个 20 面骰子"
解决:
# 检查 node 安装
which node
which npx
# 如果找不到,添加环境变量
export PATH="$HOME/.nvm/versions/node/v22.x.x/bin:$PATH"
解决:
# 检查容器状态
docker ps
# 查看日志
docker logs searxng
# 检查端口是否被占用
netstat -tlnp | grep 8080
解决:
~/Library/Logs/Claude/%APPDATA%\Claude\logs\环境搭建完成后,查看 README.md 了解所有 MCP 的功能和使用方法。