@wunderio/wdrmcp
一个通用的MCP(模型上下文协议)服务器,它从YAML配置文件中动态加载工具定义,并在Docker容器中执行它们,或者将它们代理到远程MCP服务器。
特性
- YAML驱动的工具定义 --以声明方式定义工具,无需更改代码
- Docker容器执行 --在带有安全验证的Docker容器中运行命令
- MCP服务器代理 --代理工具通过HTTP JSON-RPC/流式HTTP MCP调用远程MCP服务器
- 动态工具发现 --自动从远程MCP服务器获取和公开工具
- 安全 --容器所有权验证、命令注入预防、参数验证
- DDEV集成 --对DDEV容器命名和项目范围的内置支持
安装
npm install -g @wunderio/wdrmcp或者直接与npx一起使用:
npx @wunderio/wdrmcp --tools-config /path/to/tools-config用法
命令行界面
wdrmcp --tools-config /path/to/tools-config [options]选项:
| 标志 | 描述 | 默认值 |
|---|---|---|
| `--tools-config | ||
| ` | YAML工具配置目录的路径 | *(必填)* |
--log-level | 日志级别(调试、信息、警告、错误) | info |
| `--log-file | ||
| ` | 日志文件路径 | /tmp/wdrmcp.log |
--strict-host-key-checking | 强制SSH主机密钥验证 | false |
环境变量:
| 变量 | 描述 | 默认值 |
|---|---|---|
DDEV_PROJECT | DDEV项目名称 | default-project |
HOST_PROJECT_ROOT | 主机文件系统项目根 | /workspace |
CONTAINER_PROJECT_ROOT | 容器文件系统项目根 | /var/www/html |
SSH_STRICT_HOST_KEY_CHECKING | 强制SSH主机密钥验证(true/false) | false |
VS代码/GitHub副本配置
{
"servers": {
"wdrmcp": {
"command": "npx",
"args": ["-y", "@wunderio/wdrmcp", "--tools-config", "/path/to/tools-config"],
"env": {
"DDEV_PROJECT": "my-project"
}
}
}
}工具配置格式
工具在Tools-config目录中的YAML文件中定义。每个文件必须包含 tools 阵列。
命令工具
通过SSH执行shell命令:
tools:
- name: my_tool
enabled: true
description: "What this tool does"
type: command
command_template: "my-command {arg1} {arg2}"
ssh_target: "web"
ssh_user: "${DDEV_SSH_USER}"
working_dir: "/var/www/html"
shell: "bash" # Uses /usr/bin/env to resolve the shell
default_args:
arg2: "default-value"
disallowed_commands:
- "rm"
- "shutdown"
validation_rules:
- pattern: "dangerous-pattern"
message: "This pattern is not allowed"
max_arg_length: 4096
input_schema:
type: object
properties:
arg1:
type: string
description: "First argument"
required:
- arg1MCP服务器代理工具
代理工具调用远程MCP服务器:
tools:
- name: remote_tools
enabled: true
description: "Remote MCP server"
type: mcp_server
server_url: "http://localhost:8080"
expose_remote_tools: true
tool_prefix: "remote_"
timeout: 30
auth_token: "${REMOTE_MCP_TOKEN}"笔记:
wdrmcp支持普通JSON-RPC HTTP MCP端点和流式HTTP MCP端点。- 对于流式HTTP服务器,
wdrmcp执行initialize和notifications/initialized,保持mcp-session-id,并发送Accept: application/json, text/event-stream.
建筑
src/
├── index.ts # CLI entry point
├── server.ts # MCP server setup (tool registration with Zod schemas)
├── registry.ts # Tool registry (YAML loading, executor creation)
├── executors/
│ ├── base.ts # Base executor interface
│ ├── command.ts # Docker container command executor
│ └── mcp-proxy.ts # Remote MCP server proxy executor
├── docker.ts # Docker exec & container validation
├── config.ts # CLI argument parsing
├── logger.ts # Stderr-only logger
└── types.ts # TypeScript type definitions许可证
麻省理工学院
安全说明
- 中的参数占位符
command_template在执行之前,每个参数都进行了shell转义。 disallowed_commands与参数值和呈现的命令字符串匹配。- 主机密钥验证是可配置的;集
--strict-host-key-checking(或SSH_STRICT_HOST_KEY_CHECKING=true)用于类似生产的环境。 - 使用环境占位符作为凭据(
${VAR})而不是YAML中的字面秘密。
