使用说明
Dublyo MCP网关
轻量级、多租户 模型上下文协议 (MCP)网关,在任何服务器上运行,并通过HTTPS公开MCP工具。内置Go,零框架依赖。
每个网关实例承载多个MCP连接,每个连接都有自己的子域、API密钥和配置文件,所有这些都通过单个容器路由。
特性
- 18个内置配置文件 --文件系统、Web Fetch、WordPress知识、内存、时间、DNS、加密、健康检查、Cron、Regex、数学、IP、Webhook、电子邮件、数据转换、数据库(PostgreSQL)、Redis和顺序思维
- 两个MCP传输 --SSE(兼容克劳德桌面)和流式HTTP
- 每次连接身份验证 -使用恒定时间比较的带胡椒的SHA-256 API密钥验证
- 速率限制 --每个连接的滑动窗口(可配置请求/分钟)
- 并发控制 --每个连接的最大并发会话数
- 指标报告 --请求计数、错误率、P95延迟、活动会话
- 自动配置同步 -每隔30秒轮询一次Dublyo API以了解连接更改
- 自动令牌刷新 --网关JWT令牌在到期前透明刷新
- Traefik集成 --通配符子域路由的Docker标签
- 占地面积小 --约15MB基于Alpine的Docker镜像
快速开始
docker run -d \
--name mcp-gateway \
-e GATEWAY_TOKEN=your_jwt_token \
-e DUBLYO_API_URL=https://your-api-url.example.com \
-p 8080:8080 \
ghcr.io/dublyo/mcp-gateway:latest
或者使用Docker Compose:
services:
mcp-gateway:
image: ghcr.io/dublyo/mcp-gateway:latest
restart: unless-stopped
environment:
- GATEWAY_TOKEN=${GATEWAY_TOKEN}
- DUBLYO_API_URL=https://your-api-url.example.com
ports:
- "8080:8080"
volumes:
- mcp-data:/data
volumes:
mcp-data:
环境变量
| 变量 | 必填 | 默认 | 描述 |
|---|---|---|---|
GATEWAY_TOKEN |
是 | - | JWT令牌用于Dublyo API身份验证 |
GATEWAY_PORT |
没有 | 8080 |
HTTP侦听端口 |
DUBLYO_API_URL |
没有 | - | Dublyo API配置同步和度量的基本URL |
SYNC_INTERVAL |
没有 | 30s |
配置同步轮询间隔 |
METRICS_INTERVAL |
没有 | 30s |
指标报告间隔 |
LOG_LEVEL |
没有 | info |
日志冗长(debug, info, warn, error) |
建筑
Client (Claude Desktop / SDK / Any MCP Client)
│
│ HTTPS + Bearer Token
▼
┌─────────────────────────────────────────┐
│ MCP Gateway Container (:8080) │
│ │
│ Host header ──► Connection lookup │
│ Bearer token ──► SHA-256 verification │
│ Rate limit check ──► Sliding window │
│ │
│ ┌─────────┐ ┌─────────┐ │
│ │ SSE │ │ HTTP │ Transports │
│ │ /sse │ │ /mcp │ │
│ └────┬────┘ └────┬────┘ │
│ └──────┬─────┘ │
│ ▼ │
│ ┌──────────────────┐ │
│ │ JSON-RPC Handler │ │
│ └────────┬─────────┘ │
│ ▼ │
│ ┌──────────────────┐ │
│ │ Profile Handler │ (18 profiles) │
│ └──────────────────┘ │
└─────────────────────────────────────────┘
│ ▲
│ Metrics (30s) │ Config sync (30s)
▼ │
Dublyo API ───────────────┘
端点
| 路线 | 方法 | 授权 | 描述 |
|---|---|---|---|
/health |
GET | 无 | 健康检查--返回 {"status":"ok"} |
/sse |
GET | Bearer | 打开SSE流(兼容克劳德桌面) |
/message |
POST | 承载 | 向SSE会话发送JSON-RPC消息 |
/mcp |
POST | 承载 | 流式HTTP——JSON-RPC请求/响应 |
/mcp |
GET | 承载 | 流式HTTP——保持SSE流的活动状态 |
/mcp |
DELETE | 无 | 可流式HTTP--终止会话 |
档案
| ID | 名称 | 工具 | 需要配置 |
|---|---|---|---|
filesystem |
文件系统 | 8 | ALLOWED_PATHS |
fetch |
Web提取 | 2 | 可选 ALLOWED_DOMAINS |
wordpress-knowledge |
WordPress知识 | 4 | LLMS_TXT_URL |
memory |
内存 | 5 | 可选 PERSIST_PATH |
time |
时区 | 4 | 可选 DEFAULT_TIMEZONE |
thinking |
顺序思维 | 1 | 无 |
dns |
DNS和网络 | 4 | 无 |
crypto |
哈希和加密 | 6 | 无 |
healthcheck |
HTTP和SSL监视器 | 4 | 无 |
cron |
Cron计划程序 | 3 | 无 |
regex |
正则表达式测试器 | 4 | 无 |
math |
数学和计算器 | 5 | 无 |
ip |
IP和网络 | 4 | 无 |
webhook |
Webhook发送器 | 3 | 可选 SLACK_WEBHOOK_URL, DISCORD_WEBHOOK_URL |
email |
电子邮件发件人 | 3 | SMTP_HOST, FROM_ADDRESS |
transform |
数据转换 | 8 | 无 |
database |
数据库(PostgreSQL) | 4 | DATABASE_URL |
redis |
Redis | 6 | REDIS_URL |
添加个人资料
- 创建
internal/profiles/yourprofile.go实施Profile接口:
package profiles
type YourProfile struct{}
func (p *YourProfile) ID() string { return "your-profile" }
func (p *YourProfile) Tools() []Tool {
return []Tool{
{
Name: "your_tool",
Description: "What your tool does",
InputSchema: map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"param": map[string]interface{}{
"type": "string",
"description": "Parameter description",
},
},
"required": []string{"param"},
},
},
}
}
func (p *YourProfile) CallTool(name string, args map[string]interface{}, env map[string]string) (string, error) {
switch name {
case "your_tool":
// Implementation here
return "result", nil
default:
return "", fmt.Errorf("unknown tool: %s", name)
}
}
- 在中注册
internal/profiles/profiles.go:
func init() {
reg := []Profile{
// ... existing profiles
&YourProfile{},
}
// ...
}
- 推至
main--CI自动构建并推送到GHCR。
从源头构建
# Clone
git clone https://github.com/dublyo/mcp-gateway.git
cd mcp-gateway
# Build binary
go build -o mcp-gateway ./cmd/gateway
# Run
GATEWAY_TOKEN=your_token ./mcp-gateway
Docker构建
docker build -t mcp-gateway .
docker run -e GATEWAY_TOKEN=your_token -p 8080:8080 mcp-gateway
MCP协议
网关实现 模型上下文协议 规范版本 2024-11-05.
支持的JSON-RPC方法:
initialize--返回服务器信息和功能ping--健康检查tools/list--返回连接配置文件的可用工具tools/call--执行工具并返回结果
与Claude Desktop连接:
添加到您的Claude桌面配置(claude_desktop_config.json):
{
"mcpServers": {
"my-server": {
"url": "https://my-server-a1b2c3d4.dublyo.xyz/sse",
"headers": {
"Authorization": "Bearer dky_your_api_key_here"
}
}
}
}
项目结构
mcp-gateway/
├── cmd/gateway/main.go # Entry point
├── internal/
│ ├── gateway/
│ │ ├── gateway.go # Core: connections, auth, rate limits, metrics
│ │ ├── poller.go # Config sync + metrics reporting loops
│ │ └── traefik.go # Optional Traefik file provider config
│ ├── mcp/
│ │ ├── handler.go # JSON-RPC 2.0 protocol handler
│ │ └── types.go # MCP protocol type definitions
│ ├── profiles/
│ │ ├── profiles.go # Profile interface + registry
│ │ ├── filesystem.go # File operations (sandboxed)
│ │ ├── fetch.go # HTTP fetch (SSRF-safe)
│ │ ├── wordpress_knowledge.go # WordPress llms.txt search
│ │ ├── memory.go # Key-value store
│ │ ├── time.go # Timezone operations
│ │ ├── thinking.go # Structured reasoning
│ │ ├── dns.go # DNS lookups
│ │ ├── crypto.go # Hashing, UUID, passwords
│ │ ├── healthcheck.go # URL/SSL monitoring
│ │ ├── cron.go # Cron expressions
│ │ ├── regex.go # Regex operations
│ │ ├── math_profile.go # Math/stats/conversion
│ │ ├── ip.go # IP/CIDR/subnet
│ │ ├── webhook.go # Webhooks, Slack, Discord
│ │ ├── email.go # SMTP email
│ │ ├── transform.go # JSON, Base64, URL encoding
│ │ ├── database.go # PostgreSQL queries
│ │ └── redis.go # Redis operations
│ └── server/
│ └── server.go # HTTP server, SSE + HTTP transports
├── Dockerfile # Multi-stage build (Alpine 3.20)
├── go.mod
└── .github/workflows/build.yml # CI: build + push to GHCR
许可证
该项目根据 GNU Affero通用公共许可证v3.0 (AGPL-3.0)。
您可以自由使用、修改和分发此软件。如果修改它并将其作为网络服务运行,则必须使该服务的用户可以使用修改后的源代码。
由...建造 Dublyo.
