API Testing MCP
概览
这是最完整的 MCP 服务器 用于 API 测试 — 42 个工具,零配置,无可比拟。这不仅仅是一个请求发送器,它是一个完整的测试工作台:包含断言的 HTTP 请求、带变量提取的多步流程、支持模式感知模拟数据的 OpenAPI 导入、带百分位指标的负载测试、跨环境响应差异对比、批量测试运行器、可重用集合、带目录作用域和持久化默认值的环境组、Postman 导入/导出以及 cURL 导出。一切皆可通过自然语言对话完成。无需账户,无需云端,无需生成文件。所有内容均在本地运行,并以你拥有的纯 JSON 格式存储。
直接对话
你无需学习工具名称或参数。只需描述你的需求,AI 就会选择合适的工具。
"Create a group called my-project and add this directory as scope"
"Set up a dev environment with BASE_URL http://localhost:3000"
"Switch to prod for this session"
"Set dev as the default environment"
"Import my API spec from /api-docs-json"
"Show me all user endpoints"
"GET /users"
"Create a user with random data"
"Verify that DELETE /users/5 returns 204"
"Login as admin, extract the token, then fetch dashboard stats"
"How fast is /health with 50 concurrent requests?"
"Run all my saved smoke tests"
"Compare the users endpoint between dev and prod"
"Export the create-user request as curl"
"Export my collection to Postman"如果你已经导入了 OpenAPI 规范,AI 就已经了解了每一个端点、每一个必填字段以及每一个有效的枚举值。当你说“创建一个博客文章”时,它会读取模式并正确构建请求 — 无需猜测。
安装
Claude Code
claude mcp add --scope user api-testing -- npx -y @cocaxcode/api-testing-mcp@latestClaude Desktop
添加到你的配置文件中(macOS 上为 ~/Library/Application Support/Claude/claude_desktop_config.json,Windows 上为 %APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"api-testing": {
"command": "npx",
"args": ["-y", "@cocaxcode/api-testing-mcp@latest"]
}
}
}Cursor / Windsurf
添加到项目根目录的 .cursor/mcp.json 或 .windsurf/mcp.json 中:
{
"mcpServers": {
"api-testing": {
"command": "npx",
"args": ["-y", "@cocaxcode/api-testing-mcp@latest"]
}
}
}VS Code — 添加到 .vscode/mcp.json:
{
"servers": {
"api-testing": {
"command": "npx",
"args": ["-y", "@cocaxcode/api-testing-mcp@latest"]
}
}
}Codex CLI (OpenAI):
codex mcp add api-testing -- npx -y @cocaxcode/api-testing-mcp@latest或者添加到 ~/.codex/config.toml:
[mcp_servers.api-testing]
command = "npx"
args = ["-y", "@cocaxcode/api-testing-mcp@latest"]Gemini CLI — 添加到 ~/.gemini/settings.json:
{
"mcpServers": {
"api-testing": {
"command": "npx",
"args": ["-y", "@cocaxcode/api-testing-mcp@latest"]
}
}
}快速开始
安装完成后,设置一个环境以便相对路径自动解析:
"Create an environment called dev with BASE_URL http://localhost:3000"如果你的 API 有 Swagger/OpenAPI 规范,请导入它:
"Import my API spec from http://localhost:3000/api-docs-json"通过以下命令验证:"List my environments"(列出我的环境)— 你应该能看到刚刚创建的环境。
功能
HTTP 请求
发送带有标头、查询参数、JSON 正文、身份验证和 {{variable}} 插值的任何 HTTP 方法。相对 URL 会自动针对 BASE_URL 进行解析。
"POST to /api/users with name Jane and email jane@company.com using my bearer token"支持:GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS — Bearer / API Key / Basic 认证 — 自定义超时。
断言
使用结构化的通过/失败结果验证响应:
"Verify that GET /api/health returns 200, body.status is ok, and responds in under 500ms"PASS — 3/3 assertions passed
status === 200
body.status === "ok"
timing.total_ms < 50010 个运算符:eq, neq, gt, gte, lt, lte, contains, not_contains, exists, type
请求流程
通过步骤间的变量提取来链接请求。非常适合身份验证流程和 CRUD 序列。
"Login as admin@test.com, extract the access token, then use it to fetch all users"flow_run({
steps: [
{
name: "login",
method: "POST",
url: "/auth/login",
body: { email: "admin@test.com", password: "SecurePass#99" },
extract: { "TOKEN": "body.access_token" }
},
{
name: "get-users",
method: "GET",
url: "/api/users",
headers: { "Authorization": "Bearer {{TOKEN}}" }
}
]
})OpenAPI 导入
从 URL 或本地文件(JSON 和 YAML)导入规范。导入后,AI 将了解每一个端点、参数和模式。
"Import my API spec from http://localhost:3000/api-docs-json"
"Import the spec from ./openapi.yaml"
"What parameters does POST /users expect?"支持 OpenAPI 3.x,具有完整的 $ref 解析、allOf、oneOf、anyOf。部分支持 OpenAPI 2.0。
模拟数据生成
根据你的 OpenAPI 模式生成逼真的虚假数据。遵循类型、格式(email, uuid, date-time)、枚举和必填字段。
"Generate mock data for creating a user"{
"email": "user42@example.com",
"name": "Test User 73",
"password": "TestPass123!",
"role": "admin"
}负载测试
触发 N 个并发请求并获取性能指标:
"How fast is the health endpoint with 50 concurrent requests?"LOAD TEST — GET /api/health
Requests: 50 concurrent
Successful: 50 | Failed: 0
Req/sec: 23.31
Min: 45ms | Avg: 187ms
p50: 156ms | p95: 412ms | p99: 523ms
Max: 567ms响应差异对比
执行两个请求并逐字段比较它们的响应。检测回归或比较环境。
"Compare the users endpoint between dev and prod"批量测试
运行集合中的每个已保存请求(或按标签过滤)并获取摘要:
"Run all my saved smoke tests"BULK TEST — 8/8 passed | 1.2s total
health — GET /health → 200 (45ms)
list-users — GET /users → 200 (123ms)
create-post — POST /blog → 201 (89ms)
login — POST /auth/login → 200 (156ms)集合
保存请求以便通过标签重用。构建回归测试套件。
"Save this request as create-user with tags auth, smoke"
"List all requests tagged smoke"环境
环境保存你的变量 — BASE_URL、令牌、API 密钥 — 并按上下文隔离它们。系统有三个核心概念:
组 (Group)。 组用于组织环境并将其绑定到目录。一个组拥有 N 个作用域(目录),它们共享该组的环境,并且恰好有一个默认环境。当你在组内创建环境时,它就属于该组。当你 cd 进入作为组作用域的目录时,其环境会自动变为可用。
默认 (Default)。 当你进入其组的作用域时,默认环境会自动激活。它在会话间持久存在 — 重启编辑器、重新打开终端,默认环境依然存在。设置一次即可。
活动 (Active)。 活动环境是当前用于变量解析的环境。当你进入作用域时,它默认为默认环境,但你可以随时切换。活动选择仅限当前会话 — 重启后会重置为默认环境。
全局环境(不与任何组关联)依然存在。它们需要通过 env_switch 显式激活,且不会在会话间持久存在。
实际示例:
"Create a group called my-api"
"Add this directory as scope to my-api"
"Create a dev environment with BASE_URL http://localhost:3000" <- auto-joins group, auto-default
"Create a prod environment with BASE_URL https://api.example.com"
"List environments" <- shows dev (active, default) and prod
"Switch to prod" <- session only
"Set prod as default" <- persists自动插值。 URL、标头、查询参数或请求正文中的任何 {{variable}} 都会在请求触发前针对活动环境进行解析。设置一次 BASE_URL,每个相对路径都能正常工作。
你的凭据永远不会离开你的机器。 环境文件是存储在 ~/.api-testing/ 中的纯 JSON。没有任何内容同步到云端。没有任何内容嵌入到导出文件中。没有任何内容被 git 跟踪。你的令牌和密钥保留在它们应该在的地方:你的磁盘上,由你控制。
Postman 导入与导出
双向 Postman 支持。在 Postman 和你的 AI 工作流之间无缝迁移。
"Import my Postman collection from ./exported.postman_collection.json"
"Export my collection to Postman"
"Export the dev environment for Postman"集合: Postman v2.1 格式。文件夹变为标签。身份验证继承自文件夹/集合级别。支持原始 JSON、x-www-form-urlencoded、form-data 正文。
环境: 优先使用 currentValue 而非 value。跳过禁用的变量。可选的 activate 标志。
集合: 请求按标签分组在文件夹中。身份验证映射到 Postman 的原生格式。{{variables}} 按原样保留。
环境: 所有变量以 Postman 兼容格式导出为 enabled: true。
原生导出与导入
将集合和环境导出到可移植的 .atm/ 文件夹。与团队共享或在项目间复制。
"Export my collection and dev environment"your-project/
└── .atm/
├── collection.json
└── dev.env.json注意:
.atm/在首次导出时会自动添加到.gitignore中。
cURL 导出
将任何已保存的请求转换为带有已解析变量的、可直接粘贴的 cURL 命令。
"Export the create-user request as curl"curl -X POST \
'https://api.example.com/users' \
-H 'Authorization: Bearer eyJhbGci...' \
-H 'Content-Type: application/json' \
-d '{"name":"Jane","email":"jane@company.com"}'工具参考
9 个类别中的 42 个工具:
类别 | 工具 | 数量 |
请求 |
| 1 |
测试 |
| 1 |
流程 |
| 1 |
集合 |
| 4 |
环境 |
| 8 |
组 |
| 7 |
API 规范 |
| 4 |
模拟 |
| 1 |
实用工具 |
| 12 |
提示: 你无需直接调用工具。描述你的需求,AI 会选择合适的工具。
存储
一切都在本地。没有数据库,没有云同步,没有遥测。所有数据都以纯 JSON 文件的形式存储在 ~/.api-testing/ 中,你可以随时读取、备份或删除。
~/.api-testing/
├── groups/ # Environment groups with scopes and defaults
├── environments/ # Environment variables — tokens, keys, passwords
├── collections/ # Saved requests (shareable, no secrets)
├── specs/ # Imported OpenAPI specs
└── project-envs.json # Session-only active environments (cleared on restart)全局存储与项目导出。 ~/.api-testing/ 目录是你的私有全局存储 — 这是凭据所在的地方,它们永远不会离开这里。当你导出集合或环境时,它会进入项目根目录的 .atm/。该文件夹在首次导出时会自动添加到 .gitignore,但即使你选择提交它,你的凭据也会保留在 ~/.api-testing/ 中,永远不会被复制到 .atm/。你可以安全地与团队共享 .atm/ 导出,而不会泄露密钥。
覆盖默认存储路径:
{
"env": { "API_TESTING_DIR": "/path/to/custom/.api-testing" }
}警告: 如果你将
API_TESTING_DIR覆盖为 git 仓库内的路径,请将.api-testing/添加到你的.gitignore以避免推送凭据。
架构
src/
├── index.ts # Entry point (shebang + StdioServerTransport)
├── server.ts # createServer() factory
├── tools/ # 42 tool handlers (one file per category)
│ ├── request.ts # HTTP requests (1)
│ ├── assert.ts # Assertions (1)
│ ├── flow.ts # Request chaining (1)
│ ├── collection.ts # Collection CRUD (4)
│ ├── environment.ts # Environment management (8)
│ ├── group.ts # Environment groups (7)
│ ├── api-spec.ts # OpenAPI import/browse (4)
│ ├── mock.ts # Mock data generation (1)
│ ├── load-test.ts # Load testing (1)
│ └── utilities.ts # curl, diff, bulk, import/export (12)
├── lib/ # Business logic (no MCP dependency)
│ ├── http-client.ts # fetch wrapper with timing
│ ├── storage.ts # JSON file storage engine
│ ├── schemas.ts # Shared Zod schemas
│ ├── url.ts # BASE_URL resolution
│ ├── path.ts # Dot-notation accessor (body.data.0.id)
│ ├── interpolation.ts # {{variable}} resolver
│ └── openapi-parser.ts # $ref + allOf/oneOf/anyOf resolution
└── __tests__/ # 10+ test suites, 120+ tests技术栈: TypeScript (严格模式) · MCP SDK · Zod · Vitest · tsup
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/cocaxcode/api-testing-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server