A zero-configuration tool for automatically exposing FastAPI endpoints as Model Context Protocol (MCP) tools.
- Zero configuration - Just point it at your FastAPI app and it works, with automatic discovery of endpoints and conversion to MCP tools
- Schema & docs preservation - Keep the same request/response models and preserve documentation of all your endpoints
- Flexible deployment - Mount your MCP server to the same FastAPI application, or deploy separately
- Custom endpoint exposure - Control which endpoints become MCP tools using operation IDs and tags
- ASGI transport - Uses FastAPI's ASGI interface directly by default for efficient communication
We recommend using uv, a fast Python package installer:
uv add fastapi-mcp
Alternatively, you can install with pip:
pip install fastapi-mcp
The simplest way to use FastAPI-MCP is to add an MCP server directly to your FastAPI application:
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
mcp = FastApiMCP(app)
# Mount the MCP server directly to your FastAPI app
mcp.mount()
That's it! Your auto-generated MCP server is now available at https://app.base.url/mcp
.
Note on
base_url
: Whilebase_url
is optional, it is highly recommended to provide it explicitly. Thebase_url
tells the MCP server where to send API requests when tools are called. Without it, the library will attempt to determine the URL automatically, which may not work correctly in deployed environments where the internal and external URLs differ.
FastAPI-MCP provides comprehensive documentation in the docs
folder:
- Best Practices - Essential guidelines for converting APIs to MCP tools safely and effectively
- FAQ - Frequently asked questions about usage, development and support
- Tool Naming - Best practices for naming your MCP tools using operation IDs
- Connecting to MCP Server - How to connect various MCP clients like Cursor and Claude Desktop
- Advanced Usage - Advanced features like custom schemas, endpoint filtering, and separate deployment
Check out the examples directory for code samples demonstrating these features in action.
Thank you for considering contributing to FastAPI-MCP! We encourage the community to post Issues and create Pull Requests.
Before you get started, please see our Contribution Guide.
Join MCParty Slack community to connect with other MCP enthusiasts, ask questions, and share your experiences with FastAPI-MCP.
- Python 3.10+ (Recommended 3.12)
- uv
MIT License. Copyright (c) 2024 Tadata Inc.