# AIMock — Mock LLM, MCP, A2A, Vector APIs > AIMock is a mock server for AI app testing: it simulates LLM providers, MCP tools, A2A agents, and vector/search APIs so tests avoid real paid endpoints. ## Install Save as a script file and run: ## Quick Use 1. Install / set up: ```bash npm install @copilotkit/aimock ``` 2. Start / smoke test: ```bash npx -p @copilotkit/aimock llmock -p 4010 -f ./fixtures ``` 3. Verify: - Set `OPENAI_BASE_URL=http://127.0.0.1:4010/v1` and confirm your app/test hits the mock server (no real API calls). ## Intro AIMock is a mock server for AI app testing: it simulates LLM providers, MCP tools, A2A agents, and vector/search APIs so tests avoid real paid endpoints. - **Best for:** teams writing agent tests who need deterministic fixtures, record/replay, and one-port mocks - **Works with:** Node.js projects, test runners (Jest/Vitest), OpenAI-compatible SDKs via `OPENAI_BASE_URL` - **Setup time:** 10 minutes ## Practical Notes - Mocks many surfaces from one port (LLM APIs, MCP, A2A, vector/search/rerank, etc.) - Supports 12 LLM providers (per project docs) and streaming behaviors for realistic tests - GitHub stars/forks (verified): see Source & Thanks AIMock pays for itself the first time you avoid a flaky test or a surprise token bill. Use it in three steps: 1. Start `llmock` (fixtures-first) or the full suite via `--config`. 2. Point your SDK to the mock by setting `OPENAI_BASE_URL` (and a dummy key if the SDK requires it). 3. Record real traces once (optional), then replay deterministically in CI forever. Two good guardrails: - Keep fixtures in version control and review them like code. - Add a CI check that fails if your tests accidentally talk to real endpoints (base URL not patched). ### FAQ **Q: What does it mock?** A: LLM APIs plus agent protocols like MCP/A2A and common infra like vector DBs, search, and rerank. **Q: Can it record real responses?** A: Yes — it supports record & replay so you can capture and replay fixtures deterministically. **Q: How do I adopt it safely?** A: Patch base URLs via env vars in tests and add a CI guard to prevent real endpoint calls. ## Source & Thanks > Source: https://github.com/CopilotKit/aimock > License: MIT > GitHub stars: 581 · forks: 37 --- ## 快速使用 1. 安装 / 设置: ```bash npm install @copilotkit/aimock ``` 2. 启动 / 冒烟测试: ```bash npx -p @copilotkit/aimock llmock -p 4010 -f ./fixtures ``` 3. 验证: - 设置 `OPENAI_BASE_URL=http://127.0.0.1:4010/v1`,确认应用/测试请求命中 mock(没有真实 API 调用)。 ## 简介 AIMock 是一个用于 AI 应用测试的“一站式 mock 服务器”:可模拟 LLM provider、MCP 工具、A2A agent、向量/搜索 API 等,让测试不再直连真实付费端点并降低波动与费用。 - **适合谁:** 需要可复现 fixture、record/replay、并希望一端口统一 mock 的 Agent 测试团队 - **可搭配:** Node.js 项目、Jest/Vitest 等测试框架、通过 `OPENAI_BASE_URL` 对接 OpenAI 兼容 SDK - **准备时间:** 10 分钟 ## 实战建议 - 一个端口即可 mock 多类能力(LLM API、MCP、A2A、向量/搜索/重排等) - 官方文档列出 12 个 LLM provider 支持,并可模拟 streaming 行为 - GitHub stars / forks(已核验):见「来源与感谢」 AIMock 的收益非常直接:一次避免 flaky 测试或“意外烧 token”就值回票价。 建议按三步使用: 1. 先用 `llmock`(fixture 驱动)或用 `--config` 跑全套 mock。 2. 通过 `OPENAI_BASE_URL` 把 SDK 指向 mock(某些 SDK 仍需要一个占位 key)。 3. 需要时先录一次真实 trace,之后在 CI 里长期稳定回放。 两个实践护栏: - fixture 进版本库,像代码一样审查。 - CI 加断言:如果测试误连真实端点(base URL 没 patch)就直接失败。 ### FAQ **它能 mock 哪些东西?** 答:LLM API + MCP/A2A 等协议,以及向量库/搜索/重排等常见基础设施。 **能录制真实响应吗?** 答:可以,支持 record & replay,把真实响应保存为可复现 fixture。 **怎么安全接入?** 答:测试里用环境变量 patch base URL,并在 CI 加护栏防止误连真实端点。 ## 来源与感谢 > Source: https://github.com/CopilotKit/aimock > License: MIT > GitHub stars: 581 · forks: 37 --- Source: https://tokrepo.com/en/workflows/aimock-mock-llm-mcp-a2a-vector-apis Author: Script Depot