内容
# 远程MCP服务器示例
本MCP服务器使用SSE传输,并通过API密钥进行身份验证。
## 本地运行
前提条件:
* Python 3.11 或更高版本
* [uv](https://docs.astral.sh/uv/getting-started/installation/)
在本地运行服务器:
```bash
uv venv
uv sync
# Linux/macOS
export API_KEYS=<一个API密钥>
# Windows
set API_KEYS=<一个API密钥>
uv run fastapi dev main.py
```
VS Code MCP 配置 (mcp.json):
```json
{
"inputs": [
{
"type": "promptString",
"id": "weather-api-key",
"description": "天气API密钥",
"password": true
}
],
"servers": {
"weather-sse": {
"type": "sse",
"url": "http://localhost:8000/sse",
"headers": {
"x-api-key": "${input:weather-api-key}"
}
}
}
}
```
## 部署到Azure容器应用
```bash
az containerapp up -g <资源组名称> -n weather-mcp --environment mcp -l westus --env-vars API_KEYS=<一个API密钥> --source .
```
如果部署成功,Azure CLI 将返回应用程序的URL。您可以使用此URL从Visual Studio Code连接到服务器。
如果部署失败,请在更新CLI和Azure容器应用扩展后重试:
```bash
az upgrade
az extension add -n containerapp --upgrade
```