fastapi_mcp

MCP.Pizza Chef: tadata-org

fastapi_mcp is an MCP server that transforms FastAPI endpoints into Model Context Protocol tools, enabling seamless integration of web APIs with LLMs. It supports authentication to secure access, making it ideal for exposing RESTful services as callable MCP tools. This server facilitates real-time, structured interaction between language models and FastAPI-based APIs, enhancing automation and AI workflows.

Use This MCP server To

Expose FastAPI REST endpoints as MCP tools for LLM integration Secure API endpoints with built-in authentication for MCP access Enable LLMs to call FastAPI endpoints during multi-step reasoning Integrate FastAPI services into AI-enhanced workflows Automate data retrieval and updates via FastAPI through MCP Create custom MCP tools from existing FastAPI applications

README

fastapi-to-mcp

FastAPI-MCP

Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!

PyPI version Python Versions FastAPI CI Coverage

fastapi-mcp-usage

Features

  • Authentication built in, using your existing FastAPI dependencies!

  • FastAPI-native: Not just another OpenAPI -> MCP converter

  • Zero/Minimal configuration required - just point it at your FastAPI app and it works

  • Preserving schemas of your request models and response models

  • Preserve documentation of all your endpoints, just as it is in Swagger

  • Flexible deployment - Mount your MCP server to the same app, or deploy separately

  • ASGI transport - Uses FastAPI's ASGI interface directly for efficient communication

Installation

We recommend using uv, a fast Python package installer:

uv add fastapi-mcp

Alternatively, you can install with pip:

pip install fastapi-mcp

Basic Usage

The simplest way to use FastAPI-MCP is to add an MCP server directly to your FastAPI application:

from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

app = FastAPI()

mcp = FastApiMCP(app)

# Mount the MCP server directly to your FastAPI app
mcp.mount()

That's it! Your auto-generated MCP server is now available at https://app.base.url/mcp.

Documentation, Examples and Advanced Usage

FastAPI-MCP provides comprehensive documentation. Additionaly, check out the examples directory for code samples demonstrating these features in action.

FastAPI-first Approach

FastAPI-MCP is designed as a native extension of FastAPI, not just a converter that generates MCP tools from your API. This approach offers several key advantages:

  • Native dependencies: Secure your MCP endpoints using familiar FastAPI Depends() for authentication and authorization

  • ASGI transport: Communicates directly with your FastAPI app using its ASGI interface, eliminating the need for HTTP calls from the MCP to your API

  • Unified infrastructure: Your FastAPI app doesn't need to run separately from the MCP server (though separate deployment is also supported)

This design philosophy ensures minimum friction when adding MCP capabilities to your existing FastAPI services.

Development and Contributing

Thank you for considering contributing to FastAPI-MCP! We encourage the community to post Issues and create Pull Requests.

Before you get started, please see our Contribution Guide.

Community

Join MCParty Slack community to connect with other MCP enthusiasts, ask questions, and share your experiences with FastAPI-MCP.

Requirements

  • Python 3.10+ (Recommended 3.12)
  • uv

License

MIT License. Copyright (c) 2024 Tadata Inc.

fastapi_mcp FAQ

How do I secure my FastAPI endpoints when using fastapi_mcp?
fastapi_mcp includes built-in authentication mechanisms to protect your endpoints, ensuring only authorized MCP clients can access them.
Can fastapi_mcp handle complex FastAPI routes and parameters?
Yes, it supports exposing various FastAPI endpoints including those with path and query parameters as MCP tools.
Is fastapi_mcp compatible with multiple LLM providers?
Yes, it works with any MCP client and supports models from OpenAI, Anthropic Claude, and Google Gemini.
How do I install fastapi_mcp?
You can install it via PyPI using 'pip install fastapi-mcp'.
Does fastapi_mcp support real-time updates from FastAPI endpoints?
It exposes endpoints as MCP tools that can be called in real-time, enabling dynamic interaction.
Can I customize authentication methods in fastapi_mcp?
Yes, fastapi_mcp allows customization of authentication to fit your security requirements.
How does fastapi_mcp improve AI workflow integration?
By exposing FastAPI endpoints as MCP tools, it enables LLMs to interact directly with APIs, automating multi-step tasks efficiently.