FastAPI-MCP — Turn Any FastAPI into MCP Tools
Zero-config bridge that exposes existing FastAPI endpoints as MCP tools with authentication. Add one line to make your API AI-accessible.
What it is
FastAPI-MCP is a zero-configuration bridge that turns any FastAPI application into a set of MCP tools. AI agents can call your existing API endpoints as tools through the MCP protocol without any endpoint rewriting. Authentication is preserved, so your existing security model carries over.
Backend developers and AI engineers use FastAPI-MCP to make their existing APIs accessible to AI agents instantly. Instead of writing separate tool definitions for each endpoint, the bridge auto-generates MCP tool schemas from your FastAPI route definitions.
How it saves time or tokens
FastAPI-MCP eliminates the work of manually defining MCP tool schemas for each API endpoint. It reads your FastAPI route metadata (types, descriptions, parameters) and generates MCP-compatible tool definitions automatically. This saves hours of boilerplate and keeps tool definitions in sync with your API as it evolves.
How to use
- Install the fastapi-mcp package in your FastAPI project.
- Add the MCP bridge middleware to your FastAPI app with a single function call.
- Connect your AI agent to the MCP endpoint, and all your FastAPI routes become available as tools.
Example
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
@app.get('/users/{user_id}')
async def get_user(user_id: int):
return {'id': user_id, 'name': 'Alice'}
@app.post('/tasks')
async def create_task(title: str, priority: int = 1):
return {'id': 1, 'title': title, 'priority': priority}
# One line to expose all endpoints as MCP tools
mcp = FastApiMCP(app)
mcp.mount()
Related on TokRepo
- AI Tools for API — API development and integration tools
- AI Tools for Agents — Agent frameworks and tool integrations
Common pitfalls
- Exposing destructive endpoints (DELETE, bulk UPDATE) to agents without adding guardrails or confirmation steps.
- Not providing descriptive docstrings on your FastAPI routes, which results in vague MCP tool descriptions that confuse agents.
- Forgetting to test the MCP bridge with your authentication middleware to ensure tokens and API keys pass through correctly.
Frequently Asked Questions
FastAPI-MCP supports standard route parameters, query parameters, request bodies, and response models. It reads Pydantic schemas from your endpoint definitions to generate typed MCP tool parameters.
Yes. FastAPI-MCP preserves your existing authentication middleware. API keys, OAuth tokens, and other auth mechanisms work through the MCP bridge without additional configuration.
Yes. You can filter which endpoints are exposed as MCP tools using include and exclude patterns. This lets you keep internal or admin endpoints hidden from AI agents.
Any MCP-compatible client works, including Claude, Cursor, and custom agents built with the MCP SDK. The bridge implements the standard MCP server protocol.
FastAPI-MCP primarily targets request-response endpoints. Streaming endpoints (SSE, WebSocket) require separate handling. Standard JSON API endpoints are fully supported.
Citations (3)
- FastAPI-MCP GitHub— Zero-config bridge for FastAPI to MCP tools
- Model Context Protocol— MCP protocol for AI agent tool integration
- FastAPI Documentation— FastAPI automatic API documentation and schema generation
Related on TokRepo
Source & Thanks
- GitHub: tadata-org/fastapi_mcp
- License: MIT
- Stars: 11,000+
- Maintainer: Tadata
Thanks to the Tadata team for the elegant "one line to MCP" approach that saves backend teams weeks of integration work.