快速启动
1.克隆存储库
git clone https://github.com/yourusername/FastMCP-and-FastAPI.git
cd FastMCP-and-FastAPI2.创建虚拟环境(可选)
python -m venv venv
.\venv\Scripts\activate3.安装依赖项
pip install fastapi uvicorn mcp fastmcp httpx
4.启动FastAPI服务器
# From the root directory
uvicorn src.app:app --reload5.启动MCP检查器(在新终端中)
npx @modelcontextprotocol/inspector6.测试应用程序
- 在浏览器中访问端点:
- http://localhost:8000/-欢迎页面 - http://localhost:8000/status-服务器状态 - http://localhost:8000/about-关于信息
- 在MCP检查器中:
- 连接到: http://localhost:8000/sse - 测试工具:
add(2, 3)
greeting://YourName
get_weather_alerts("CA")
get_weather_forecast(37.7749, -122.4194)项目结构
FastMCP-and-FastAPI/
├── src/
│ ├── __init__.py
│ ├── app.py
│ ├── routes.py
│ ├── server.py
│ └── weather.py
├── main.py
└── server.py