Registry / llm-agents / fastapi-mcp

fastapi-mcp

JSON →
library0.4.0pypypi✓ verified 26d ago

FastAPI-MCP is a Python library that automatically converts FastAPI endpoints into Model Context Protocol (MCP) tools, enabling seamless integration with Large Language Models (LLMs) and AI agents. It provides a straightforward way to expose existing FastAPI APIs as discoverable and callable tools for AI. The library is currently at version 0.4.0 and maintains an active release cadence with frequent updates and feature additions.

pip install fastapi-mcp uvicorn
INSTALL
IMPORT
SIG · FASTAPI-MCP
F
fastapi-mcp
llm-agentspythonv0.4.0
Install
8.4s avg
Import
4109ms
Disk
80MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
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
musl
glibc
py 3.10
✓ —
✓ 9.9s
py 3.11
✓ —
✓ 8.7s
py 3.12
✓ —
✓ 7.5s
py 3.13
✓ —
✓ 7.6s
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.
fix
Use `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.
fix
Remove 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.
fix
Migrate 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.
fix
Always 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.
fix
Ensure 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.
fix
Upgrade 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).
Agent activity
38 hits · last 30 days
node
32
OpenAI (training)
1
Resources
fastapi-mcp — pip install fastapi-mcp · libregistry