TO

tadata-org/fastapi_mcp

API 开发

本页由 AI 翻译,技术细节请以原文为准。 查看原文

1.2万 stars 967 forks 质量 62 趋势 31MIT

将你的FastAPI端点暴露为模型上下文协议(MCP)工具,使用Auth!

概览

将你的FastAPI端点暴露为模型上下文协议(MCP)工具,使用Auth! - 内置,利用你现有的FastAPI依赖! - 不仅仅是另一个OpenAPI -> MCP转换器 - 必须 - 只需指向你的 FastAPI 应用,它就能正常工作 - 你的请求模型和响应模型 - 所有端点中,就像Swagger一样 - - 将你的MCP服务器挂载到同一个应用,或单独部署 - - 直接使用 FastAPI 的 ASGI 接口以实现高效通信

概述(AI 翻译)

由塔达塔制造

FastAPI-MCP

将你的FastAPI端点暴露为模型上下文协议(MCP)工具,使用Auth!

特色

  • 认证内置,利用你现有的FastAPI依赖!

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

  • 零/最小配置要求 - 只需指向你的FastAPI应用,它就能正常工作

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

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

  • 灵活部署 - 将你的MCP服务器挂载到同一应用,或单独部署

  • ASGI 传输 - 直接使用 FastAPI 的 ASGI 接口以实现高效通信

托管解决方案

如果你更喜欢托管的解决方案,可以看看 tadata.com。

安装

我们推荐使用uv,一个快速的Python软件包安装器:

或者,你也可以用PIP安装:

基本用法

使用FastAPI-MCP最简单的方式是直接在你的FastAPI应用中添加一个MCP服务器:

就是这样!你的自动生成MCP服务器现在已在https://app.base.url/mcp开放。

文档、示例与高级用法

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

FastAPI-MCP

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

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

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →