Expose FastAPI endpoints as MCP tools with authentication
Mounts onto a FastAPI app to auto-generate an MCP server from its endpoints, preserving schemas, docs, and auth.
0.4.0Add to Favorites
Why it matters
Transform your existing FastAPI application into a Model Context Protocol server so AI agents can interact with your API endpoints as native tools, preserving all schemas, documentation, and authentication logic without requiring separate deployment or HTTP overhead.
Outcomes
What it gets done
Auto-generate MCP tools from FastAPI routes with zero configuration
Preserve request/response schemas and endpoint documentation in MCP format
Secure MCP endpoints using existing FastAPI authentication dependencies
Mount MCP server directly to FastAPI app or deploy separately via ASGI
Source
Get it from source
Spark does not host a copy of it.
Open sourceReports
Agent outcome reports
No reports yet
Overview
FastAPI to MCP auto generator
FastAPI-MCP mounts directly onto an existing FastAPI application to auto-generate an MCP server from its endpoints, preserving request/response schemas and documentation and reusing existing FastAPI authentication dependencies. Use it when you already run a FastAPI service and want to expose it as MCP tools with minimal configuration. It is specific to FastAPI apps, using their native ASGI interface.
What it does
FastAPI-MCP turns an existing FastAPI application into an MCP server, auto-generating MCP tools from its endpoints while preserving request/response schemas and documentation. It calls itself "FastAPI-native" rather than a generic OpenAPI-to-MCP converter: it mounts directly onto your FastAPI app and communicates over FastAPI's ASGI interface instead of making HTTP calls back to your own API.
When to use - and when NOT to
Use it when you already have a FastAPI application and want to expose its endpoints to an MCP client with minimal extra configuration - the basic setup is adding two lines to your FastAPI app. It's a fit if you want authentication for the MCP endpoints to reuse your existing FastAPI Depends() dependencies rather than a separate auth layer. It's not for exposing arbitrary REST APIs written in other frameworks - it works specifically with FastAPI apps via their native ASGI interface, though the resulting MCP server can still be deployed separately from the original app if you don't want them running in the same process.
Capabilities
- Authentication built in, reusing your existing FastAPI dependencies.
- Zero/minimal configuration - point it at a FastAPI app and it works.
- Preserves request/response model schemas and endpoint documentation exactly as they appear in your FastAPI/Swagger setup.
- Flexible deployment: mount the MCP server on the same app, or deploy it separately.
- Uses FastAPI's ASGI transport directly for efficient communication, without HTTP calls back to your own API.
How to install
Install via uv add fastapi-mcp (or pip install fastapi-mcp), then mount it directly on your FastAPI app:
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()
This exposes the auto-generated MCP server at https://app.base.url/mcp. Requires Python 3.10+ (3.12 recommended) and uv. It is MIT licensed (Copyright 2025 Tadata Inc.), and a hosted, managed version is available at tadata.com for teams that don't want to self-host.
Who it's for
Teams that already run a FastAPI service and want to expose it to AI agents as MCP tools without maintaining a separate conversion layer or duplicating authentication logic. It requires Python 3.10 or newer (3.12 recommended) and the uv package manager, and a community Slack (MCParty) is available for questions and support. The project publishes full documentation and an examples directory covering these features in more depth for teams that need advanced setups.
Source README
FastAPI-MCP
Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!
Features
Authentication built in, using your existing FastAPI dependencies!
FastAPI-native: Not just another OpenAPI -> MCP converter
Zero/Minimal configuration required - just point it at your FastAPI app and it works
Preserving schemas of your request models and response models
Preserve documentation of all your endpoints, just as it is in Swagger
Flexible deployment - Mount your MCP server to the same app, or deploy separately
ASGI transport - Uses FastAPI's ASGI interface directly for efficient communication
Hosted Solution
If you prefer a managed hosted solution check out tadata.com.
Installation
We recommend using uv, a fast Python package installer:
uv add fastapi-mcp
Alternatively, you can install with pip:
pip install fastapi-mcp
Basic Usage
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.
Documentation, Examples and Advanced Usage
FastAPI-MCP provides comprehensive documentation. Additionaly, check out the examples directory for code samples demonstrating these features in action.
FastAPI-first Approach
FastAPI-MCP is designed as a native extension of FastAPI, not just a converter that generates MCP tools from your API. This approach offers several key advantages:
Native dependencies: Secure your MCP endpoints using familiar FastAPI
Depends()for authentication and authorizationASGI transport: Communicates directly with your FastAPI app using its ASGI interface, eliminating the need for HTTP calls from the MCP to your API
Unified infrastructure: Your FastAPI app doesn't need to run separately from the MCP server (though separate deployment is also supported)
This design philosophy ensures minimum friction when adding MCP capabilities to your existing FastAPI services.
Development and Contributing
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.
Community
Join MCParty Slack community to connect with other MCP enthusiasts, ask questions, and share your experiences with FastAPI-MCP.
Requirements
- Python 3.10+ (Recommended 3.12)
- uv
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.