# panz2018/fastapi_mcp_sse architecture

> Architecture diagram of the GitHub repository panz2018/fastapi_mcp_sse, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/panz2018/fastapi_mcp_sse
- Repository: https://github.com/panz2018/fastapi_mcp_sse

## Overview

##### Project type and purpose
- This is a backend-focused demonstration tool that uses FastAPI to expose both standard web endpoints and Server-Sent Events (SSE) endpoints implemented according to the Model Context Protocol (MCP).
- Purpose: show how to integrate MCP SSE into a FastAPI application, expose `/sse` and `/messages/` for SSE clients, and host standard web routes (`/`, `/about`, `/status`, `/docs`, `/redoc`).

##### File structure
- Top-level: configuration files (`.flake8`, `.gitignore`, `pyproject.toml`, etc.) and `README.md`.
- `src/` folder contains the application code:
- `server.py` – initializes FastAPI, sets up MCP SSE transport & handlers, includes routers.
- `routes.py` – defines standard web endpoints via an `APIRouter`.
- `weather.py` – defines MCP tool functions (`get_alerts`, `get_forcast`) acting as domain logic.
- `app.py` – (optional helper) may assemble the FastAPI app.
- No database layer is present; domain logic is in-process.
- Deployment is via Uvicorn (invoked in `server.py` or `uv run start`).

##### Key insights from the README
- FastAPI is the web framework.
- MCP SSE is the core feature: SSE transport for live event streaming, plus an HTTP POST `/messages/` for submitting messages.
- Standard web routes coexist with MCP SSE routes.
- Extensibility via adding new APIRouter routes or new MCP tool functions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients"
        Browser["Browser"]:::client
        SSEClient["SSE Client (MCP Inspector)"]:::client
    end

    subgraph "API Server"
        subgraph "Entry Point"
            Uvicorn["Uvicorn ASGI Server"]:::infrastructure
        end
        subgraph "FastAPI Application"
            AppHelper["App Assembler Helper (src/app.py)"]:::module
            APIRouter["Standard Web Routes (src/routes.py)"]:::module
            SSEModule["MCP SSE Module (src/server.py)"]:::module
            DomainLogic["Domain Logic / Weather Tools (src/weather.py)"]:::domain
        end
    end

    subgraph "External Services"
        WeatherAPI["Upstream Weather API"]:::external
    end

    Config["Project Config & Metadata (pyproject.toml, README.md)"]:::config

    Browser -->|"GET /, /about, /status, /docs"| APIRouter
    APIRouter -->|"invokes"| AppHelper
    Uvicorn -->|"runs ASGI App"| AppHelper
    SSEClient -->|"GET /sse"| SSEModule
    Browser -->|"POST /messages/"| SSEModule
    SSEModule -->|"calls tools"| DomainLogic
    DomainLogic -->|"fetches data"| WeatherAPI
    SSEModule -->|"SSE stream"| SSEClient

    click AppHelper "https://github.com/panz2018/fastapi_mcp_sse/blob/main/src/app.py"
    click APIRouter "https://github.com/panz2018/fastapi_mcp_sse/blob/main/src/routes.py"
    click SSEModule "https://github.com/panz2018/fastapi_mcp_sse/blob/main/src/server.py"
    click Uvicorn "https://github.com/panz2018/fastapi_mcp_sse/blob/main/src/server.py"
    click DomainLogic "https://github.com/panz2018/fastapi_mcp_sse/blob/main/src/weather.py"
    click Config "https://github.com/panz2018/fastapi_mcp_sse/blob/main/pyproject.toml"

    classDef client fill:#E8F1F2,stroke:#333,stroke-width:1px
    classDef infrastructure fill:#F0F0F0,stroke:#333,stroke-width:1px
    classDef module fill:#FFEFD5,stroke:#333,stroke-width:1px
    classDef domain fill:#E6FFE6,stroke:#333,stroke-width:1px
    classDef external fill:#FFF5E6,stroke:#333,stroke-width:1px
    classDef config fill:#F5E6FF,stroke:#333,stroke-width:1px
```
