本项目是一个借助 Model Context Protocol (MCP) 实现的服务器端工具,主要为 Claude AI 等大型语言模型提供功能支持。目前,服务器可提供 BMI 计算与天气信息查询两项主要服务。
本项目是使用 Model Context Protocol (MCP) 实现的服务器端工具,为大型语言模型(LLM)如 Claude AI 提供功能支持。下面为你介绍如何快速开启使用。
git clone https://github.com/yourusername/hello-mcp-server-python.git
cd hello-mcp-server-python
pip install httpx "mcp[cli]"
python server.py
# 或使用 MCP CLI
mcp run server.py
在项目根目录下创建或修改 mcp.json 文件,添加以下内容来配置服务器:
{
"mcpServers": {
"mcp-server-python": {
"command": "mcp",
"args": [
"run",
"/path/to/server.py"
]
}
}
}
直接在终端执行以下命令启动服务器:
python server.py
calculate_bmi:接受身高(cm)和体重(kg)作为输入,输出 BMI 指数。fetch_weather:根据城市名称查询天气信息。calculate_bmi --height 170 --weight 65
输出结果为 BMI 值。fetch_weather --city "北京"
返回指定城市的天气详情。在 server.py 中添加以下代码以配置天气 API 的密钥:
API_KEY = "your_api_key_here" # 替换为实际的 API 密钥
hello-mcp-server-python/
├── server.py # MCP 服务器主程序文件
└── requirements.txt # 依赖项管理文件(可选)
mcp.json 文件存在且配置正确。python server.py
本项目遵循 MIT 许可证协议。详细内容请参阅 LICENSE 文件。