api-tester-liqi
v1.0.0
Published
MCP Server for API testing with health checks, database validation, and Postman integration
Maintainers
Readme
@liqi_511/api-tester
基于 Model Context Protocol (MCP) 的 API 测试工具,支持连通性检查、数据库验证和 Postman 集成。
特性
- 🚀 开箱即用 - 零配置启动
- 🔧 高度可配置 - 支持多服务配置
- 📮 Postman 集成 - 自动导入请求历史
- 🗄️ 数据库验证 - 直连数据库验证数据
- ⚡ 批量测试 - 一键运行测试用例
- 🧪 Newman 支持 - CLI 自动化测试
安装
npm install -g @liqi_511/api-tester快速入门
👉 新手入门指南 - 5分钟快速上手
文档目录
| 文档 | 说明 | |------|------| | 新手入门 | 快速上手指南 | | API 参考 | 所有 MCP 工具详细参数 | | 开发指南 | 开发贡献指南 |
快速开始
1. 配置你的服务
创建 config/services.json:
{
"my-service": {
"name": "my-service",
"host": "localhost",
"port": 3000,
"baseUrl": "http://localhost:3000",
"db": {
"host": "localhost",
"port": 3306,
"user": "root",
"password": "your_password",
"database": "your_db",
"dialect": "mysql"
}
}
}2. 设置环境变量(可选)
# Postman API Key(用于自动导入)
export POSTMAN_API_KEY="your-postman-api-key"
# 自定义配置路径
export SERVICES_CONFIG_PATH="./my-services.json"3. 启动 MCP Server
api-tester或在 Claude Code 中配置 settings.json:
{
"mcpServers": {
"api-tester": {
"command": "api-tester"
}
}
}MCP 工具
| 工具 | 描述 | Postman |
|------|------|---------|
| http_request | 发送 HTTP 请求 | autoImportPostman |
| health_check | 检查服务连通性 | - |
| run_api_test | 执行批量测试用例 | ✓ |
| db_query | 查询/验证数据库 | - |
| assert_response | 断言响应 | - |
| run_with_newman | Newman CLI 运行 | - |
使用示例
http_request
{
"tool": "http_request",
"service": "my-service",
"method": "POST",
"path": "/api/users",
"body": { "name": "test", "age": 20 },
"autoImportPostman": true
}run_api_test
{
"tool": "run_api_test",
"service": "my-service",
"testCases": [
{ "name": "获取列表", "method": "GET", "path": "/api/users", "expected": { "errno": 0 } },
{ "name": "创建用户", "method": "POST", "path": "/api/users", "body": { "name": "test" }, "expected": { "errno": 0 } }
]
}db_query
{
"tool": "db_query",
"service": "my-service",
"table": "users",
"operation": "select",
"where": { "id": 1 }
}CLI 选项
api-tester --help # 显示帮助
api-tester --list # 列出已配置的服务
api-tester --config ./my-config.json # 指定配置文件项目结构
@liqi_511/api-tester/
├── bin/
│ └── mcp-api-tester.js # CLI 入口
├── lib/
│ ├── index.js # 主入口
│ ├── config/
│ │ └── services.js # 配置加载器
│ └── tools/
│ ├── http.js # HTTP 请求
│ ├── health.js # 健康检查
│ ├── test.js # 批量测试
│ ├── db.js # 数据库
│ ├── assert.js # 断言
│ ├── newman.js # Newman
│ └── postman-api.js # Postman API
├── config/
│ ├── services.json # 默认配置
│ └── services.example.json # 示例配置
└── README.md发布到 npm
# 登录 npm
npm login
# 发布
npm publish
# 发布 beta 版本
npm publish --tag betaLicense
MIT
