# tadata-org/fastapi_mcp architecture

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

- Interactive diagram: https://gitdiagram.com/tadata-org/fastapi_mcp
- Repository: https://github.com/tadata-org/fastapi_mcp

## Overview

##### Project Overview & Purpose
- This is a Python package that integrates with a FastAPI application to automatically discover FastAPI endpoints and convert them into MCP tools.
- The goal is to allow users to “mount” an MCP server onto their FastAPI app, making all endpoints available via the MCP protocol (using Server-Sent Events or a provided proxy, for example).
- It also supports adding custom tools via decorators.

##### Main Components
- FastAPI Application:
- This represents the existing FastAPI app (provided by users) to which the MCP functionality is added.
- MCP Server Module:
- Represents the core integration logic found in fastapi_mcp/server.py. This module is responsible for setting up and running the MCP server on a specified mount path.
- HTTP Tools & Conversion Logic:
- Found in fastapi_mcp/http_tools.py. This component is responsible for the automatic discovery of FastAPI endpoints, converting request/response models, documentation, and schemas into MCP tools.
- MCP Tools (Auto-generated and Custom):
- Two aspects: the auto-generated MCP tools (turned from FastAPI endpoints) and additionally defined custom tools (as shown in the README’s advanced usage example with the @mcp_server.tool() decorator).
- External MCP Clients and Proxies:
- Clients like Cursor or using mcp-proxy that interact with the MCP server either through SSE or stdio. They are external to the FastAPI app but need to be represented as consumers of the MCP service.

##### Relationships and Interactions
- Optionally, indicate the role of configuration (via setup.py, pyproject.toml, and uv.lock/uv configuration) as supporting modules for deployment and integration.

##### Architectural Patterns and Technologies
- The design uses a “zero configuration” integration pattern—simply adding the MCP layer to an existing FastAPI instance without the need for manual endpoint configuration.
- Auto-discovery mechanism:
– Illustrate how FastAPI endpoints (with their request/response schemas and Swagger-style documentation) are mapped to MCP tool representations.
- Use of FastAPI for the backend, Python 3.10+, and support tools like “uv” for dependency installation.
- Also, include mention of SSE (Server-Sent Events) and alternative stdio methodologies for client connections.

## Diagram (Mermaid)

```mermaid
flowchart TD
    FAP["FastAPI Application"]:::fastapi
    FS["MCP Server"]:::core
    HT["HTTP Tools & Converter"]:::converter
    subgraph "MCP Tools"
        AGT["Auto-generated Tools"]:::mcp
        CT["Custom Tools"]:::mcp
    end
    EMC["External MCP Clients"]:::external
    subgraph "Configuration & Deployment"
        SP["setup.py"]:::config
        PPT["pyproject.toml"]:::config
        UV["uv.lock"]:::config
    end

    FAP -->|"mounts"| FS
    FS -->|"scans&converts"| HT
    HT -->|"auto-discovers"| AGT
    AGT -->|"exposes"| EMC
    CT -->|"exposes"| EMC
    FS <-->|"SSE/stdio"| EMC
    SP -->|"supports"| FS
    PPT -->|"supports"| FS
    UV -->|"supports"| FS

    click FAP "https://github.com/tadata-org/fastapi_mcp/blob/main/examples/simple_integration.py"
    click FS "https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/server.py"
    click HT "https://github.com/tadata-org/fastapi_mcp/blob/main/fastapi_mcp/http_tools.py"
    click AGT "https://github.com/tadata-org/fastapi_mcp/blob/main/examples/simple_integration.py"
    click CT "https://github.com/tadata-org/fastapi_mcp/blob/main/README.md"
    click SP "https://github.com/tadata-org/fastapi_mcp/blob/main/setup.py"
    click PPT "https://github.com/tadata-org/fastapi_mcp/blob/main/pyproject.toml"
    click UV "https://github.com/tadata-org/fastapi_mcp/blob/main/uv.lock"

    classDef fastapi fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef core fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef converter fill:#a9dfbf,stroke:#1e8449,stroke-width:2px;
    classDef mcp fill:#f7dc6f,stroke:#b7950b,stroke-width:2px;
    classDef external fill:#d2b4de,stroke:#8e44ad,stroke-width:2px;
    classDef config fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
```
