FastAPI-MCP:将 FastAPI 转换为 MCP 工具
将 FastAPI 端点暴露为支持身份验证的模型上下文协议 (MCP) 工具。
快速入门
-
安装 使用 uv 安装:
uv add fastapi-mcp
或使用 pip:
pip install fastapi-mcp
-
基本用法 在 FastAPI 应用中添加 MCP 服务器:
from fastapi import FastAPI from fastapi_mcp import FastApiMCP
app = FastAPI() mcp = FastApiMCP(app) mcp.mount()
-
访问
https://app.base.url/mcp
查看生成的 MCP 服务。
更多文档和示例,请参考 官方文档。