使用说明
MCP测试服务器
模型上下文协议(MCP)服务器,用于本地测试API端点、web浏览器和电话UI。
特性
API测试
- 发出HTTP请求(GET、POST、PUT、DELETE、PATCH)
- 批量API测试
- 自定义标头、正文和查询参数
- 响应验证
Web浏览器测试
- 导航到URL
- 点击元素
- 在输入字段中键入
- 截图
- 提取文本内容
- 等待元素
- 支持多个选项卡/页面
手机用户界面测试
- 带有设备预设的移动浏览器模拟
- 点击互动
- 滑动手势
- 移动视口截图
- 设备特定测试(iPhone、三星等)
设置
先决条件
- Python 3.8或更高版本
- pip(Python包管理器)
安装
- 导航到mcp服务器目录:
cd mcp-server
- 创建虚拟环境(推荐):
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- 安装依赖项:
pip install -r requirements.txt
- 安装Playwright浏览器:
playwright install chromium
运行服务器
方法1:直接执行Python
python server.py
方法2:使用启动脚本
chmod +x start.sh
./start.sh
方法3:作为MCP服务器(适用于Cursor/Claude桌面)
添加到MCP配置文件(通常 ~/.cursor/mcp.json 或类似):
{
"mcpServers": {
"testing-server": {
"command": "python",
"args": ["/absolute/path/to/mcp-server/server.py"],
"env": {}
}
}
}
使用示例
API测试
测试GET请求:
{
"tool": "api_test_request",
"arguments": {
"url": "https://api.example.com/users",
"method": "GET",
"headers": {
"Authorization": "Bearer token"
}
}
}
测试POST请求:
{
"tool": "api_test_request",
"arguments": {
"url": "https://api.example.com/users",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": {
"name": "John Doe",
"email": "john@example.com"
}
}
}
Web浏览器测试
导航到URL:
{
"tool": "browser_navigate",
"arguments": {
"url": "https://example.com",
"page_id": "main"
}
}
单击元素:
{
"tool": "browser_click",
"arguments": {
"selector": "button#submit",
"page_id": "main"
}
}
截图:
{
"tool": "browser_screenshot",
"arguments": {
"page_id": "main",
"full_page": true,
"path": "./screenshot.png"
}
}
手机用户界面测试
在手机上导航:
{
"tool": "phone_navigate",
"arguments": {
"url": "https://example.com",
"device": "iPhone 12",
"page_id": "mobile_test"
}
}
点击一个元素:
{
"tool": "phone_tap",
"arguments": {
"selector": "button.login",
"page_id": "mobile_test"
}
}
滑动:
{
"tool": "phone_swipe",
"arguments": {
"direction": "up",
"distance": 300,
"page_id": "mobile_test"
}
}
可用设备预设
- iPhone 12
- iPhone 13
- iPhone 13 Pro
- iPhone 14
- 三星Galaxy S21
- 三星Galaxy S20
- 像素5
- iPad Pro
- 更多(见剧作家设备列表)
故障排除
浏览器无法启动
- 确保安装了Playwright浏览器:
playwright install chromium - 检查您是否有必要的系统依赖关系
导入错误
- 确保安装了所有依赖项:
pip install -r requirements.txt - 验证Python版本是否为3.8+
端口冲突
- 服务器使用stdio进行通信,因此不需要端口
- 如果浏览器实例冲突,请关闭现有浏览器窗口
备注
- 默认情况下,服务器以非无头模式运行(浏览器可见)
- 通过以下方式支持多个页面/选项卡
page_id参数 - 截图可以保存到磁盘或以base64格式返回
- 所有浏览器实例都是自动管理的
许可证
这是一个用于本地开发的测试工具。
