Back to MCP directory
publicPublicdnsLocal runtime

mcp-examples

该项目展示了一个MCP服务器与客户端的示例,包含Docker容器运行配置及工具模块。

article

README

🚀 MCP示例项目

本项目展示了一个模型上下文协议(MCP)的服务器和客户端设置,包含在Docker容器中运行服务器所需的工具和配置。

📦 安装指南

构建Docker镜像

从项目根目录运行以下命令:

docker build -t mcp-example-stdio-server:latest .

这将创建一个名为 mcp-example-stdio-server:latest 的Docker镜像,其中包含MCP服务器。

独立运行服务器

可以直接运行以下命令启动服务器:

docker run --rm -i mcp-example-stdio-server:latest

服务器将启动并监听MCP标准输入输出请求。

💻 使用示例

mcp.json 配置

.vscode/mcp.json 文件用于配置在开发环境(如VS Code)中如何启动MCP服务器:

{
  "servers": {
    "example-mcp-server": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "mcp-example-stdio-server:latest"
      ]
    }
  },
  "inputs": []
}
  • typestdio 表示服务器通过标准输入输出进行通信。
  • command:用于启动服务器的命令(docker)。
  • args:运行带有已构建镜像的Docker容器的参数。

这种设置允许开发工具在容器化环境中自动启动MCP服务器。

📚 详细文档

项目结构

.
├── Dockerfile                # MCP服务器的Docker构建指令
├── pyproject.toml            # Python项目配置
├── uv.lock                   # 依赖项的锁文件
├── README.md                 # 项目文档
├── client/                   # 客户端代码(如果有)
└── servers/                  # MCP服务器实现
    ├── __init__.py
    ├── main.py               # 服务器的主入口点
    └── tools/                # 额外的服务器工具
        ├── __init__.py
        ├── calendar.py       # 日历工具实现
        ├── task_manager.py   # 任务管理器工具实现
        └── weather.py        # 天气工具实现

🔧 技术细节

  • 确保系统上已安装并运行Docker。
  • 在对服务器代码进行更改后,根据需要通过重新构建镜像来更新Docker镜像。
  • servers/tools/ 目录包含模块化的工具实现,可以根据需要进行扩展。
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client