Integrations
Supports environment variable configuration through .env files for customizing server settings like host, port, and database connections
Integrates with FastAPI framework to provide high-performance server-side events (SSE) communication and schema validation capabilities for Model Context Protocol implementations
Provides repository integration for code management and version control via the specified GitHub repository
🚀 FastAPI MCP 服务器
FastAPI MCP服务器是一个专为大型语言模型设计的Model Context Protocol (MCP) 集成应用,基于FastAPI框架开发,提供高性能的服务器端事件(SSE)通信、智能工具注册和完善的会话管理功能。
📖 项目简介
此项目是一个轻量级、高性能的MCP服务器实现,旨在简化AI模型与用户应用程序之间的交互。它利用FastAPI的异步特性和Schema验证能力,结合SSE(Server-Sent Events)技术实现低延迟的实时通信,并通过会话管理系统支持多用户、多模型并发交互,为开发AI驱动的应用提供强大后端支持。
✨ 项目亮点
- 🔄 FastAPI + MCP整合:将FastAPI的高性能与MCP协议无缝集成,提供标准化的模型交互接口
- 📡 高效SSE实时通信:基于服务器发送事件(SSE)实现毫秒级响应的单向实时数据流
- 👥 多用户会话隔离:完善的会话创建、存储和管理机制,确保多用户场景下的数据隔离
- 🔐 灵活认证机制:支持多种认证方式,包括token、path和query参数,满足不同场景需求
- ⚡ 全异步处理架构:从请求处理到数据库操作均采用异步设计,支持高并发访问
- 🧰 智能工具注册系统:简化AI工具函数的注册和管理,便于扩展模型能力
🔍 工作原理
📸 屏幕截图
MCP交互界面
MCP Inspector参数无感透传
MCP Inspector参数鉴权校验
📁 项目结构
🛠️ 安装指南
前置条件
- 🐍 Python 3.13+
- 🗄️ 支持异步的数据库(可选)
- 📦 uv包管理器(推荐)
安装步骤
- 克隆代码库:
- 创建并激活虚拟环境:
- 安装依赖:
使用uv安装(推荐):
或使用pip安装:
- 配置环境变量:
创建.env
文件,参考.env.example
设置必要的环境变量。
- 创建数据库:
需要在database目录下创建session.db数据库文件,可以通过运行以下命令初始化:
- 自定义鉴权逻辑:
在auth/credential.py
中实现您自己的API密钥验证逻辑。默认提供了基本框架,您需要根据自己的需求修改:
🚀 使用指南
启动服务器
使用Python启动:
使用uv启动:
使用inspector模式启动(调试):
服务器默认运行在 http://localhost:8000
自定义工具
在tools/
目录下添加您的自定义工具函数,并在server.py
中注册:
⚙️ 环境变量
变量名 | 描述 | 默认值 | 是否必需 |
---|---|---|---|
HOST | 服务器主机 | 127.0.0.1 | 否 |
PORT | 服务器端口 | 8000 | 否 |
DATABASE_URL | 数据库连接地址 | 无 | 是 |
🔧 常见问题解决
连接问题
- 无法启动服务器:检查端口是否被占用,尝试更改
PORT
环境变量 - SSE连接断开:检查网络连接,或者客户端超时设置
工具注册问题
- 工具注册失败:确保工具函数格式正确,并且已正确导入
- 工具执行错误:检查工具函数的错误处理逻辑
会话管理问题
- 会话创建失败:检查数据库连接配置
- 会话过期:调整会话过期时间,或确保客户端保持活跃连接
🔮 未来规划
我们计划在未来版本中添加以下功能:
- Docker容器部署
- 创建优化的Docker镜像
- 提供docker-compose配置
- 支持多容器协作部署
- IP黑白名单系统
- 基于IP的访问控制
- 支持CIDR格式的网络规则
- 可配置的拦截策略
- FastMCP Streamable模式支持
- 支持异步流式响应传输
- 实现MCP协议的流式处理机制
- 提供流式传输的进度监控和错误处理
- 高级监控与日志
- 实时性能监控
- 结构化日志输出
- 分布式追踪支持
📜 许可证
本项目采用 MIT 许可证 - 详情请查看 LICENSE 文件。
This server cannot be installed
A high-performance Model Context Protocol (MCP) server designed for large language models, enabling real-time communication between AI models and applications with support for session management and intelligent tool registration.
Related MCP Servers
- AsecurityAlicenseAqualityAn MCP (Model Context Protocol) server that integrates with the ArgoCD API, enabling AI assistants and large language models to manage ArgoCD applications and resources through natural language interactions.Last updated -106PythonMIT License
- -securityFlicense-qualityA Model Context Protocol server implementation that enables seamless integration with Claude and other MCP-compatible clients to access Prem AI's language models, RAG capabilities, and document management features.Last updated -JavaScript
- -securityFlicense-qualityA demonstration implementation of the Model Context Protocol server that facilitates communication between AI models and external tools while maintaining context awareness.Last updated -Python
- -security-license-qualityA Model Context Protocol (MCP) server that allows AI assistants like Claude to interact with Go's Language Server Protocol (LSP) and benefit from advanced Go code analysis features.Last updated -GoApache 2.0