@cocaxcode/api-testing-mcp
The most complete MCP server for API testing. Period.
42 MCP tools · Zero config · Works in any MCP client
Overview · Just Talk to It · Installation · Features · Tool Reference · Storage · Architecture
______________________________________________________________________
快速概览
最完整的 MCP服务器 对于API测试-42个工具,零配置,其他一切都无法接近。这不仅仅是一个请求发送者。它是一个完整的测试工作台:带断言的HTTP请求、带变量提取的多步流、带模式感知模拟数据的OpenAPI导入、带百分位数指标的负载测试、跨环境的响应差异、批量测试运行器、可重用集合、带目录范围和持久默认值的环境组、Postman导入/导出和cURL导出。一切都来自自然对话。没有帐户,没有云,没有生成的文件。所有内容都以内联方式运行,并存储为您拥有的纯JSON。
______________________________________________________________________
只需与它对话
您不需要学习工具名称或参数。描述你想要什么,人工智能会选择合适的工具。
"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 mcp add --scope user api-testing -- npx -y @cocaxcode/api-testing-mcp@latest克劳德桌面版
添加到配置文件(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上, %APPDATA%\Claude\claude_desktop_config.json 在Windows上):
{
"mcpServers": {
"api-testing": {
"command": "npx",
"args": ["-y", "@cocaxcode/api-testing-mcp@latest"]
}
}
}光标/风帆
添加 .cursor/mcp.json 或 .windsurf/mcp.json 在项目根目录中:
{
"mcpServers": {
"api-testing": {
"command": "npx",
"args": ["-y", "@cocaxcode/api-testing-mcp@latest"]
}
}
}VS Code / Codex CLI / Gemini CLI
VS代码 --添加到 .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"通过以下方式进行验证: *“列出我的环境”* --你应该看到你刚刚创建的那个。
______________________________________________________________________
特性
HTTP请求
发送任何带有标头、查询参数、JSON正文、auth和 {{variable}} 插值。相对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-承载器/API密钥/基本身份验证-自定义超时。
压缩模式(v0.13+)
AI代理为进入其上下文窗口的每个字节付费。默认情况下, request 现在返回一个压缩的响应,在不丢失调试值的情况下减少70-95%的令牌。三个可选参数控制它:
| 参数 | 值 | 它的作用 |
|---|---|---|
verbosity | 'minimal' / 'normal' (默认)/ 'full' | 控制详细程度 |
only_fields | ['user.id', 'items[*].name'] | 仅返回这些正文路径(点符号+通配符) |
max_body_bytes | 数字(默认值 2048) | 车身尺寸帽 'normal' |
模式:
minimal--只有status,timing,size_bytes,身体的前200个字符。非常适合健康检查、轮询循环或即发即弃呼叫。 *节省约95%的代币。*normal*(默认)* --过滤集管(液滴Date,Server,CF-*,Set-Cookie等)+主体截断为max_body_bytes涵盖了约80%的调试用例。 *节省约75%的代币。*full--完整的响应未受影响。当您明确需要每个标头或整个正文时使用。
5KB JSON响应的典型节省 (≈1500个代币):
| 模式 | 消耗代币 | 节省 |
|---|---|---|
full | ~1500 | 0%(基线) |
normal | ~300-400 | ~75% |
minimal | ~50-80 | ~95% |
only_fields: ['data.id'] | ~30 | ~98% |
进行直接比较curl,WebFetch以及其他具有测量数字的本地替代方案,请参阅 本地替代品 在......下面
恢复完整响应: 每个压缩响应都包括 call_id。如果你以后需要全身检查,请致电 inspect_last_response({ call_id }) --无需重新执行请求。这适用于 request, assert,每一步 flow_run。响应保存在20个槽的环形缓冲区中,并持久化到 .api-testing/last-responses/ TTL为1小时。
// Example: normal (default) response
{
"call_id": "k3m9a2xp",
"status": 200,
"statusText": "OK",
"method": "GET",
"url": "https://api.example.com/users/1",
"timing": { "total_ms": 142 },
"size_bytes": 5324,
"headers": { "content-type": "application/json" },
"body": { "id": 1, "email": "...", "...": "..." },
"body_truncated": true,
"hint": "Body truncated to 2048 bytes (full size: 5324B). Call inspect_last_response({ call_id: \"k3m9a2xp\" }) for the full body.",
"tokens_saved_estimate": 820
}原生替代方案:真实代币成本
此MCP与Claude Code在以下情况下的本机选项相比如何 api-testing 不可用(Bash+curl、WebFetch等)。
太长,读不下去了:与生相比 curl, request 节省之间 65%和97% 取决于模式的上下文令牌,而不会丢失调试信息。通过实际通话进行测量 GET /api/v1/blog 返回8个帖子(约8.7KB的JSON,19个响应头):
|代理人如何称呼它|使用MCP?|消耗的代币|Delta与curl| |---|:-:|---|---| | Bash + curl (原始标准输出)|❌ 本地|~2170|基线| | WebFetch (法学硕士摘要)|❌ 原生|~400-800|-65%,但无身份验证/无envs/无检查| | request 冗长=full | ✅ MCP|~2170|0%(与卷曲相同,无压缩)| | request 冗长=normal *(默认)* | ✅ MCP| ~750 | −65% | | request 冗长=minimal | ✅ MCP|~50| −97% | | request 和 only_fields: ["data[*].id","data[*].title"] | ✅ MCP |约190| −91% |
为什么这个表的数字与上面的“压缩模式”部分略有不同:这些来自单个真实世界的响应,而上一个表显示了合成5KB响应的典型节省。趋势和数量级是相同的。
笔记:
- 默认模式(
normal)无需任何配置即可节省65%:它过滤掉嘈杂的标头(Date、Server、CF-\*、Set Cookie…),并将正文限制在2048字节。 only_fields接受具有数组索引和通配符支持的点路径(items[*].name)--只返回您要求的字段。- MCP还添加了没有直接本地等效功能的功能:
{{variable}}插值、存储环境、身份验证模式、流、Postman导入/导出,以及inspect_last_response在不重新连接服务器的情况下恢复全身。 - 每个注册的MCP每个会话都会增加约300-600个令牌的固定开销(其指令块+工具名称)。典型的盈亏平衡:每次通话1-2次。
断言
使用结构化的通过/失败结果验证响应:
"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
What the tool executes
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密钥-并通过上下文将它们分隔开。该系统有三个核心概念:
**集团。** 组组织环境并将其绑定到目录。一个组有N个共享其环境的作用域(目录),以及一个默认环境。当您在组内创建环境时,它属于该组。当你 `cd` 进入一个组范围内的目录,其环境会自动可用。
**违约。** 当您输入其组的范围时,默认环境会自动激活。它在会话之间持续存在——重新启动编辑器,重新打开终端,默认值仍然存在。设置一次,然后忘记它。
**活跃。** 活动环境是目前用于可变分辨率的环境。当您输入作用域时,它将作为默认值开始,但您可以随时切换它。活动选择仅限于会话,在重新启动时重置为默认值。
全局环境(不与任何组关联)仍然存在。它们需要明确激活 `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" Import details
收藏: Postman v2.1格式。文件夹变成标签。从文件夹/集合级别继承的身份验证。支持原始JSON、x-www-form-urlencoded、表单数据体。
环境: 较喜欢 currentValue 结束 value.跳过禁用的变量。可选的 activate 旗帜。
Export details
收藏: 按标签分组到文件夹中的请求。Auth映射到Postman的原生格式。 {{variables}} 保持原样。
环境: 所有变量导出为 enabled: true 采用Postman兼容格式。
本地进出口
将集合和环境导出到便携式 .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"}'______________________________________________________________________
工具参考
10个类别的42个工具:
| 类别 | 工具 | 计数 |
|---|---|---|
| 请求: | request | 1 |
| 检查 | inspect_last_response | 1 |
| 测试 | assert | 1 |
| 流动 | flow_run | 1 |
| 集合 | collection_save, collection_list, collection_get, collection_delete | 4 |
| 环境 | env_create, env_list, env_set, env_get, env_switch, env_rename, env_delete, env_spec, env_project_clear, env_project_list | 10 |
| 群组 | env_group_create, env_group_list, env_group_delete, env_group_add_scope, env_group_remove_scope, env_set_default, env_set_group | 7 |
| API规范 | api_import, api_spec_list, api_endpoints, api_endpoint_detail | 4 |
| 模拟 | mock | 1 |
| 公用事业 | load_test, export_curl, diff_responses, bulk_test, export_collection, import_collection, export_environment, import_environment, export_postman_collection, import_postman_collection, export_postman_environment, import_postman_environment | 12 |
提示: 你不需要直接调用工具。描述你想要什么,人工智能会选择正确的一个。
______________________________________________________________________
存储
一切都是本地的。没有数据库,没有云同步,没有遥测。所有数据都存在于 ~/.api-testing/ 作为纯JSON文件,您可以随时读取、备份或删除。
~/.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 request (1)
│ ├── inspect.ts # inspect_last_response (1)
│ ├── assert.ts # Assertions (1)
│ ├── flow.ts # Request chaining (1)
│ ├── collection.ts # Collection CRUD (4)
│ ├── environment.ts # Environments + groups (17)
│ ├── 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 (11)
├── lib/ # Business logic (no MCP dependency)
│ ├── http-client.ts # fetch wrapper with timing
│ ├── storage.ts # JSON file storage engine (atomic writes)
│ ├── compress.ts # Response compression + verbosity modes
│ ├── response-cache.ts # Ring buffer + disk cache for inspect
│ ├── schemas.ts # Shared Zod schemas (HttpMethodSchema, AuthSchema)
│ ├── 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, 171 tests堆栈: TypeScript(严格)·MCP SDK·Zod·Vitest·tsup
______________________________________________________________________
