Skip to main content
Glama

PyPI 版本 Python 版本 快速API CI 覆盖范围

特征

  • 内置身份验证,使用您现有的 FastAPI 依赖项!

  • **FastAPI-native:**不仅仅是另一个 OpenAPI -> MCP 转换器

  • 无需/只需极少配置- 只需将其指向您的 FastAPI 应用程序即可运行

  • 保留请求模型和响应模型的模式

  • 保存所有端点的文档,就像在 Swagger 中一样

  • 灵活部署- 将您的 MCP 服务器安装到同一应用程序,或单独部署

  • ASGI 传输- 直接使用 FastAPI 的 ASGI 接口进行高效通信

Related MCP server: Basic MCP Application

安装

我们建议使用uv ,一个快速的 Python 包安装程序:

uv add fastapi-mcp

或者,您可以使用 pip 安装:

pip install fastapi-mcp

基本用法

使用 FastAPI-MCP 最简单的方法是将 MCP 服务器直接添加到你的 FastAPI 应用程序中:

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()

就这样!您自动生成的 MCP 服务器现在可以在https://app.base.url/mcp上使用。

文档、示例和高级用法

FastAPI-MCP 提供了详尽的文档。此外,您还可以查看示例目录,获取演示这些功能的代码示例。

FastAPI 优先方法

FastAPI-MCP 被设计为 FastAPI 的原生扩展,而不仅仅是一个从 API 生成 MCP 工具的转换器。这种方法有几个关键优势:

  • 本机依赖项:使用熟悉的 FastAPI Depends()进行身份验证和授权,保护您的 MCP 端点

  • ASGI 传输:使用其 ASGI 接口直接与您的 FastAPI 应用通信,无需从 MCP 向您的 API 进行 HTTP 调用

  • 统一的基础架构:您的 FastAPI 应用无需与 MCP 服务器单独运行(尽管也支持单独部署

这种设计理念可确保在向现有 FastAPI 服务添加 MCP 功能时产生最小的摩擦。

开发与贡献

感谢您考虑为 FastAPI-MCP 做出贡献!我们鼓励社区发布问题 (Issues) 并创建拉取请求 (Pull Request)。

在开始之前,请参阅我们的贡献指南

社区

加入MCParty Slack 社区与其他 MCP 爱好者联系、提出问题并分享您使用 FastAPI-MCP 的经验。

要求

  • Python 3.10+(推荐3.12)

  • 紫外线

执照

MIT 许可证。版权所有 (c) 2024 Tadata Inc.

-
security - not tested
A
license - permissive license
-
quality - not tested

Resources

Looking for Admin?

Admins can modify the Dockerfile, update the server description, and track usage metrics. If you are the server author, to authenticate as an admin.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tadata-org/fastapi_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server