开始构建你自己的服务器,以便在 Claude Desktop 和其他客户端中使用。
get-alerts
和 get-forecast
。然后,我们将服务器连接到一个 MCP host(在本例中是 Claude for Desktop):
为什么选择 Claude for Desktop 而不是 Claude.ai?
uv
并设置我们的 Python 项目和环境:uv
命令被识别。现在,让我们创建并设置我们的项目:weather.py
文件的顶部:uv run weather.py
以确认一切正常。现在让我们从现有的 MCP host,Claude for Desktop 测试你的 server。~/Library/Application Support/Claude/claude_desktop_config.json
中的 Claude for Desktop App configuration。如果该 file 不存在,请确保创建它。例如,如果你安装了 VS Code:mcpServers
key 中添加你的 servers。只有正确配置了至少一个 server,MCP UI 元素才会显示在 Claude for Desktop 中。在本例中,我们将添加我们的单个天气服务器,如下所示:command
字段中放入 uv
executable 的完整 path。你可以在 MacOS/Linux 上运行 which uv
或在 Windows 上运行 where uv
来获取它。uv --directory /ABSOLUTE/PATH/TO/PARENT/FOLDER/weather run weather.py
来启动它weather
server 中暴露的两个 tools。你可以通过查找锤子 Claude for Desktop 集成问题
~/Library/Logs/Claude
中的 log files:mcp.log
将包含关于 MCP 连接和连接失败的通用 logging。mcp-server-SERVERNAME.log
的 Files 将包含来自命名 server 的错误 (stderr) logging。claude_desktop_config.json
file 语法Weather API 问题