MCP服务器部署工具

用于创建和部署自定义MCP服务器的工具集,支持虚拟环境配置、依赖管理及Docker容器化部署。

  • by Benjamincf0
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Benjamincf0/mcp-servers

使用说明

MCP服务器

这个仓库包含各种自定义的MCP服务器

要创建一个mcp服务器,请按照以下步骤操作:

  1. 创建一个新目录并为其命名

  2. 创建并激活一个虚拟环境(我认为这会生成一个pyproject.toml文件)

    uv venv
    source .venv/bin/activate
    
  3. 然后运行

    uv sync
    

    这应该会将一个 uv.lock 文件与 .toml 文件进行同步。

  4. 添加 UV 依赖项 mcp[cli] 及其任何其他依赖项

  5. 创建一个main.py文件,并添加你的MCP代码

  6. 如果使用 Docker,请创建一个 Dockerfile。这个文件描述了如何创建一个 Docker 虚拟机来运行你的服务器

    # Use Python slim image
    FROM python:3.10-slim
    
    # Set working directory
    WORKDIR /app
    
    # Install uv (the package manager used in the tutorial)
    RUN pip install uv
    
    # Copy your project files
    COPY pyproject.toml .
    COPY weather.py .
    
    # Install dependencies using uv
    RUN uv sync
    
    # Set the entrypoint to run your server
    ENTRYPOINT ["uv", "run", "weather.py"]
    
  7. 编辑这个 ~/.docker/mcp/catalogs/custom.yaml

    version: 2
    name: custom
    displayName: Custom MCP Servers
    registry:
    weather-mcp:
        description: "Weather forecast and alerts"
        title: "Weather Server"
        type: server
        dateAdded: "2025-01-01T00:00:00Z"
        image: weather-mcp-server:latest
        ref: ""
        tools:
        - name: get_alerts
        - name: get_forecast
    
  8. 编辑这个 ~/.docker/mcp/custom-registry.yaml

    registry:
        weather-mcp:
            ref: ""
    
  9. 然后检查Claude配置的自定义目录和注册表@ ~/Library/Application Support/Claude/claude_desktop_config.json

    {
        "mcpServers":{
            "weather":{
                "command":"uv",
                "args":["--directory","/Users/benjamin/Code/mcp-servers/weather","run","weather.py"]
            },
                "MCP_DOCKER": {
                    "command": "docker",
                    "args": [
                        "run",
                        "-i",
                        "--rm",
                        "-v", "/var/run/docker.sock:/var/run/docker.sock",
                        "-v", "/Users/benjamin/.docker/mcp:/mcp",
                        "docker/mcp-gateway",
                        "--catalog=/mcp/catalogs/docker-mcp.yaml",
                        "--catalog=/mcp/catalogs/custom.yaml",
                        "--registry=/mcp/registry.yaml",
                        "--registry=/mcp/custom-registry.yaml",
                        "--transport=stdio"
        ]
                }
        }
    }