fastapi_mcp README

The project's README from github.com/tadata-org/fastapi_mcp. As one markdown file: README.md.

fastapi-to-mcp

Built by Tadata

FastAPI-MCP

tadata-org%2Ffastapi_mcp | Trendshift

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

PyPI version Python Versions FastAPI CI Coverage

fastapi-mcp-usage

Features

Hosted Solution

If you prefer a managed hosted solution check out tadata.com.

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:

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

License

MIT License. Copyright (c) 2025 Tadata Inc.

fastapi_mcp (tadata-org/fastapi_mcp)

Searching Database…

这是什么?FastAPI-MCP 可以把你现有的 FastAPI 接口转换为 Model Context Protocol(MCP)工具,让 Claude、Cursor 等 AI 智能体直接调用你的 API,并内置身份验证。
这是独立的 MCP 服务器,还是要加到我应用里的库?它是一个 Python 库/扩展,需要添加到你的 FastAPI 代码中,而不是一个单独的转换工具。它的设计是 FastAPI 的原生扩展,而不是仅仅根据你的 OpenAPI 规范生成 MCP 工具。
我该如何为 FastAPI 应用添加 MCP 支持?用 uv 或 pip 安装该包,然后只需几行代码直接在 FastAPI 应用中添加一个 MCP 服务器;自动生成的 MCP 服务器即可立即使用。
使用前需要先安装什么?你需要 Python 3.10+(推荐 3.12),推荐使用 uv 包管理器安装,当然 pip 也可以。
它是不是和其他转换工具一样,只是把我的 OpenAPI 规范转换成 MCP 工具?不是——它明确避免只做'又一个 OpenAPI -> MCP 转换器'。它通过 ASGI 直接与你的应用通信,而不是发起 HTTP 调用,因此不需要单独的转换步骤,也不需要额外的网络跳转。
这是为谁设计的?已经有 FastAPI 后端、希望在不额外搭建集成层的情况下把它开放给 AI 智能体的开发者。
暴露的 MCP 工具是如何进行身份验证的?FastAPI-MCP 会复用你现有的 FastAPI Depends() 函数,因此你保护 MCP 接口的方式与保护 REST 接口的方式完全相同。
我可以把 MCP 服务器和主 API 分开运行吗?可以,部署方式很灵活——你可以把 MCP 服务器挂载到同一个 FastAPI 应用上,也可以按需单独部署。
如果我不想自己维护,有托管服务吗?有。创作者(Tadata)在 tadata.com 提供托管服务,适合不想自己运行 FastAPI-MCP 的团队。
它会保留我现有的 API 文档和模式吗?会。它会完整保留请求/响应模型的模式以及接口文档,与它们在 Swagger 中的显示完全一致。
Creator
tadata-org
Size
0.4 MB
Stars
12K
Age
1y
Commits · 90 Days