使用说明
MCP服务器
这个仓库包含各种自定义的MCP服务器
要创建一个mcp服务器,请按照以下步骤操作:
-
创建一个新目录并为其命名
-
创建并激活一个虚拟环境(我认为这会生成一个pyproject.toml文件)
uv venv source .venv/bin/activate -
然后运行
uv sync这应该会将一个 uv.lock 文件与 .toml 文件进行同步。
-
添加 UV 依赖项 mcp[cli] 及其任何其他依赖项
-
创建一个main.py文件,并添加你的MCP代码
-
如果使用 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"] -
编辑这个
~/.docker/mcp/catalogs/custom.yamlversion: 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 -
编辑这个
~/.docker/mcp/custom-registry.yamlregistry: weather-mcp: ref: "" -
然后检查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" ] } } }
