Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
- Fixture and server `misbehavior` configuration, `LLMock.setMisbehavior()` / `clearMisbehavior()`, seeded rates, and per-test firing limits. Runtime overrides use `GET` / `POST` / `DELETE /__aimock/misbehavior`; `GET /__aimock/misbehavior/catalog` lists faults and wire support.
- Optional journal `response.misbehavior` evidence, including served tool calls for applied faults, and the `aimock_misbehavior_total` metric. Journal consumers must allow the new optional field.
- Add opt-in AWS Bedrock K5/K9 contract comparisons for Invoke and Converse; retain explicit modeled K9 non-trigger reporting.
- Record live MCP servers into `mcpFakes` files and replay them offline: `--mcp-record <mount>=<url>` and `--mcp-proxy-only <mount>=<url>` on the `llmock` bin and Docker image, `llm.record.mcp` for `aimock --config`, and `MCPMock.enableRecording()` / `disableRecording()`.
- Recording settings `AIMOCK_RECORD_SECRET_VALUES` and `AIMOCK_MCP_UPSTREAM_AUTH`. Recordings never contain headers, redact known secrets, and are not written while a secret remains.
- `mcpFakes` accepts the recorded keys `list`, `recorded` and `timing` (block) and `notifications` and `durationMs` (call entry). Older aimock versions reject files with these keys.
- In MCP record mode, a mount forwards every path and method, forwards fake misses to the upstream, and does not answer from its registered tools.
- A replayed MCP tool call with recorded notifications can be answered as SSE, with progress notifications at the recorded timing (scaled by `--replay-speed`).
- An MCP mount holding recorded log notifications advertises `logging` and answers `logging/setLevel`.
- Per-test MCP fake report: `GET /__aimock/mcp/fakes/report`.
- Vitest and Jest plugins: `useAimock({ fakesReport: "warn" | "fail" })` checks each test's fake report in `afterEach`; handle methods `fakesFor()` and `fakesReport()`, with a per-test default test id; Jest option `testIdRoot`.
- New exports `assertFakesReport`, `AimockFakesReportError` and `AimockTestIdCollisionError`.
- aimock-pytest: `fakes_for`, `fakes_report` and `assert_fakes_report`.

### Changed

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ WORKDIR /app
RUN apk add --no-cache git

COPY --from=build /app/dist/ dist/
# package.json sits above dist/ so aimockVersion() reports the real version
COPY --from=build /app/package.json ./
COPY fixtures/ fixtures/

EXPOSE 4010
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Run them all on one port with `npx @copilotkit/aimock --config aimock.json`, or
- **OpenAI platform APIs** — [Files](https://aimock.copilotkit.dev/files) (byte-exact uploads, purpose validation), [Vector Stores](https://aimock.copilotkit.dev/vector-stores) (CRUD, file attach with deterministic poll progression, file batches, deterministic direct search; hosted `file_search` execution is not supported), [fine-tuning jobs](https://aimock.copilotkit.dev/fine-tuning) (deterministic lifecycle, events, cursor pages) and Batches (`/v1/batches` create/list/retrieve/cancel with deterministic poll progression and real output files)
- **[MCP](https://aimock.copilotkit.dev/mcp-mock) / [A2A](https://aimock.copilotkit.dev/a2a-mock) / [AG-UI](https://aimock.copilotkit.dev/agui-mock) / [Vector](https://aimock.copilotkit.dev/vector-mock)** — Mock every protocol your AI agents use
- **[MCP Scenario Fakes](https://aimock.copilotkit.dev/mcp-mock#scenario-fakes)** — An `mcpFakes` block in a fixture file scripts each test's MCP tool answers next to its LLM turns: ordered answers, exact or any-argument matching, scripted tool errors, and a closed-world mode that fails on any undeclared tool. Works with any MCP client over Streamable HTTP
- **[MCP Recording](https://aimock.copilotkit.dev/record-replay#mcp-recording)** — Record a live MCP server into `mcpFakes` files (`--mcp-record /mcp=<url>`, or `llm.record.mcp` in a config) and replay them offline, with the recorded tool list, progress notifications and timing; known secrets are redacted before anything is written
- **[MCP Fake Reports](https://aimock.copilotkit.dev/mcp-mock#fakes-report)** — `GET /__aimock/mcp/fakes/report` lists each test's served, unused and failed fakes; with `useAimock({ fakesReport: "fail" })` a swallowed fake error or an unused fake fails the test, and `fakesFor()` gives the MCP URL and headers for the current test. Works for agents, workflows and pipelines alike
- **[Chaos Testing](https://aimock.copilotkit.dev/chaos-testing)** — 500 errors, malformed JSON, mid-stream disconnects and 429 rate limits (`--chaos-ratelimit`, with `Retry-After`) at any probability, plus a fixed pre-handling delay (`--chaos-latency <ms>`); read, set and clear the rates at runtime via `GET` / `POST` / `DELETE /__aimock/chaos`, scoped to the caller's `X-Test-Id` so one test cannot destabilise the suite running beside it
- **[Model Misbehavior](https://aimock.copilotkit.dev/model-misbehavior)** — Test invalid tool arguments, schema violations, unknown tools, duplicate IDs, length stops, empty responses, refusals, content filtering, and reasoning-only responses. Supported wires include OpenAI Chat, Responses, Realtime GA, Anthropic, Bedrock InvokeModel and Converse, Gemini generateContent (including the Vertex wrapper), Gemini Live, Gemini Interactions, Cohere, and Ollama chat. Fault and mode support varies by wire. Azure and OpenRouter use the Chat wire. Seeded rates, per-test limits, and journal evidence apply across supported wires. See the reference for the support matrix, SDK behavior, and modeled contracts whose native occurrence remains unverified.
- **Request journal** — `GET /__aimock/journal` returns every recorded request, filterable by `path`, `method`, `status`, `service`, `testId` and `requestId` with `limit` / `offset` paging and an `X-Total-Count` header carrying the pre-pagination total
Expand Down
111 changes: 111 additions & 0 deletions docs/aimock-cli/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,100 @@ <h3>Recording Config (<code>llm.record</code>)</h3>
}</code></pre>
</div>

<h3 id="mcp-record-config">Recording MCP servers (<code>llm.record.mcp</code>)</h3>
<p>
<code>llm.record.mcp</code> maps an MCP mount path to an upstream MCP server URL, or to an
object with more options. Each mount records that server into <code>mcpFakes</code> files;
see <a href="/record-replay#mcp-recording">Recording MCP servers</a>. A mount path that
the config already serves with an MCP mock (<code>mcp.path</code>) records through that
mount. A free path gets a new MCP mock. A path held by another kind of mock fails at
start. <code>llm.record.mcp</code> alone does not turn on LLM recording: that needs
<code>llm.record.providers</code>.
</p>
<div class="code-block" data-sample="inline:mcp-record-config">
<div class="code-block-header">aimock.json <span class="lang-tag">json</span></div>
<pre><code>{
<span class="prop">"llm"</span>: {
<span class="prop">"fixtures"</span>: <span class="str">"./fixtures"</span>,
<span class="prop">"record"</span>: {
<span class="prop">"mcp"</span>: {
<span class="prop">"/mcp"</span>: <span class="str">"http://localhost:3001/mcp"</span>,
<span class="prop">"/search"</span>: { <span class="prop">"upstream"</span>: <span class="str">"http://localhost:3002/mcp"</span>, <span class="prop">"proxyOnly"</span>: <span class="kw">true</span> }
}
}
}
}</code></pre>
</div>
<table class="endpoint-table">
<thead>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>upstream</code></td>
<td>string</td>
<td>&mdash; (required)</td>
<td>
The upstream MCP endpoint URL. A string value is the same as
<code>{ "upstream": url }</code>
</td>
</tr>
<tr>
<td><code>fixturePath</code></td>
<td>string</td>
<td>
<code>llm.record.fixturePath</code>, else <code>&lt;llm.fixtures&gt;/recorded</code>
</td>
<td>
Where recordings are written. One of the three is required unless
<code>proxyOnly</code>
</td>
</tr>
<tr>
<td><code>proxyOnly</code></td>
<td>boolean</td>
<td><code>false</code></td>
<td>Forward without writing anything</td>
</tr>
<tr>
<td><code>upstreamAuth</code></td>
<td>string</td>
<td><code>AIMOCK_MCP_UPSTREAM_AUTH</code></td>
<td>A <code>"Name: value"</code> header set on every forwarded request</td>
</tr>
<tr>
<td><code>secretValues</code></td>
<td>string[]</td>
<td><code>AIMOCK_RECORD_SECRET_VALUES</code></td>
<td>Values to redact from recordings, each at least 8 characters</td>
</tr>
<tr>
<td><code>strict</code></td>
<td>boolean</td>
<td>the config&rsquo;s <code>strict</code></td>
<td>A fake miss gets the replay error instead of being forwarded</td>
</tr>
<tr>
<td><code>maxRecordBufferBytes</code></td>
<td>number</td>
<td>64 MiB (at most 256 MiB)</td>
<td>The largest response that is recorded; a larger one is forwarded only</td>
</tr>
</tbody>
</table>
<p>
A value on the mount wins over the shared value, and the shared value over the
environment. The environment variables are the same on both bins:
<code>AIMOCK_RECORD_SECRET_VALUES</code> (newline-separated) and
<code>AIMOCK_MCP_UPSTREAM_AUTH</code> (<code>Name: value</code>). A bad value of either
fails at start.
</p>

<h2>CLI Flags</h2>
<table class="endpoint-table">
<thead>
Expand Down Expand Up @@ -393,6 +487,17 @@ <h2>CLI Flags</h2>
>Error: --port requires a non-empty value.</code
>), not a silently absent one.
</p>
<p>
These are all the flags of the <code>aimock</code> bin. Recording flags, including
<code>--record</code>, <code>--mcp-record &lt;mount&gt;=&lt;url&gt;</code> and
<code>--mcp-proxy-only &lt;mount&gt;=&lt;url&gt;</code>, are on the flag-driven
<code>llmock</code> bin (<code>npx -p @copilotkit/aimock llmock</code>), which is also the
Docker image&rsquo;s entry point. See
<a href="/record-replay#mcp-recording">Recording MCP servers</a>. With
<code>aimock --config</code>, record through
<a href="#mcp-record-config"><code>llm.record.mcp</code></a
>.
</p>

<h2>Single-Port Routing</h2>
<p>
Expand Down Expand Up @@ -652,6 +757,12 @@ <h3 id="validate-mcp-fakes">MCP fakes</h3>
zero-fixture rule. The <code>OK</code> line of a file with fakes counts its blocks, for
example <code>account/read-only.json: OK (0 fixture(s), 1 mcpFakes block(s))</code>.
</p>
<p>
A <a href="/mcp-mock#recorded-fakes">recorded file</a> is checked with the same rules,
plus the <code>record-replay/fa-*</code> rules for its recorded keys. Each entry of its
top-level <code>_warnings</code> (a redacted secret, or a string that looks like a token)
is printed as a warning.
</p>

<h3>The <code>--json</code> Report</h3>
<p>
Expand Down
70 changes: 67 additions & 3 deletions docs/control-api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ <h2>Route Overview</h2>
The MCP fakes that apply to a test id and context, with each entry&rsquo;s state
</td>
</tr>
<tr>
<td><code>GET</code></td>
<td>
<code>/__aimock/mcp/fakes/<wbr />report</code>
</td>
<td>The per-test MCP fake report: served, unused and failed fakes for a test id</td>
</tr>
<tr>
<td><code>POST</code></td>
<td><code>/__aimock/reset</code></td>
Expand Down Expand Up @@ -502,8 +509,8 @@ <h3>DELETE /__aimock/fixtures</h3>
<h3 id="mcp-fakes">GET /__aimock/mcp/fakes</h3>
<p>
Read-only: for each MCP mount, the <code>mcpFakes</code> blocks that apply to a test id
and context, with every entry&rsquo;s id and whether it is used for that test id. Use it
at the end of a test to check that every declared fake was used. Query parameters:
and context, with every entry&rsquo;s id and whether it is used for that test id. To check
a test at its end, use the <a href="#mcp-fakes-report">report</a> below. Query parameters:
<code>testId</code>, <code>context</code> and <code>mount</code> (a mount path; default:
all MCP mounts), all optional. An empty value counts as not sent. Any other query
parameter is rejected with <code>400</code>, and a <code>mount</code> with no MCP mock
Expand Down Expand Up @@ -564,11 +571,68 @@ <h3 id="mcp-fakes">GET /__aimock/mcp/fakes</h3>
}</code></pre>
</div>

<h3 id="mcp-fakes-report">GET /__aimock/mcp/fakes/report</h3>
<p>
Read-only: the <a href="/mcp-mock#fakes-report">report</a> for one test id and context,
across every MCP mount. Query parameters: <code>testId</code> and <code>context</code>,
both optional; an empty value counts as not sent. Any other query parameter is rejected
with <code>400</code>. Otherwise the answer is <code>200</code> with
<code
>{ "testId", "context", "ok", "evicted", "served", "unconsumed", "unfaked", "failures",
"sharedUnconsumed" }</code
>. Reading it changes no state.
</p>
<p>
After one <code>create_ticket</code> call in the test
<code>tickets › retry on timeout</code> (the
<a href="/mcp-mock#scenario-fakes"><code>tickets/retry.json</code></a> sample), the first
entry is served and the second is unused, so <code>ok</code> is <code>false</code>:
</p>
<div class="code-block" data-sample="inline:fakes-report-curl">
<div class="code-block-header">
Read the fakes report <span class="lang-tag">shell</span>
</div>
<pre><code>curl <span class="str">"http://localhost:4010/__aimock/mcp/fakes/report?testId=tickets%20%E2%80%BA%20retry%20on%20timeout"</span></code></pre>
</div>
<div class="code-block" data-sample="inline:fakes-report-response">
<div class="code-block-header">Response <span class="lang-tag">json</span></div>
<pre><code>{
<span class="prop">"testId"</span>: <span class="str">"tickets › retry on timeout"</span>,
<span class="prop">"context"</span>: <span class="kw">null</span>,
<span class="prop">"ok"</span>: <span class="kw">false</span>,
<span class="prop">"evicted"</span>: <span class="kw">false</span>,
<span class="prop">"served"</span>: [
{
<span class="prop">"entryId"</span>: <span class="str">"tickets/retry.json:first-try"</span>,
<span class="prop">"mount"</span>: <span class="str">"/mcp"</span>,
<span class="prop">"tool"</span>: <span class="str">"create_ticket"</span>,
<span class="prop">"args"</span>: {
<span class="prop">"title"</span>: <span class="str">"Refund"</span>
}
}
],
<span class="prop">"unconsumed"</span>: [
{
<span class="prop">"entryId"</span>: <span class="str">"tickets/retry.json:retry"</span>,
<span class="prop">"mount"</span>: <span class="str">"/mcp"</span>,
<span class="prop">"tool"</span>: <span class="str">"create_ticket"</span>,
<span class="prop">"args"</span>: {
<span class="prop">"title"</span>: <span class="str">"Refund"</span>
}
}
],
<span class="prop">"unfaked"</span>: [],
<span class="prop">"failures"</span>: [],
<span class="prop">"sharedUnconsumed"</span>: []
}</code></pre>
</div>

<h3 id="reset-effects-on-mcp-fakes">Reset effects on MCP fakes</h3>
<p>
<code>POST /__aimock/reset</code>, its deprecated alias
<code>POST /__aimock/reset/fixtures</code>, and
<code>DELETE /__aimock/fixtures</code> unload every MCP fake along with the LLM fixtures.
<code>DELETE /__aimock/fixtures</code> unload every MCP fake along with the LLM fixtures,
and clear the fakes report&rsquo;s event log.
<code>POST /__aimock/reset/journal</code>
leaves fakes and their state as they are. None of them closes MCP sessions.
</p>
Expand Down
9 changes: 9 additions & 0 deletions docs/fixtures/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ <h2>File Format</h2>
<code>fixtures</code>, <code>mcpFakes</code>, or both. See
<a href="/mcp-mock#scenario-fakes">MCPMock: Scenario fakes</a>.
</p>
<p>
<a href="/record-replay#mcp-recording">MCP recording</a> writes
<code>mcpFakes</code> files with five more optional keys: <code>list</code>,
<code>recorded</code> and <code>timing</code> on a block, and
<code>notifications</code> and <code>durationMs</code> on a call entry. A recorded file
also has a top-level <code>_warnings</code> array, which the loader ignores. These keys
need aimock 1.45.0 or later; see
<a href="/mcp-mock#recorded-fakes">MCPMock: Recorded fakes</a>.
</p>

<h2>Match Fields</h2>

Expand Down
Loading
Loading