MCP ConfigsApr 2, 2026·2 min read

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.

TL;DR
FastAPI-MCP exposes existing FastAPI endpoints as MCP tools with one line of code and zero config.
§01

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.

§02

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.

§03

How to use

  1. Install the fastapi-mcp package in your FastAPI project.
  2. Add the MCP bridge middleware to your FastAPI app with a single function call.
  3. Connect your AI agent to the MCP endpoint, and all your FastAPI routes become available as tools.
§04

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()
§05

Related on TokRepo

§06

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

Does FastAPI-MCP work with all FastAPI features?+

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.

Is authentication supported?+

Yes. FastAPI-MCP preserves your existing authentication middleware. API keys, OAuth tokens, and other auth mechanisms work through the MCP bridge without additional configuration.

Can I exclude certain endpoints from MCP exposure?+

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.

What MCP clients work with FastAPI-MCP?+

Any MCP-compatible client works, including Claude, Cursor, and custom agents built with the MCP SDK. The bridge implements the standard MCP server protocol.

Does it handle streaming responses?+

FastAPI-MCP primarily targets request-response endpoints. Streaming endpoints (SSE, WebSocket) require separate handling. Standard JSON API endpoints are fully supported.

Citations (3)
🙏

Source & Thanks

Thanks to the Tadata team for the elegant "one line to MCP" approach that saves backend teams weeks of integration work.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.