使用Python SDK编写MCP服务器文档
先决条件
uv包管理器(可选,但 强烈推荐)- claude桌面或光标(基本上是任何MCP客户端)
- Serper帐户-搜索工具(免费,无需信用卡)
安装
将MCP添加到Python项目中
uv add "mcp[cli]"或者,对于使用pip作为依赖关系的项目:
pip install "mcp[cli]"开发人员快速入门
克隆存储库
git clone https://github.com/shivansh12t/docs-mcp-pythonsdk
cd docs-mcp-pythonsdk安装依赖项(可选)
uv pip sync根据template.env创建.env
SERPER_API_KEY=将MCP服务器添加到VSCode副驾驶聊天
- 首选
.vscode/mcp.json - 将args更新为mcp服务器的绝对路径
- 它应该已经启动并运行了
Agent Mode - 如果您有任何问题,请访问 在VSCode副驾驶聊天中使用MCP服务器
将MCP添加到客户端-此处为Claude Desktop
- 打开克劳德桌面,转到设置
shift + , Edit Configurations- 将以下带有正确路径的json添加到
claude_desktop_configurations.json
{
"mcpServers": {
"documentation": {
"command": "uv",
"args": [
"--directory",
"absolute/path/to/the/project",
"run",
"main.py"
]
}
}
}- 重启克劳德&如果你在聊天室附近看到一个锤子标志,恭喜你的MCP已启动并运行
使用MCP检查器
npx @modelcontextprotocol/inspector uv run main.py