Skip to content

MCP 安装配置指南

本指南将详细介绍如何安装和配置 MCP (Model Context Protocol) 服务器,让您能够在支持的应用程序中使用 MCP 功能。

前置要求

系统要求

  • 操作系统: Windows 10+, macOS 10.15+, 或 Linux
  • Node.js: 版本 18.0 或更高(大多数 MCP 服务器需要)
  • Python: 版本 3.8 或更高(Python 服务器需要)

检查环境

bash
# 检查 Node.js 版本
node --version

# 检查 npm 版本
npm --version

# 检查 Python 版本(如果需要)
python --version

支持的客户端

Claude Desktop(推荐)

Claude Desktop 是目前对 MCP 支持最完整的客户端:

下载地址:

版本要求: Claude Desktop 1.0 或更高版本

其他客户端

  • Cursor: 内置 MCP 支持
  • VS Code: 通过扩展支持
  • 自定义应用: 使用 MCP SDK 开发

配置文件位置

不同系统的配置文件路径

macOS:

bash
~/Library/Application Support/Claude/claude_desktop_config.json

Windows:

bash
%APPDATA%\Claude\claude_desktop_config.json

Linux:

bash
~/.config/claude/claude_desktop_config.json

创建配置文件

如果配置文件不存在,需要手动创建:

bash
# macOS
mkdir -p ~/Library/Application\ Support/Claude
touch ~/Library/Application\ Support/Claude/claude_desktop_config.json

# Windows (PowerShell)
New-Item -ItemType Directory -Force -Path "$env:APPDATA\Claude"
New-Item -ItemType File -Force -Path "$env:APPDATA\Claude\claude_desktop_config.json"

# Linux
mkdir -p ~/.config/claude
touch ~/.config/claude/claude_desktop_config.json

基础配置结构

配置文件格式

json
{
  "mcpServers": {
    "server-name": {
      "command": "command-to-run",
      "args": ["arg1", "arg2"],
      "env": {
        "ENV_VAR": "value"
      }
    }
  }
}

配置参数说明

  • server-name: 服务器的唯一标识符
  • command: 启动服务器的命令
  • args: 传递给服务器的参数数组
  • env: 环境变量设置(可选)

常用服务器安装

1. 文件系统服务器

安装:

bash
# 测试安装
npx -y @modelcontextprotocol/server-filesystem --help

配置:

json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/path/to/allowed/directory"
      ]
    }
  }
}

示例配置(不同系统):

macOS:

json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/username/Documents"
      ]
    }
  }
}

Windows:

json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "C:\\Users\\username\\Documents"
      ]
    }
  }
}

2. 网络搜索服务器

安装:

bash
npx -y @modelcontextprotocol/server-brave-search --help

配置:

json
{
  "mcpServers": {
    "brave-search": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-brave-search"],
      "env": {
        "BRAVE_API_KEY": "your-brave-api-key-here"
      }
    }
  }
}

获取 API 密钥:

  1. 访问 Brave Search API
  2. 注册账户并获取 API 密钥
  3. 将密钥添加到配置中

3. 数据库服务器

PostgreSQL 服务器:

json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "POSTGRES_CONNECTION_STRING": "postgresql://username:password@localhost:5432/database"
      }
    }
  }
}

SQLite 服务器:

json
{
  "mcpServers": {
    "sqlite": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-sqlite",
        "/path/to/database.db"
      ]
    }
  }
}

高级配置

多服务器配置

json
{
  "mcpServers": {
    "filesystem-docs": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/path/to/documents"
      ]
    },
    "filesystem-projects": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/path/to/projects"
      ]
    },
    "brave-search": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-brave-search"],
      "env": {
        "BRAVE_API_KEY": "your-api-key"
      }
    }
  }
}

环境变量配置

json
{
  "mcpServers": {
    "custom-server": {
      "command": "node",
      "args": ["/path/to/server.js"],
      "env": {
        "NODE_ENV": "production",
        "DEBUG": "false",
        "API_KEY": "your-api-key",
        "DATABASE_URL": "your-database-url"
      }
    }
  }
}

本地开发服务器

json
{
  "mcpServers": {
    "local-dev": {
      "command": "node",
      "args": ["/absolute/path/to/your/server/dist/index.js"],
      "env": {
        "NODE_ENV": "development"
      }
    }
  }
}

验证安装

1. 检查配置文件语法

使用在线 JSON 验证器或命令行工具:

bash
# 使用 Node.js

Released under the MIT License.