本指南详细介绍了如何设置与 Claude Desktop 集成的 Model Control Protocol (MCP) 服务器。MCP 服务器可让 Claude 与外部系统和 API(如 AWS 服务、GitHub)交互,从而扩展其能力。
uv 包管理器使用 uv 运行以下命令安装所需包:
uv add MCP --platforms linux/x86_64,linux/arm64,osx/x86_64,osx/arm64,win/x86_64,win/arm64
创建 ~/.config/mcp/config.json 文件,并添加以下内容:
{
"version": "1.0",
"servers": {
"local": {
"host": "localhost",
"port": 5005,
"type": "grpc"
}
},
"apis": {
"aws": {
"region": "us-east-2",
"access_key_id": "YOUR_ACCESS_KEY_ID",
"secret_access_key": "YOUR_SECRET_ACCESS_KEY"
},
"github": {
"token": "YOUR_GITHUB_TOKEN"
}
}
}
在终端中运行以下命令启动 MCP 服务器:
uv run MCP --server local
验证 MCP 服务器是否正常运行:
curl http://localhost:5005/ping
预期输出:
{
"status": "success",
"message": "MCP server is running"
}
在 Claude Desktop 中,导航至 Edit > Settings。
在 Services 标签下,点击 Add Service 并输入以下信息:
http://localhost:5005点击 Add 完成配置。
在终端中运行以下命令设置环境变量:
export MCP_API_KEY="your_api_key"
编辑 ~/.config/mcp/config.json 文件并添加自定义依赖项:
{
"dependencies": {
"custom-package": "^1.0.0"
}
}
运行以下命令安装依赖项:
uv run MCP --install
在 ~/.config/mcp/errors.log 文件中查看错误日志。
解决方案: 检查服务器状态:
curl http://localhost:5005/ping
确保防火墙允许端口 5005 的流量。
解决方案:
验证 config.json 文件格式是否正确,必要时使用 JSON 校验工具进行检查。
import boto3
def list_ec2_instances():
ec2 = boto3.client('ec2', region_name='us-east-2')
instances = ec2.describe_instances()
return instances['Reservations']
import os
from github import Github
def get_repository_info(repo):
g = Github(os.getenv("GITHUB_TOKEN"))
repo = g.get_repo(repo)
return repo.raw_data