使用说明
🚀 MCP模拟服务器
全面 模型上下文协议(MCP) 用于测试和开发的模拟服务器。这是功能最丰富的MCP模拟服务器,旨在帮助开发人员使用真实的数据和全面的工具测试MCP集成。
✨ 特性
- 🎯 完整的MCP流式HTTP传输 -符合HTTP/SSE的官方MCP协议
- 🔌 邮递员MCP客户端兼容 -与Postman的新MCP功能无缝协作
- 🛠️ 17+模拟工具 -CRUD操作、分析、实用程序和AI/ML工具
- 📊 丰富的模拟数据 -用户、帖子、产品、订单和分析
- 🎨 漂亮的CLI界面 -彩色输出,综合记录
- 📝 温斯顿测井 -具有多种传输的结构化日志记录
- ⚡ 即时设置 -直接与
npx mcp-mock-server - 🔧 可配置的 -自定义数据、端口和配置
- 🌐 CORS已启用 -为web开发做好准备
- 📋 JSON模式验证 -对所有工具进行适当的输入验证
- 📡 实时流媒体 -基于WebSocket的实时数据流
- 🔄 多种流类型 -用户活动、分析、聊天、传感器、日志、股票
- 🏠 服务器发送的事件 -SSE支持实时服务器到客户端通信
- 🔄 JSON-RPC 2.0 -完整的JSON-RPC协议实现
🚀 快速开始
立即运行(无需安装)
npx mcp-mock-server
全球安装
npm install -g mcp-mock-server
mcp-mock-server
本地安装
npm install mcp-mock-server
npx mcp-mock-server
🛠️ 可用工具
👥 用户管理
get_users-使用过滤选项检索模拟用户create_user-创建新的模拟用户update_user-更新现有用户数据delete_user-按ID删除用户
📝 内容管理
get_posts-使用过滤器检索博客文章create_post-创建新博客文章
🛒 电子商务
get_products-浏览产品目录process_order-处理模拟订单
📊 分析和报告
get_analytics-生成分析数据generate_report-创建业务报告
🔧 公用事业
validate_email-电子邮件验证generate_uuid-UUID生成format_date-日期格式
🤖 AI/ML工具
analyze_sentiment-模拟情绪分析classify_text-模拟文本分类
📡 流媒体工具
start_stream-启动实时数据流get_streaming_info-获取流媒体功能信息
📖 使用示例
列出可用工具
mcp-mock-server tools
获取流媒体信息
mcp-mock-server streaming
从自定义配置开始
mcp-mock-server --port 8080 --log-level debug
使用自定义数据文件
mcp-mock-server --data ./my-data.json
🌐 API终点
运行时,服务器提供多个端点:
健康与公用事业
GET /-健康检查和服务器信息GET /health-详细的健康信息GET /tools-列出所有可用工具POST /tools/call-执行工具
流媒体
GET /streaming/info-获得流媒体功能GET /streaming/stats-获取流媒体统计数据WS /stream-WebSocket流媒体端点
MCP协议(流式HTTP传输)
GET /mcp-打开SSE流以进行服务器到客户端的通信POST /mcp-发送JSON-RPC请求(初始化、工具/列表、工具/调用)OPTIONS /mcp-CORS飞行前支持DELETE /mcp-会话终止
传统MCP端点
POST /mcp/initialize-MCP协议初始化GET /mcp/tools/list-MCP工具列表POST /mcp/tools/call-MCP工具执行
🔌 邮递员MCP客户端
此服务器与Postman的新MCP客户端功能完全兼容:
- 打开邮递员 并创建新的MCP请求
- 输入地址:
http://localhost:7988/mcp - 单击连接 -服务器功能将自动加载
- 浏览工具 -所有17个工具都将在“工具”选项卡中可用
- 执行工具 -调用具有适当参数的任何工具
MCP标头
服务器支持所有官方MCP标头:
MCP-Protocol-Version: 2024-11-05Accept: application/json, text/event-streamMCP-Session-Id(用于会话管理)
📖 JSON-RPC示例
初始化MCP连接
curl -X POST http://localhost:7988/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "MCP-Protocol-Version: 2024-11-05" \
-d '{
"jsonrpc": "2.0",
"method": "initialize",
"id": 1,
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {}
}
}'
列出可用工具(MCP)
curl -X POST http://localhost:7988/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "MCP-Protocol-Version: 2024-11-05" \
-d '{
"jsonrpc": "2.0",
"method": "tools/list",
"id": 2
}'
呼叫工具(MCP)
curl -X POST http://localhost:7988/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "MCP-Protocol-Version: 2024-11-05" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"id": 3,
"params": {
"name": "get_users",
"arguments": {
"limit": 2,
"role": "admin"
}
}
}'
打开SSE流
curl -N -H "Accept: text/event-stream" \
-H "MCP-Protocol-Version: 2024-11-05" \
http://localhost:7988/mcp
🧪 使用MCP客户端进行测试
邮递员MCP客户端
- 打开邮差,寻找 主控程序 新请求中的选项卡
- 输入服务器URL:
http://localhost:7988/mcp - 点击 连接 -功能将自动加载
- 浏览中的可用工具 工具 章节
- 执行具有适当参数验证的工具
Claude桌面集成
添加到您的Claude Desktop配置中:
{
"mcpServers": {
"mock-server": {
"command": "node",
"args": ["/path/to/mcp-server/index.js"],
"env": {
"PORT": "7988"
}
}
}
}
自定义MCP客户端
async function testMCPClient() {
// Initialize connection
const initResponse = await fetch('http://localhost:7988/mcp', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
'MCP-Protocol-Version': '2024-11-05'
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'initialize',
id: 1,
params: { protocolVersion: '2024-11-05', capabilities: {} }
})
});
const initResult = await initResponse.json();
console.log('Initialized:', initResult);
// List tools
const toolsResponse = await fetch('http://localhost:7988/mcp', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'MCP-Protocol-Version': '2024-11-05'
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'tools/list',
id: 2
})
});
const tools = await toolsResponse.json();
console.log('Available tools:', tools.result.tools.length);
}
## 📋 Tool Examples
### Get Users
```bash
curl -X POST http://localhost:7988/tools/call \
-H "Content-Type: application/json" \
-d '{
"tool": "get_users",
"arguments": {
"limit": 2,
"role": "admin"
}
}'
创建用户
curl -X POST http://localhost:7988/tools/call \
-H "Content-Type: application/json" \
-d '{
"tool": "create_user",
"arguments": {
"name": "Alice Johnson",
"email": "alice@example.com",
"role": "user"
}
}'
分析情绪
curl -X POST http://localhost:7988/tools/call \
-H "Content-Type: application/json" \
-d '{
"tool": "analyze_sentiment",
"arguments": {
"text": "This MCP server is absolutely amazing!"
}
}'
📡 实时流媒体
MCP模拟服务器包括全面的基于WebSocket的流媒体功能,用于测试实时应用程序。
WebSocket连接
const ws = new WebSocket('ws://localhost:7988/stream');
ws.onopen = () => {
console.log('Connected to MCP Mock Server streaming');
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received:', data);
};
可用流类型
🧑💻 用户活动流
ws.send(JSON.stringify({
type: 'start_stream',
streamType: 'user_activity',
config: { interval: 1000 }
}));
提供:用户登录、页面浏览、点击、购买等。
📊 分析流
ws.send(JSON.stringify({
type: 'start_stream',
streamType: 'analytics',
config: { interval: 5000 }
}));
提供:活跃用户、页面浏览量、收入、服务器指标
💬 聊天模拟
ws.send(JSON.stringify({
type: 'start_stream',
streamType: 'chat_simulation',
config: { interval: 7988, channel: 'general' }
}));
提供:来自模拟用户的真实聊天消息
🌡️ 传感器数据
ws.send(JSON.stringify({
type: 'start_stream',
streamType: 'sensor_data',
config: { interval: 1000 }
}));
提供:温度、湿度、压力、运动、电池电量
📋 日志事件
ws.send(JSON.stringify({
type: 'start_stream',
streamType: 'log_events',
config: { interval: 2000 }
}));
提供:来自不同级别的各种服务的系统日志
📈 股票价格
ws.send(JSON.stringify({
type: 'start_stream',
streamType: 'stock_prices',
config: { interval: 1500 }
}));
提供:主要交易品种的实时股价更新
流媒体命令
// Start a stream
ws.send(JSON.stringify({
type: 'start_stream',
streamType: 'user_activity',
config: { interval: 1000 }
}));
// Stop a stream
ws.send(JSON.stringify({
type: 'stop_stream',
streamId: 'stream-id-here'
}));
// Subscribe to broadcasts
ws.send(JSON.stringify({
type: 'subscribe',
stream: 'notifications'
}));
// Ping/Pong
ws.send(JSON.stringify({ type: 'ping' }));
使用命令行进行测试
安装websocate以方便WebSocket测试:
# Install websocat
cargo install websocat
# Connect and test
websocat ws://localhost:7988/stream
# Send commands interactively
{"type": "start_stream", "streamType": "user_activity"}
Python示例
import websocket
import json
def on_message(ws, message):
data = json.loads(message)
print(f"Received: {data}")
def on_open(ws):
# Start multiple streams
ws.send(json.dumps({
'type': 'start_stream',
'streamType': 'analytics',
'config': {'interval': 2000}
}))
ws = websocket.WebSocketApp('ws://localhost:7988/stream',
on_open=on_open,
on_message=on_message)
ws.run_forever()
⚙️ 配置选项
mcp-mock-server [options]
Options:
-p, --port <port> Port to run server on (default: 7988)
-h, --host <host> Host to bind to (default: localhost)
-l, --log-level <level> Logging level (default: info)
-c, --config <file> Configuration file path
-d, --data <file> Custom mock data file
--no-colors Disable colored output
--quiet Suppress non-essential output
📊 模拟数据结构
服务器包括全面的模拟数据:
{
"users": [
{
"id": 1,
"name": "John Doe",
"email": "john.doe@example.com",
"role": "admin",
"avatar": "https://api.dicebear.com/7.x/avataaars/svg?seed=John",
"createdAt": "2024-01-15T08:30:00Z",
"preferences": {
"theme": "dark",
"notifications": true
}
}
],
"posts": [...],
"products": [...],
"analytics": {...}
}
🔍 日志记录
Winston支持多级和传输的日志记录:
- 控制台:用于开发的彩色输出
- 文件:结构化JSON登录
logs/目录 - 错误:单独的错误日志文件
- 异常:未经处理的异常
日志级别: error, warn, info, debug
🚀 发展
# Clone repository
git clone https://github.com/anuragarwalkar/ai-mcp-server.git
cd ai-mcp-server
# Install dependencies
npm install
# Start in development mode
npm run dev
# Start normally
npm start
📚 MCP协议合规性
此服务器实现 MCP流式HTTP传输 规范(2024-11-05):
✅ 已实现的功能
- JSON-RPC 2.0 -使用正确的消息格式完成实施
- 可流式HTTP传输 -MCP官方传输协议
- 服务器发送事件(SSE) -实时服务器到客户端通信
- 协议版本协商 -支持多个MCP版本
- CORS支持 -增强web客户端的CORS标头
- 会话管理 -可选会话ID支持
- 工具发现 -通过动态工具列表
tools/list - 工具执行 -通过调用工具
tools/call通过适当的错误处理 - 内容类型协商 -支持JSON和SSE响应
- 正确的错误处理 -JSON-RPC错误代码和消息
🔌 运输方式
- POST请求 -用于向服务器发送JSON-RPC消息
- GET请求 -用于从服务器打开SSE流
- 选项请求 -用于CORS飞行前处理
- 删除请求 -用于会话终止
📋 支持的MCP方法
initialize-初始化MCP连接并协商功能tools/list-列出所有具有模式的可用工具tools/call-执行带有参数验证的工具
🏗️ 建筑
Client (Postman, Claude, etc.)
↓ POST /mcp (JSON-RPC)
↓ GET /mcp (SSE stream)
MCP Mock Server
↓ Tool execution
↓ Mock data generation
Response (JSON-RPC 2.0)
此实现与以下内容完全兼容:
- ✅ 邮递员MCP客户端
- ✅ 克劳德桌面 (配置正确)
- ✅ 自定义MCP客户端 遵循规范
- ✅ MCP SDK集成
🤝 贡献
欢迎投稿!请随时提交拉取请求。
📄 许可证
MIT许可证-有关详细信息,请参阅许可证文件。
🙏 致谢
- 模型上下文协议 规格和团队
- 邮递员 用于MCP客户端集成
- Winston结构化日志库
- Commander.js用于漂亮的CLI界面
- 用于彩色控制台输出的粉笔
- 用于实时流媒体的WebSocket(ws)库
- Express.js对HTTP路由模式的启发
🔗 与项目连接:
由以下材料制成❤️ 靠近 阿努拉格Arwalkar
