需 Python 3.10 及以上,低版本无法安装;默认挂载后 MCP 服务在 /mcp 路径,客户端要指向该地址;鉴权依赖你已有的 FastAPI 依赖,未配置则接口无保护
fastapi_mcp
tadata-orgMIT更新放缓把 FastAPI 接口一键暴露成 MCP 工具,自带认证授权,让 Claude、Cursor 等 LLM 客户端直接调用你的后端服务。
Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!
uv add fastapi-mcpREADME 未说明,仅要求 Python 3.10+(推荐 3.12)与 uv
把 FastAPI 接口直接暴露成 MCP 工具,带鉴权,几乎零配置
把 FastAPI 接口一键暴露成 MCP 工具,自带认证授权,让 Claude、Cursor 等 LLM 客户端直接调用你的后端服务。
核心能力
- 用现有 FastAPI Depends() 依赖做 MCP 鉴权
- 直接指向 FastAPI app 即可自动生成 MCP 工具
- 保留请求/响应模型 schema 与 Swagger 文档
- 通过 ASGI 接口直连应用,不走 HTTP 调用
- 可挂载到同一应用,也可单独部署
容易踩的坑
- v0.4.0最新正式版2025-07-28 · 2025-07-28 12:10 UTC
🚀 FastAPI-MCP now supports Streamable HTTP transport.
HTTP transport is now the recommended approach, following the specification that positions HTTP as the standard while maintaining SSE for backwards compatibility.
⚠️ Breaking Changes
mount()method is deprecated and will be removed in a future version. Usemount_http()for HTTP transport (recommended) ormount_sse()for SSE transport.
Added
- 🎉 Streamable HTTP Transport Support - New
mount_http()method implementing the MCP Streamable HTTP specification - 🎉 Stateful Session Management - For both HTTP and SSE transports
PRs
- Add streamable http support by @shahar4499 in https://github.com/tadata-org/fastapi_mcp/pull/206
- bump version to 0.4.0 by @shahar4499 in https://github.com/tadata-org/fastapi_mcp/pull/207
Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.7...v0.4.0
- v0.3.72025-07-14 · 2025-07-14 16:19 UTC
查看更新说明
Fixed
- 🐛 Fix a bug with OAuth default_scope (#123)
PRs
- Fixes #123: allow usage of default_scope to be passed by @jessesanford in https://github.com/tadata-org/fastapi_mcp/pull/185
New Contributors
- @jessesanford made their first contribution in https://github.com/tadata-org/fastapi_mcp/pull/185
Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.6...v0.3.7
- v0.3.62025-07-10 · 2025-07-10 14:56 UTC
查看更新说明
What's Changed
Added
- 🚀 Add configurable HTTP header forwarding (#181)
Fixed
- 🐛 Fix a bug with handling FastAPI
root_pathparameter (#163)
PRs
- update readme by @itay-tadata in https://github.com/tadata-org/fastapi_mcp/pull/164
- Update readme by @irn77 in https://github.com/tadata-org/fastapi_mcp/pull/192
- Fix a bug with handling FastAPI
root_pathparameter by @am1ter in https://github.com/tadata-org/fastapi_mcp/pull/163 - Add configurable HTTP header forwarding by @floran-putter in https://github.com/tadata-org/fastapi_mcp/pull/181
- Change fork method in SSE transport tests to avoid pickling issues by @am1ter in https://github.com/tadata-org/fastapi_mcp/pull/196
New Contributors
- @itay-tadata made their first contribution in https://github.com/tadata-org/fastapi_mcp/pull/164
- @irn77 made their first contribution in https://github.com/tadata-org/fastapi_mcp/pull/192
- @am1ter made their first contribution in https://github.com/tadata-org/fastapi_mcp/pull/163
- @floran-putter made their first contribution in https://github.com/tadata-org/fastapi_mcp/pull/181
Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.4...v0.3.5
- v0.3.42025-05-18 · 2025-05-18 14:29 UTC
查看更新说明
Fixed
- 🐛 Update the
mcpdependency to1.8.1. Fixes Issue #134 that was caused after a breaking change in mcp sdk 1.8.0.
PRs
- Upgrades the mcp package dependency to 1.8.1 by @ierickson in https://github.com/tadata-org/fastapi_mcp/pull/137
- Fix @modelcontextprotocol/inspector command-line by @bfontaine in https://github.com/tadata-org/fastapi_mcp/pull/131
New Contributors
- @ierickson made their first contribution in https://github.com/tadata-org/fastapi_mcp/pull/137
- @bfontaine made their first contribution in https://github.com/tadata-org/fastapi_mcp/pull/131
Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.3...v0.3.4
- 🐛 Update the
- v0.3.3v0.3.3 - Fix OpenAPI Conversion Regression2025-04-23 · 2025-04-23 09:03 UTC
查看更新说明
Fixes the broken release from 0.3.2.
Fixed
- 🐛 Fix critical bug in openapi conversion (missing
param_descdefinition) (#107, #99) - 🐛 Fix non-ascii support (#66)
PRs
- Fix error in openapi conversion by @danlapid in https://github.com/tadata-org/fastapi_mcp/pull/101
- Bugfix/issue 66 by @shira-ayal in https://github.com/tadata-org/fastapi_mcp/pull/90
- add more test cases to openapi conversion by @shahar4499 in https://github.com/tadata-org/fastapi_mcp/pull/109
- bump version to 0.3.3 by @shahar4499 in https://github.com/tadata-org/fastapi_mcp/pull/108
New Contributors
- @danlapid made their first contribution in https://github.com/tadata-org/fastapi_mcp/pull/101
Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.2...v0.3.3
- 🐛 Fix critical bug in openapi conversion (missing
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
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
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:
-
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) 2025 Tadata Inc.