使用说明
MCP模拟器
Go内置了一个全面的模型上下文协议(MCP)模拟器,允许开发人员使用动态配置和AI生成的数据模拟多个MCP服务器。
特性
- 多服务器支持:在不同端口上运行多个虚拟MCP服务器
- 动态配置:在运行时添加工具、资源和提示
- AI驱动的模拟:使用OpenAI/Anthropic API生成逼真的模拟数据
- SSE支持:用于MCP通信的内置服务器发送事件适配器
- Web用户界面:用于管理服务器和生成模拟的现代基于React的界面
- 单一二进制:前端嵌入Go二进制文件,便于部署
快速开始
先决条件
- 转到1.22+
- Node.js 18+和npm
- OpenAI API密钥(用于AI模拟生成)
构建
# Build everything (web + server) into a single binary
make build
# Or build manually
cd web && npm install && npm run build && cd ..
go build -o mcp-simulator ./cmd/mcp-simulator
跑
# Set your OpenAI API key
export OPENAI_API_KEY=your-api-key-here
# Run the simulator
./mcp-simulator
应用程序将于启动 http://localhost:8080
发展
网站开发
# Run web dev server with hot reload
make dev
构建目标
make build-构建完整的应用程序(网络+服务器)make clean-清理所有构建工件make install-web-安装web依赖项make build-web-仅构建web前端make build-server-仅构建Go服务器make run-构建并运行应用程序make help-显示所有可用目标
API使用
创建虚拟服务器
curl -X POST http://localhost:8080/api/servers \
-H "Content-Type: application/json" \
-d '{"id": "srv1", "name": "GitHub Mock", "port": 8081}'
启动服务器
curl -X POST http://localhost:8080/api/servers/srv1/start
用AI生成模拟数据
curl -X POST http://localhost:8080/api/ai/generate \
-H "Content-Type: application/json" \
-d '{
"prompt": "Generate a list of 5 recent orders",
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {"type": "string"},
"total": {"type": "number"}
}
}
}
}'
建筑
该系统遵循清洁架构原则:
- 基础设施层:服务器管理、传输适配器(SSE、Stdio)、配置
- 域/引擎层:核心逻辑、动态注册表、智能路由器、模拟策略
- 应用层:管理API,请求检查,AI服务集成
- Web层:使用Tailwind CSS的React UI
许可证
麻省理工学院
