whistle-mcp
Enables AI to manage whistle mock rules, values, and inspect network sessions, facilitating API mocking and debugging through natural language.
README
whistle-mcp
MCP (Model Context Protocol) Server for whistle - 让 AI 直接操作 whistle 的 Mock 数据。
安装
# 全局安装(推荐)
npm install -g whistle-mcp
# 或直接用 npx,无需安装
npx whistle-mcp
配置
方式一:Cursor
编辑 Cursor 的 MCP 配置文件(~/.cursor/mcp.json):
{
"mcpServers": {
"whistle": {
"command": "npx",
"args": ["-y", "whistle-mcp"],
"env": {
"WHISTLE_BASE_URL": "http://127.0.0.1:8899",
"WHISTLE_USERNAME": "",
"WHISTLE_PASSWORD": ""
}
}
}
}
全局安装后也可以写成:
{
"mcpServers": {
"whistle": {
"command": "whistle-mcp",
"env": {
"WHISTLE_BASE_URL": "http://127.0.0.1:8899"
}
}
}
}
方式二:Claude Desktop
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) 或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"whistle": {
"command": "npx",
"args": ["-y", "whistle-mcp"],
"env": {
"WHISTLE_BASE_URL": "http://127.0.0.1:8899",
"WHISTLE_USERNAME": "",
"WHISTLE_PASSWORD": ""
}
}
}
}
如果 whistle 启用了鉴权(
w2 start -u admin -p 123456),请填写WHISTLE_USERNAME和WHISTLE_PASSWORD。
方式三:其他 MCP 客户端
任何支持 stdio 传输的 MCP 客户端都可以使用:
WHISTLE_BASE_URL=http://127.0.0.1:8899 \
WHISTLE_USERNAME=admin \
WHISTLE_PASSWORD=123456 \
npx -y whistle-mcp
功能
规则管理
whistle_rule_list- 获取所有规则列表whistle_rule_get- 获取规则内容whistle_rule_set- 创建/更新规则whistle_rule_remove- 删除规则whistle_rule_enable/whistle_rule_disable- 启用/禁用规则
Values 管理
whistle_value_list- 获取所有 Valueswhistle_value_get- 获取 Value 内容whistle_value_set- 创建/更新 Valuewhistle_value_remove- 删除 Value
Mock 工作流
whistle_mock_create- 一键创建完整 Mock 方案(规则 + Values)whistle_mock_apply- 启用/禁用 Mock 规则
抓包数据查看
whistle_sessions_list- 获取最近抓包的 session 列表,可按 URL / HTTP 方法过滤whistle_session_get- 获取单个请求的完整详情,自动解析 Query 参数、POST 参数和响应 JSON 字段树whistle_sessions_search- 按请求参数名(query/POST body)或响应 JSON 字段名搜索抓包,例如"哪些请求带了 token 参数"、"哪些接口返回了 address 字段"
系统状态
whistle_status- 检查 whistle 服务状态whistle_server_info- 获取服务器信息
环境变量
| 变量 | 默认值 | 说明 |
|---|---|---|
WHISTLE_BASE_URL |
自动探测 | whistle Web UI 地址。不设置时会自动读取 ~/.startingAppData/ 状态文件探测运行中的实例 |
WHISTLE_USERNAME |
`` | whistle 鉴权用户名(可选) |
WHISTLE_PASSWORD |
`` | whistle 鉴权密码(可选) |
端口自动探测
MCP Server 启动时会自动检测运行中的 whistle 实例(不管用什么端口启动),优先级:
- 环境变量
WHISTLE_BASE_URL(显式指定,最高优先级) - whistle 状态文件
~/.startingAppData/(自动探测) - 默认
http://127.0.0.1:8899(fallback)
所以即使你 w2 start -p 8888 用别的端口启动,也能自动识别,无需改配置。
使用示例
1. 创建 Mock 接口
AI 指令:
帮我创建一个 Mock,当请求
api.example.com/user/info时返回用户数据
AI 会调用:
{
"tool": "whistle_mock_create",
"arguments": {
"pattern": "api.example.com/user/info",
"response": {
"code": 200,
"data": {
"id": 12345,
"name": "张三",
"email": "zhangsan@example.com"
}
},
"statusCode": 200,
"delay": 100
}
}
2. 管理规则
AI 指令:
列出所有 whistle 规则
AI 会调用:
{
"tool": "whistle_rule_list"
}
3. 更新 Mock 数据
AI 指令:
把用户 Mock 数据里的邮箱改成 lisi@example.com
AI 会调用:
{
"tool": "whistle_value_set",
"arguments": {
"name": "mock_value_1234567890",
"content": "{\"statusCode\":200,\"headers\":{\"Content-Type\":\"application/json\"},\"body\":{\"code\":200,\"data\":{\"id\":12345,\"name\":\"张三\",\"email\":\"lisi@example.com\"}}}"
}
}
4. 查看抓包数据
AI 指令:
帮我看看最近有没有抓到 api.vip.com 的请求
AI 会调用:
{
"tool": "whistle_sessions_list",
"arguments": {
"urlFilter": "api.vip.com",
"count": 10
}
}
AI 指令:
查看最后一个请求的完整响应数据
AI 会调用:
{
"tool": "whistle_session_get",
"arguments": {
"id": "abc123-def456"
}
}
5. 按参数/字段搜索抓包
AI 指令:
查一下最近有没有请求带了 userId 参数
AI 会调用:
{
"tool": "whistle_sessions_search",
"arguments": {
"param": "userId",
"count": 50
}
}
AI 指令:
看看最近 POST 到 api.vip.com 的接口,返回的数据里有没有 address 字段
AI 会调用:
{
"tool": "whistle_sessions_search",
"arguments": {
"urlFilter": "api.vip.com",
"method": "POST",
"field": "address",
"count": 50
}
}
前置条件
-
whistle 已安装并运行:
npm i -g whistle w2 start -
确认 whistle Web UI 可访问:
curl http://127.0.0.1:8899/cgi-bin/status
架构
┌─────────────┐ MCP (stdio) ┌──────────────────┐ HTTP ┌─────────────┐
│ AI Client │ ◄──────────────────► │ whistle-mcp-server│ ◄─────────────► │ whistle │
│ (Claude/ │ │ (Node.js) │ │ (127.0.0.1 │
│ Cursor) │ │ │ │ :8899) │
└─────────────┘ └──────────────────┘ └─────────────┘
│
▼
┌─────────────┐
│ ~/.whistle/ │
│ rules/ │
│ values/ │
└─────────────┘
开发
本地测试
# 启动 whistle
w2 start
# 启动 MCP Server(开发模式)
npm run dev
# 测试 MCP 协议
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | node src/index.js
调试
查看 whistle Web UI 的 CGI 接口:
# 规则列表
curl http://127.0.0.1:8899/cgi-bin/rules/list
# Values 列表
curl http://127.0.0.1:8899/cgi-bin/values/list
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。