A Server-Sent Events implementation using FastAPI framework that integrates Model Context Protocol (MCP), allowing AI models to access external tools and data sources like weather information.
English | 简体中文
A Server-Sent Events (SSE) implementation using FastAPI framework with Model Context Protocol (MCP) integration.
The Model Context Protocol (MCP) is an open standard that enables AI models to interact with external tools and data sources. MCP solves several key challenges in AI development:
This project demonstrates how to implement MCP using Server-Sent Events (SSE) in a FastAPI web application.
This project demonstrates how to implement Server-Sent Events (SSE) using the FastAPI framework while integrating Model Context Protocol (MCP) functionality. The key feature is the seamless integration of MCP's SSE capabilities within a full-featured FastAPI web application that includes custom routes.
This project showcases a modular architecture that:
/sse
and /messages/
) into a FastAPI application/
, /about
, /status
, /docs
, /redoc
)Install UV Package Manager - A fast Python package installer written in Rust:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Run the application directly without cloning the repository using UV's execution tool:
uvx --from git+https://github.com/panz2018/fastapi_mcp_sse.git start
Create an isolated Python environment for the project:
uv venv
Activate the virtual environment to use it:
.venv\Scripts\activate
Install all required packages:
uv pip install -r pyproject.toml
Launch the integrated FastAPI server with MCP SSE functionality:
python src/server.py
or
uv run start
After starting the server (using either Option 1 or Option 2), the following endpoints will be available:
For testing and debugging MCP functionality, use the MCP Inspector:
mcp dev ./src/weather.py
SSE
Connect
Tools
sectionList Tools
to see available functions:
get_alerts
: Get weather alertsget_forcast
: Get weather forecastRun Tool
to executeThe application structure makes it easy to add new routes using FastAPI's APIRouter:
Define new route handlers in routes.py using the APIRouter:
@router.get("/new-route") async def new_route(): return {"message": "This is a new route"}
All routes defined with the router will be automatically included in the main application
The MCP SSE functionality is integrated in server.py through:
To use this MCP server with the Continue VS Code extension, add the following configuration to your Continue settings:
{ "experimental": { "modelContextProtocolServers": [ { "transport": { "name": "weather", "type": "sse", "url": "http://localhost:8000/sse" } } ] } }
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!