待我绝境涅槃 (@LiLin) 在 使用FastAPI MCP开发自己的MCP服务 中发帖
FastAPI MCP简介
FastAPI MCP是一个零配置工具,可自动将你的FastAPI端点作为模型上下文协议(MCP)工具暴露出来。
使用FastAPI MCP,你可以:
自动将FastAPI端点转换为MCP工具
保留您的API架构和文档
将MCP服务器与您的API一起部署或作为单独的服务
自定义哪些端点作为工具暴露
控制如何生成工具描述
FastAPI MCP安装
在开始使用之前,您需要安装FastAPI MCP包。你有两个选择:
使用uv (推荐更快安装):
uv add fastapi-mcp
使用pip:
pip install fastapi-mcp
实现
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
# Your existing Fas...