✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more

fastapi-to-mcp

FastAPI-MCP

A zero-configuration tool for automatically exposing FastAPI endpoints as Model Context Protocol (MCP) tools.

PyPI version Python Versions FastAPI CI Coverage

fastapi-mcp-usage

Features

  • Zero configuration - Just point it at your FastAPI app and it works, with automatic discovery of endpoints and conversion to MCP tools
  • Schema & docs preservation - Keep the same request/response models and preserve documentation of all your endpoints
  • Flexible deployment - Mount your MCP server to the same FastAPI application, or deploy separately
  • Custom endpoint exposure - Control which endpoints become MCP tools using operation IDs and tags
  • ASGI transport - Uses FastAPI’s ASGI interface directly by default 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.

Note on base_url: While base_url is optional, it is highly recommended to provide it explicitly. The base_url tells the MCP server where to send API requests when tools are called. Without it, the library will attempt to determine the URL automatically, which may not work correctly in deployed environments where the internal and external URLs differ.

Documentation, Examples and Advanced Usage

FastAPI-MCP provides comprehensive documentation in the docs folder:

  • Best Practices - Essential guidelines for converting APIs to MCP tools safely and effectively
  • FAQ - Frequently asked questions about usage, development and support
  • Tool Naming - Best practices for naming your MCP tools using operation IDs
  • Connecting to MCP Server - How to connect various MCP clients like Cursor and Claude Desktop
  • Advanced Usage - Advanced features like custom schemas, endpoint filtering, and separate deployment

Check out the examples directory for code samples demonstrating these features in action.

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 © 2024 Tadata Inc.

Featured Templates

View More
AI Characters
Your Speaking Avatar
164 600
Customer service
Service ERP
125 658
AI Agents
AI Video Generator
244 1250 5.0
AI Engineering
Python Bug Fixer
117 957

Start your free trial

Build your solution today. No credit card required.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.