本项目是一个基于FastAPI的模型上下文协议(MCP)服务器,专为Azure容器应用设计。它借助安全的、受API密钥保护的Server-Sent事件(SSE)接口,提供天气相关工具(如警报和预报),能与MCP兼容客户端(如Visual Studio Code或自定义脚本)集成。
此MCP服务器使用SSE传输并使用API密钥进行身份验证。下面为你介绍如何快速搭建和使用该服务器。
git clone https://github.com/KRVaghani/Azure-MCP-Server.git
cd Azure-MCP-Server
uv venv
uv sync
export API_KEYS=devkey # 或您选择的密钥
uv run fastapi dev main.py
本项目包含一个用于命令行交互的示例Python客户端(model_request_client.py),你可以按以下步骤操作:
python model_request_client.py
get_alerts(按美国州)或get_forecast(按纬度/经度)你可以使用curl命令进行测试:
curl -H "x-api-key: devkey" http://localhost:8000/sse
/sse(GET):主要的SSE端点,用于MCP协议通信。需要x-api-key头。/messages(SSE):内部使用的消息流端点(基于会话)。本项目是一个基于FastAPI的MCP服务器,通过Server-Sent事件(SSE)接口提供服务。SSE是一种允许服务器向客户端发送实时更新的技术,非常适合需要实时数据的应用场景。服务器使用API密钥进行身份验证,确保只有授权的客户端可以访问服务。
本项目采用MIT许可证(如需添加LICENSE文件)。
uv venv
uv sync
# Linux/macOS
export API_KEYS=
# Windows
set API_KEYS=
uv run fastapi dev main.py
{
"inputs": [
{
"type": "promptString",
"id": "weather-api-key",
"description": "Weather API Key",
"password": true
}
],
"servers": {
"weather-sse": {
"type": "sse",
"url": "http://localhost:8000/sse",
"headers": {
"x-api-key": "${input:weather-api-key}"
}
}
}
}
az containerapp up -g -n weather-mcp --environment mcp -l westus --env
ModuleNotFoundError,请确保激活了虚拟环境并且安装了依赖项。python -m ensurepip --upgrade
python -m pip install --upgrade pip
欢迎拉取请求!请先打开问题讨论主要更改。