KF

kid0317/fastapi_mcpserver_base

Developer tools

This page was translated automatically. Technical details may differ from the original. View the original

7 stars 7 forks Quality 49 Trend 15

基于 FastAPI 构建的企业级 Model Context Protocol (MCP) 服务器框架,采用 2025 Streamable HTTP 传输协议规范。开箱即用,专为快速开发 MCP Tools / Resources / Prompts 而设计。

Overview

基于 FastAPI 构建的企业级 Model Context Protocol (MCP) 服务器框架,采用 2025 Streamable HTTP 传输协议规范。开箱即用,专为快速开发 MCP Tools / Resources / Prompts 而设计。 - - 遵循 MCP 2025-06-18 规范,单端点 (/mcp/) 双向通信,无状态模式无需 initialize - - 基于 FastAPI ASGI,全链路 async/await,高并发低延迟 - - API Key 鉴权(Bearer / X-API-Key)、Origin 校验、恒定时间比较防时序攻击 - - Structlog 结构化 JSON 日志 + Prometheus 指标(工具粒度耗时/计数/错误率) - - 控制台 + logs/app.log(全量)+ logs/app.log.wf(WARNING+),自动轮转 - - httpx 连接池 + Tenacity 指数退避重试 + 优雅关闭 - - @mcp_tool 一个装饰器完成工具注册 + 监控埋点,零样板代码 MCP 端点支持两种鉴权方式: - Authorization: Bearer - X-API-Key: 本框架的核心价值在于让你专注于业务逻辑。以下是开发三种 MCP 能力的完整指南。 - 使用 @mcp_tool(name=..., description=...) 装饰器,自动完成 MCP 注册 + Prometheus 监控 - 函数参数会自动生成 JSON Schema,成为 MCP inputSchema - 参数类型标注必须写清楚,MCP 客户端依赖此信息 - 支持默认值(unit="celsius" 会在 schema 中标记为 optional) - 返回值会自动序列化为 JSON 完成。

Install

docker run -p 8007:8000 -e MCP_API_KEY=your-secret-api-key fastapi-mcp-server
New to MCP? Start with the mcpskill.org guide →