The Problem
FastAPI developers needing Model Context Protocol (MCP) exposure face a choice between generic OpenAPI-to-MCP converters (which lose FastAPI-native dependencies and schemas) or building custom integration layers. This repo addresses the gap by providing a native FastAPI extension that preserves request/response models, documentation, and dependency injection while generating MCP tools.
What This Does
fastapimcp is a FastAPI extension that auto-generates MCP tools from your existing FastAPI endpoints. The core implementation lives in fastapimcp/server.py which orchestrates the MCP server setup, while fastapimcp/transport/ handles the communication layer (http.py, sse.py). The fastapimcp/openapi/ directory contains conversion utilities (convert.py, utils.py) that preserve schemas and documentation from your FastAPI models.
Authentication integrates with FastAPI's dependency injection system - examples in examples/08authexampletokenpassthrough.py and examples/09authexampleauth0.py demonstrate token passthrough and Auth0 integration respectively. The transport layer uses FastAPI's ASGI interface directly (fastapimcp/transport/http.py), eliminating the overhead of HTTP calls from MCP to your API. The project includes 17 test files under tests/ and 16 example scripts covering basic usage, custom endpoints, separate server deployment, custom routers, re-registration, HTTP timeout configuration, and multiple auth patterns.
How To Use It
Setup: Install via pip or uv:
uv add fastapi-mcp or pip install fastapi-mcp
Configuration: Point the MCP server at your FastAPI application. No environment variables or keys are required for basic usage - authentication uses your existing FastAPI Depends() dependencies.
Running it: Create a FastAPI app and mount the MCP server from fastapimcp:
from fastapi import FastAPI from fastapimcp import FastApiMCP
app = FastAPI() mcp = FastApiMCP(app) mcp.mount()
The MCP server becomes available at https://app.base.url/mcp. For separate deployment, configure via fastapimcp/server.py and the advanced deployment docs at docs/advanced/deploy.mdx.
Real-World Use
A FastAPI team wanting to expose their API to LLM clients can add MCP support in minutes without separate service deployment. For example, an e-commerce API with product and order endpoints automatically becomes an MCP server preserving all schemas and documentation. Authentication hooks into existing FastAPI dependencies - the Auth0 example (examples/09authexampleauth0.py) shows integrating OAuth2 token validation. The ASGI transport means the MCP layer runs in-process with zero HTTP overhead, ideal for internal tooling or low-latency LLM integration.
Code Health & Issues
Low/Risk - Dependencies declared without a lockfile: pyproject.toml declares dependencies but uv.lock exists, suggesting uv is used for installation. However, no requirements.txt or Pipfile.lock is committed, which may cause reproducibility concerns for environments not using uv. Verify the lockfile is checked into CI. Tests: 18 test files found under tests/ with coverage reporting configured via .codecov.yml and GitHub Actions CI. Test coverage appears comprehensive across basic functionality, configuration, OpenAPI conversion, and transport layers (both mock and real HTTP/SSE). CI/CD: GitHub Actions configured with ci.yml and release.yml workflows. Dependabot is enabled via .github/dependabot.yml for dependency updates. Documentation: 22 doc files in Markdown/MDX format covering getting started, advanced topics (auth, transport, deploy, customization), and configurations.
The Bottom Line
This is a practical, well-structured FastAPI extension that genuinely native MCP exposure without the friction of conversion pipelines. Authentication via FastAPI dependencies is a strong differentiator. The main concern is lockfile discipline - ensure uv.lock is version-controlled and CI installs from it. Recommended for any FastAPI team needing MCP capabilities, particularly those already using FastAPI's dependency injection for auth.
Who should use it: FastAPI teams wanting to expose endpoints as MCP tools while preserving schemas, documentation, and existing auth patterns. Not ideal if your stack doesn't use FastAPI or you need a language-agnostic MCP server.