使用说明
MCP模拟器
使用以下工具在单个端口上模拟N个虚拟MCP服务器 可流式传输的HTTP 运输。每台服务器都维护一组随机的工具,并定期对其进行修改,通过SSE通知连接的客户端。
为负载测试而构建的MCP客户端,可与数千台服务器保持持久连接。
快速开始
# Run with defaults (1000 servers, port 8080)
go run ./cmd/simulator/
# Custom configuration
go run ./cmd/simulator/ \
--servers 1000 \
--port 9090 \
--min-tools 3 \
--max-tools 10 \
--min-mutation-interval 5s \
--max-mutation-interval 60s
# Build and run binary
go build -o mcp-simulator ./cmd/simulator/
./mcp-simulator --servers 10000 --port 9090
旗帜
| 标志 | 默认值 | 描述 |
|---|---|---|
--port |
8080 |
HTTP服务器端口 |
--servers |
1000 |
虚拟MCP服务器数量 |
--min-tools |
3 |
init时每台服务器的最低工具数 |
--max-tools |
10 |
init时每台服务器的最大工具数 |
--min-mutation-interval |
5s |
工具突变之间的最短时间 |
--max-mutation-interval |
60s |
工具突变之间的最长时间 |
API
每个虚拟服务器都公开一个可流式传输的HTTP端点:
POST /server/{id}/mcp
支持的JSON-RPC方法
| 方法 | 描述 | 响应 |
|---|---|---|
initialize |
MCP握手 | 服务器功能 |
notifications/initialized |
客户端就绪信号 | 202已接受 |
tools/list |
列出当前工具 | 带inputSchema的工具数组 |
常规JSON响应
curl -X POST http://localhost:9090/server/0/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'
带有通知的SSE流
添加 Accept: text/event-stream 以SSE事件的形式接收响应,然后 notifications/tools/list_changed 服务器工具更改时的事件:
curl -N -X POST http://localhost:9090/server/0/mcp \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'
建筑
cmd/simulator/main.go Entry point, CLI flags, graceful shutdown
internal/jsonrpc/schema.go JSON-RPC 2.0 request/response/notification structs
internal/tools/tools.go Random tool generation and mutation
internal/server/config.go Server configuration
internal/server/registry.go Virtual server registry, HTTP routing
internal/server/virtual_server.go VirtualServer state, pub/sub, mutation loop
internal/server/handler.go HTTP handler, JSON-RPC dispatch, SSE streaming
- 每台服务器上有一个goroutine运行一个变异循环(以随机间隔添加/删除/更新随机工具)
- 突变广播
notifications/tools/list_changed面向所有SSE用户 - 零外部依赖关系——仅限标准库
