微服务控制平面服务器模板

一个基于Python的微服务控制平面(MCP)服务器模板,提供健康检查控制器和OpenAPI支持,支持Docker和本地运行,并可集成到Claude Desktop中。

  • by fgaule
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 fgaule/python-mcp-server-template

使用说明

python mcp服务器模板

微服务控制平面(MCP)服务器的Python模板,具有健康检查控制器和OpenAPI支持。
已准备好在本地使用Docker运行,或作为Claude Desktop的MCP服务器运行。


目录


特性

  • 基于FastAPI的Python服务器
  • 健康检查端点
  • OpenAPI(Swagger)文档
  • Docker和本地开发支持
  • 已准备好通过MCP与Claude Desktop集成

先决条件


快速开始

使用Docker运行

docker-compose up --build

API将于 http://localhost:8000.

验证应用程序是否正在运行:

curl -X GET http://localhost:8000/healthz

预期响应:

{"message":"API is up and running!!"}

本地运行(使用紫外线)

pip install uv
make init
make run

或者,直接:

uv run src/main.py

API将于 http://localhost:8000.

验证应用程序是否正在运行:

curl -X GET http://localhost:8000/healthz

预期响应:

{"message":"API is up and running!!"}

作为Claude Desktop的MCP服务器运行

  1. 打开Claude Desktop配置目录:

    open ~/Library/Application\ Support/Claude
    
  2. 转到克劳德->设置->开发人员->编辑配置

  3. 创建或编辑 claude_desktop_config.json:

    {
      "mcpServers": {
        "python-mcp-server-template": {
          "command": "/absolute/path/to/uv",
          "args": [
            "--directory",
            "/absolute/path/to/python-mcp-server-template",
            "run",
            "src/main.py"
          ]
        }
      }
    }
    
    • 用实际位置替换路径。
    • 找到你的 uv 路径与 which uv.

示例:使用npx和mcp-remote(本地主机:8000)

如果您想使用以下命令将Claude Desktop连接到远程MCP服务器 npx 和 mcp-remote,您可以在 claude_desktop_config.json:

{
  "mcpServers": {
    "python-mcp-server-template": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://localhost:8000/mcp/"
      ]
    }
  }
}
  • 这将使用 npx 运行 mcp-remote 打包并连接到MCP服务器 https://localhost:8000/mcp/.
  • 确保你有 npx 已安装(它随Node.js一起提供)。
  • 您可以在下面添加多个服务器 mcpServers 不同环境或项目的关键。

Makefile命令

命令 描述
make init 安装依赖项
make run 在本地运行
make run_local 在Docker中运行
make test 运行单元测试
make coverage-test 运行覆盖率测试
make integration-test 运行集成测试
make tear_down_containers 停止并删除Docker容器

贡献

欢迎投稿!
请看 贡献.md 作为指导方针。


许可证

麻省理工学院 或您偏好的许可证。