FastAPI-MCP: Turn FastAPI Endpoints into MCP-Standard Tools 69

小编 ·

FastAPI-MCP: Turn FastAPI Endpoints into MCP-Standard Tools

FastAPI-MCP is an open-source tool that automatically converts FastAPI application endpoints into MCP-compliant interfaces with zero configuration, while preserving request/response schemas and Swagger documentation. With simple code integration, FastAPI applications can be seamlessly connected with AI systems to support AI-driven automation tasks.

FastAPI-MCP: Turn FastAPI Endpoints into MCP-Standard Tools

What is FastAPI-MCP?

FastAPI-MCP is an open-source tool that can automatically convert the endpoint interfaces of a FastAPI application into MCP-compliant tools with zero configuration. It preserves the request/response schemas as well as the Swagger documentation. Through simple code integration, it enables seamless connection between FastAPI applications and AI systems, supporting AI-driven automation tasks.

For example, if you ask Claude to execute: "Send an email to the user with ID 1111 about XX", Claude will directly call your email-sending API. Without writing code or doing anything manually, it knows exactly how to use this API correctly.

FastAPI-MCP:把FastAPI应用接口端点变成MCP标准的工具.webp

FastAPI-MCP Features

  • Zero-configuration integration: No complex setup needed — just a few lines of code to automatically convert FastAPI endpoints into MCP tools.

  • Automatic discovery and conversion: Automatically discovers all endpoints in a FastAPI application and converts them into MCP tools.

  • Preserves documentation and schemas: Retains the request/response schemas of FastAPI endpoints along with the Swagger documentation, ensuring accuracy during AI invocations.

  • Flexible deployment: Supports mounting the MCP server directly into a FastAPI application, or deploying it independently.

  • Customization options: Filter exposed endpoints by operation ID or tags, and adjust tool naming and descriptions.

FastAPI-MCP Installation and Usage

  • Installation: It is recommended to install using uv, but pip also works.

uv add fastapi-mcp

or

pip install fastapi-mcp
  • Basic usage: Add the MCP server to a FastAPI application.

from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
mcp = FastApiMCP(
    app,
    name="My API MCP",
    description="My API description",
    base_url="http://localhost:8000",
)
mcp.mount()

Once done, the MCP server will be available at the specified path.

FastAPI-MCP Use Cases

  • AI-driven automation: Enables AI agents to perform automated tasks via APIs, such as data analysis, content management, e-commerce, and more.

  • Internal automation: Used for automation workflows within enterprises.

  • Multi-agent collaboration: Supports AI agents collaborating through standardized APIs.

github:https://github.com/tadata-org/fastapi_mcp