fastapi_mcp

tadata-orgMIT更新放缓

把 FastAPI 接口一键暴露成 MCP 工具,自带认证授权,让 Claude、Cursor 等 LLM 客户端直接调用你的后端服务。

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

v0.4.0发布于 2025-07-28 12:10 UTC12,027star965fork同步于 2026-11-10 05:28 UTC

怎么上手

由 README 提炼,执行前请确认
uv add fastapi-mcp
硬件要求按 README 说明

README 未说明,仅要求 Python 3.10+(推荐 3.12)与 uv

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

把 FastAPI 接口直接暴露成 MCP 工具,带鉴权,几乎零配置

把 FastAPI 接口一键暴露成 MCP 工具,自带认证授权,让 Claude、Cursor 等 LLM 客户端直接调用你的后端服务。

核心能力

  • 用现有 FastAPI Depends() 依赖做 MCP 鉴权
  • 直接指向 FastAPI app 即可自动生成 MCP 工具
  • 保留请求/响应模型 schema 与 Swagger 文档
  • 通过 ASGI 接口直连应用,不走 HTTP 调用
  • 可挂载到同一应用,也可单独部署

容易踩的坑

需 Python 3.10 及以上,低版本无法安装;默认挂载后 MCP 服务在 /mcp 路径,客户端要指向该地址;鉴权依赖你已有的 FastAPI 依赖,未配置则接口无保护

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.4.0
  1. 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. Use mount_http() for HTTP transport (recommended) or mount_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

    Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.7...v0.4.0

  2. v0.3.72025-07-14 · 2025-07-14 16:19 UTC
    查看更新说明

    Fixed

    • 🐛 Fix a bug with OAuth default_scope (#123)

    PRs

    New Contributors

    Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.6...v0.3.7

  3. 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_path parameter (#163)

    PRs

    New Contributors

    Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.4...v0.3.5

  4. v0.3.42025-05-18 · 2025-05-18 14:29 UTC
    查看更新说明

    Fixed

    • 🐛 Update the mcp dependency to 1.8.1. Fixes Issue #134 that was caused after a breaking change in mcp sdk 1.8.0.

    PRs

    New Contributors

    Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.3...v0.3.4

  5. 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_desc definition) (#107, #99)
    • 🐛 Fix non-ascii support (#66)

    PRs

    New Contributors

    Full Changelog: https://github.com/tadata-org/fastapi_mcp/compare/v0.3.2...v0.3.3

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    PyPI version Python Versions FastAPI CI Coverage

    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.