Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
py 3.9
✕ build_error
✕ build_error
80MB installed
● package 80MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
FastApiMCP
✓ from fastapi_mcp import FastApiMCP
✗ from fastmcp import FastApiMCP
Ensure you import from `fastapi_mcp` for the FastAPI integration, not the generic `fastmcp` SDK.
This quickstart demonstrates how to create a basic FastAPI application, instantiate `FastApiMCP` with your app, and then mount the MCP server using the recommended `mount_http()` method. The `operation_id` is explicitly set for clarity in the exposed MCP tool. To run, save as `main.py` and execute `python main.py`. The MCP server will be available at `http://localhost:8000/mcp`.
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
# Create a FastAPI app
app = FastAPI(title="My MCP API")
@app.get("/hello")
def read_root():
return {"message": "Hello, World!"}
@app.get("/items/{item_id}", operation_id="get_item_by_id")
def read_item(item_id: int):
"""Get a specific item by its ID"""
return {"item_id": item_id, "name": f"Item {item_id}"}
# Create an MCP server based on this app
mcp = FastApiMCP(app)
# Mount the MCP server to your app using the recommended HTTP transport
mcp.mount_http()
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
Debug
Known issues
breakingThe `mount()` method is deprecated as of v0.4.0 and will be removed in future versions. It previously handled SSE transport by default.fixUse `mcp.mount_http()` for HTTP transport (recommended) or `mcp.mount_sse()` for Server-Sent Events (SSE) transport instead.
affects: >=0.4.0
breakingThe `base_url` argument was removed from the `FastApiMCP` constructor. It is now redundant due to the default use of ASGI transport.fixRemove the `base_url` argument when initializing `FastApiMCP`. If an explicit base URL is required, configure it via the `http_client` argument with your own `httpx.AsyncClient`.
affects: >=0.3.0
breakingVersion 0.2.0 introduced a complete refactor from a function-based API to a new class-based `FastApiMCP` API. This changed how MCP instances are created and mounted.fixMigrate your code to use the `FastApiMCP` class (e.g., `mcp = FastApiMCP(app)` followed by `mcp.mount()`, or `mcp.mount_http()`/`mcp.mount_sse()` in later versions).
affects: >=0.2.0
gotchaFastAPI-MCP uses the `operation_id` from your FastAPI routes as the MCP tool names. If `operation_id` is not explicitly provided, FastAPI auto-generates a cryptic one.fixAlways provide an explicit `operation_id` parameter to your FastAPI route definitions (`@app.get('/path', operation_id='my_tool_name')`) for clearer and more intuitive tool names for AI agents. affects: All versions
gotchaFastAPI-MCP depends on the `mcp` package. Breaking changes in the `mcp` SDK itself (e.g., `mcp` SDK 1.8.0) can cause issues with `fastapi-mcp` if not explicitly handled.fixEnsure your `mcp` dependency is compatible with your `fastapi-mcp` version. Refer to `fastapi-mcp` release notes for required `mcp` versions (e.g., v0.3.4 fixed an issue by upgrading `mcp` to 1.8.1).
affects: All versions (dependent on mcp package versions)
breaking`fastapi-mcp` requires Python >= 3.10. Installation will fail on older Python versions.fixUpgrade your Python environment to 3.10 or newer to install `fastapi-mcp`.
affects: All versions
Upgrade
Version history
0.4.0latest on PyPI · released Jul 28, 2025
Audit
Dependencies
fastapirequiredCore web framework that fastapi-mcp integrates with.
uvicornrequiredASGI server required to run FastAPI applications, including the MCP server.
mcprequiredUnderlying Model Context Protocol SDK, explicitly mentioned as a dependency that can introduce breaking changes across its versions (e.g., mcp sdk 1.8.0 vs 1.8.1).