How tadata-org/fastapi_mcp works
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.