# 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. ## Install Merge the JSON below into your `.mcp.json`: # FastAPI-MCP — Turn Any FastAPI into MCP Tools ## Quick Use ```bash pip install fastapi-mcp ``` ```python 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 Config** — `FastApiMCP(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: ```json { "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 - GitHub: [tadata-org/fastapi_mcp](https://github.com/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. --- Source: https://tokrepo.com/en/workflows/b764314c-4294-449c-9bb8-c8b1f70098a3 Author: MCP Hub