Features
- Direct integration - Mount an MCP server directly to your FastAPI app
- Zero configuration required - just point it at your FastAPI app and it works
- Automatic discovery of all FastAPI endpoints and conversion to MCP tools
- 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
Installation
We recommend using uv, a fast Python package installer:
Alternatively, you can install with pip:
Basic Usage
The simplest way to use FastAPI-MCP is to add an MCP server directly to your FastAPI application:
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.
Tool Naming
FastAPI-MCP uses the operation_id
from your FastAPI routes as the MCP tool names. When you don't specify an operation_id
, FastAPI auto-generates one, but these can be cryptic.
Compare these two endpoint definitions:
For clearer, more intuitive tool names, we recommend adding explicit operation_id
parameters to your FastAPI route definitions.
To find out more, read FastAPI's official docs about advanced config of path operations.
Advanced Usage
FastAPI-MCP provides several ways to customize and control how your MCP server is created and configured. Here are some advanced usage patterns:
Customizing Schema Description
Customizing Exposed Endpoints
You can control which FastAPI endpoints are exposed as MCP tools using Open API operation IDs or tags:
Notes on filtering:
- You cannot use both
include_operations
andexclude_operations
at the same time - You cannot use both
include_tags
andexclude_tags
at the same time - You can combine operation filtering with tag filtering (e.g., use
include_operations
withinclude_tags
) - When combining filters, a greedy approach will be taken. Endpoints matching either criteria will be included
Deploying Separately from Original FastAPI App
You are not limited to serving the MCP on the same FastAPI app from which it was created.
You can create an MCP server from one FastAPI app, and mount it to a different app:
Adding Endpoints After MCP Server Creation
If you add endpoints to your FastAPI app after creating the MCP server, you'll need to refresh the server to include them:
Examples
See the examples directory for complete examples.
Connecting to the MCP Server using SSE
Once your FastAPI app with MCP integration is running, you can connect to it with any MCP client supporting SSE, such as Cursor:
- Run your application.
- In Cursor -> Settings -> MCP, use the URL of your MCP server endpoint (e.g.,
http://localhost:8000/mcp
) as sse. - Cursor will discover all available tools and resources automatically.
Connecting to the MCP Server using mcp-proxy stdio
If your MCP client does not support SSE, for example Claude Desktop:
- Run your application.
- Install mcp-proxy, for example:
uv tool install mcp-proxy
. - Add in Claude Desktop MCP config file (
claude_desktop_config.json
):
On Windows:
On MacOS:
Find the path to mcp-proxy by running in Terminal: which mcp-proxy
.
- Claude Desktop will discover all available tools and resources automatically
Development and Contributing
Thank you for considering contributing to FastAPI-MCP! We encourage the community to post Issues and 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 (c) 2024 Tadata Inc.
This server cannot be installed
A zero-configuration tool that automatically converts FastAPI endpoints into Model Context Protocol (MCP) tools, enabling AI systems to interact with your API through natural language.