FastAPI-MCP
A zero-configuration tool for automatically exposing FastAPI endpoints as Model Context Protocol (MCP) tools.
Features
- 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
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
.
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.
Documentation, Examples and Advanced Usage
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.
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
License
MIT License. Copyright © 2024 Tadata Inc.
FastAPI-MCP
Project Details
- tadata-org/fastapi_mcp
- MIT License
- Last Updated: 4/21/2025
Categories
Recomended MCP Servers
A Model Context Protocol server for Linear.
A CLI tool to convert your codebase into a single LLM prompt with source tree, prompt templating, and...
MCP Server for Odoo
Make websites accessible for AI agents
CLI to set up and deploy MCP Servers to Cloudflare Workers in seconds. Just write TypeScript functions to...
Execute a secure shell in Claude Desktop using the Model Context Protocol.
A zero-installation solution for AI agents to control remote macOS systems. Full desktop capabilities without extra software, using...
browser-tools-mcp
Collection of apple-native tools for the model context protocol.