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.

MC
MCP Hub · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

pip install fastapi-mcp
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

app = FastAPI()

@app.get("/items/{item_id}")
async def get_item(item_id: int):
    return {"item_id": item_id, "name": "Example"}

# One line to expose all endpoints as MCP tools
mcp = FastApiMCP(app)
mcp.mount()

Your FastAPI app now serves MCP at /mcp — connect any AI assistant to it.

Introduction

FastAPI-MCP is a Python library that automatically converts your existing FastAPI endpoints into MCP-compatible tools. Instead of writing MCP server code from scratch, you add a single line to your existing FastAPI app and every endpoint becomes an AI-callable tool.

Key features:

  • Zero ConfigFastApiMCP(app).mount() is all you need. Every route becomes an MCP tool automatically.
  • Authentication Built-in — Leverages your existing FastAPI security dependencies (OAuth2, API keys, etc.) for MCP tool access.
  • Schema Preservation — Request/response models, validation rules, and documentation carry over to MCP tool definitions.
  • Selective Exposure — Include or exclude specific endpoints with include_operations and exclude_operations.
  • ASGI Transport — Direct in-process communication eliminates HTTP overhead when the MCP client and FastAPI run together.
  • Custom Tool Naming — Override auto-generated tool names for cleaner AI assistant integration.

Perfect for teams that already have FastAPI backends and want to make them AI-accessible without rewriting anything.

FAQ

Q: Does it work with existing authentication? A: Yes. FastAPI-MCP reuses your existing FastAPI Depends() security — OAuth2 bearer tokens, API keys, and custom auth all work transparently.

Q: Can I choose which endpoints to expose? A: Yes. Use include_operations=["get_item", "list_items"] or exclude_operations=["delete_all"] to control access.

Q: How do I connect Claude to my FastAPI-MCP server? A: Add this to your MCP config:

{
  "mcpServers": {
    "my-api": {
      "url": "http://localhost:8000/mcp"
    }
  }
}

Q: Does it handle complex request bodies? A: Yes. Pydantic models, query parameters, path parameters, and JSON bodies are all converted to MCP tool input schemas automatically.

Works With

  • FastAPI 0.100+
  • Python 3.10+
  • Claude Code / Claude Desktop / Any MCP client
  • Any existing FastAPI authentication setup
🙏

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.

Related Assets