mock-mcp 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -128
- package/dist/adapter/index.cjs +712 -0
- package/dist/adapter/index.d.cts +55 -0
- package/dist/adapter/index.d.ts +55 -0
- package/dist/adapter/index.js +672 -0
- package/dist/client/connect.cjs +913 -0
- package/dist/client/connect.d.cts +211 -0
- package/dist/client/connect.d.ts +209 -6
- package/dist/client/connect.js +867 -10
- package/dist/client/index.cjs +914 -0
- package/dist/client/index.d.cts +4 -0
- package/dist/client/index.d.ts +4 -2
- package/dist/client/index.js +873 -2
- package/dist/daemon/index.cjs +667 -0
- package/dist/daemon/index.d.cts +62 -0
- package/dist/daemon/index.d.ts +62 -0
- package/dist/daemon/index.js +628 -0
- package/dist/discovery-Dc2LdF8q.d.cts +105 -0
- package/dist/discovery-Dc2LdF8q.d.ts +105 -0
- package/dist/index.cjs +2238 -0
- package/dist/index.d.cts +472 -0
- package/dist/index.d.ts +472 -10
- package/dist/index.js +2185 -53
- package/dist/protocol-CiwaQFOt.d.ts +239 -0
- package/dist/protocol-xZu-wb0n.d.cts +239 -0
- package/dist/shared/index.cjs +386 -0
- package/dist/shared/index.d.cts +4 -0
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared/index.js +310 -0
- package/dist/types-BKREdsyr.d.cts +32 -0
- package/dist/types-BKREdsyr.d.ts +32 -0
- package/package.json +44 -4
- package/dist/client/batch-mock-collector.d.ts +0 -87
- package/dist/client/batch-mock-collector.js +0 -223
- package/dist/client/util.d.ts +0 -1
- package/dist/client/util.js +0 -3
- package/dist/connect.cjs +0 -299
- package/dist/connect.d.cts +0 -95
- package/dist/server/index.d.ts +0 -1
- package/dist/server/index.js +0 -1
- package/dist/server/test-mock-mcp-server.d.ts +0 -73
- package/dist/server/test-mock-mcp-server.js +0 -392
- package/dist/types.d.ts +0 -42
- package/dist/types.js +0 -2
package/README.md
CHANGED
|
@@ -4,17 +4,19 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/mock-mcp)
|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
Mock MCP Server - AI-generated mock data based on your **OpenAPI JSON Schema** definitions. The project
|
|
7
|
+
Mock MCP Server - AI-generated mock data based on your **OpenAPI JSON Schema** definitions. The project uses a **Daemon + Adapter** architecture that enables multiple MCP clients (Cursor, Claude Desktop, etc.) to run simultaneously without port conflicts, while providing robust claim-based concurrency control for mock batch processing.
|
|
8
8
|
|
|
9
9
|
## Table of Contents
|
|
10
10
|
|
|
11
11
|
- [Quick Start](#quick-start)
|
|
12
12
|
- [Why Mock MCP](#why-mock-mcp)
|
|
13
13
|
- [What Mock MCP Does](#what-mock-mcp-does)
|
|
14
|
+
- [Architecture](#architecture)
|
|
14
15
|
- [Configure MCP Server](#configure-mcp-server)
|
|
15
16
|
- [Connect From Tests](#connect-from-tests)
|
|
16
17
|
- [Describe Requests with Metadata](#describe-requests-with-metadata)
|
|
17
|
-
- [MCP
|
|
18
|
+
- [MCP Tools](#mcp-tools)
|
|
19
|
+
- [CLI Commands](#cli-commands)
|
|
18
20
|
- [Available APIs](#available-apis)
|
|
19
21
|
- [Environment Variables](#environment-variables)
|
|
20
22
|
- [How It Works](#how-it-works)
|
|
@@ -33,17 +35,21 @@ yarn add -D mock-mcp
|
|
|
33
35
|
pnpm add -D mock-mcp
|
|
34
36
|
```
|
|
35
37
|
|
|
36
|
-
2. **Configure the Model Context Protocol server.**
|
|
38
|
+
2. **Configure the Model Context Protocol server.** Add mock-mcp to your MCP client configuration (Cursor, Claude Desktop, etc.):
|
|
37
39
|
|
|
38
40
|
```json
|
|
39
41
|
{
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
42
|
+
"mcpServers": {
|
|
43
|
+
"mock-mcp": {
|
|
44
|
+
"command": "npx",
|
|
45
|
+
"args": ["-y", "mock-mcp", "adapter"]
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
```
|
|
46
50
|
|
|
51
|
+
> **Note:** The `adapter` command connects to a shared daemon process that is automatically started when needed. This eliminates port conflicts when running multiple MCP clients simultaneously.
|
|
52
|
+
|
|
47
53
|
3. **Connect from your tests.** Use `connect` to retrieve a mock client and request data for intercepted calls.
|
|
48
54
|
|
|
49
55
|
```ts
|
|
@@ -70,9 +76,10 @@ it("example", async () => {
|
|
|
70
76
|
instructions: "Respond with a single user described by the schema.",
|
|
71
77
|
};
|
|
72
78
|
|
|
73
|
-
fetchMock.get("/user", () =>
|
|
74
|
-
mockClient.requestMock("/user", "GET", { metadata }) // add mock via mock-mcp
|
|
75
|
-
|
|
79
|
+
fetchMock.get("/user", async () => {
|
|
80
|
+
const response = await mockClient.requestMock("/user", "GET", { metadata }) // add mock via mock-mcp
|
|
81
|
+
return response.data
|
|
82
|
+
});
|
|
76
83
|
|
|
77
84
|
const result = await fetch("/user");
|
|
78
85
|
const data = await result.json();
|
|
@@ -131,59 +138,81 @@ Unlike "hallucinated" mocks, Mock MCP uses your actual **OpenAPI JSON Schema** d
|
|
|
131
138
|
|
|
132
139
|
## What Mock MCP Does
|
|
133
140
|
|
|
134
|
-
Mock MCP
|
|
141
|
+
Mock MCP uses a **Daemon + Adapter** architecture to move intercepted requests from tests to AI helpers and back again.
|
|
135
142
|
|
|
136
143
|
- **Schema-aware generation** uses your provided metadata (OpenAPI JSON Schema) to ensure mocks match production behavior.
|
|
137
144
|
- **Batch-aware test client** collects every network interception inside a single macrotask and waits for the full response set.
|
|
138
|
-
- **
|
|
139
|
-
- **
|
|
145
|
+
- **Claim-based concurrency** prevents multiple AI clients from racing on the same batch through lease-based locking.
|
|
146
|
+
- **Multi-run isolation** supports concurrent test processes with distinct run IDs.
|
|
147
|
+
- **IPC-based communication** uses Unix Domain Sockets (macOS/Linux) or Named Pipes (Windows) instead of TCP ports, eliminating port conflicts.
|
|
140
148
|
- **Timeouts, TTLs, and cleanup** guard the test runner from stale batches or disconnected clients.
|
|
141
149
|
|
|
142
|
-
##
|
|
150
|
+
## Architecture
|
|
143
151
|
|
|
144
|
-
|
|
152
|
+
The v0.4.0 release introduces a new **Daemon + Adapter** architecture that fundamentally solves the "multiple MCP clients" problem:
|
|
145
153
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
154
|
+
```
|
|
155
|
+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
|
156
|
+
│ Test Process │ │ Daemon │ │ Adapter │
|
|
157
|
+
│ (your tests) │────▶│ (per-project) │◀────│ (per MCP client)│
|
|
158
|
+
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
|
159
|
+
│ │ │
|
|
160
|
+
│ WebSocket/IPC │ JSON-RPC/IPC │ MCP stdio
|
|
161
|
+
│ │ │
|
|
162
|
+
▼ ▼ ▼
|
|
163
|
+
BatchMockCollector Mock Bridge Daemon MCP Tools
|
|
164
|
+
- Auto-discovers - Manages runs/batches - claim_next_batch
|
|
165
|
+
- Sends batches - Claim/lease control - provide_batch_mock_data
|
|
166
|
+
- Receives mocks - Multi-client safe - get_status, list_runs
|
|
167
|
+
```
|
|
150
168
|
|
|
151
|
-
|
|
169
|
+
**Key Benefits:**
|
|
152
170
|
|
|
153
|
-
|
|
171
|
+
- Single daemon per project (no per-client server instances)
|
|
172
|
+
- IPC communication
|
|
173
|
+
- Full multi-client support
|
|
174
|
+
- Claim-based concurrency (no race conditions)
|
|
175
|
+
- Auto-discovery (no manual configuration)
|
|
176
|
+
|
|
177
|
+
## Configure MCP Server
|
|
178
|
+
|
|
179
|
+
Add mock-mcp to your MCP client configuration. The adapter automatically discovers or starts the daemon for your project:
|
|
154
180
|
|
|
155
181
|
```json
|
|
156
182
|
{
|
|
157
183
|
"mcpServers": {
|
|
158
184
|
"mock-mcp": {
|
|
159
185
|
"command": "npx",
|
|
160
|
-
"args": ["-y", "mock-mcp
|
|
161
|
-
"env": {
|
|
162
|
-
"MCP_SERVER_PORT": "3002" // 3002 is the default port
|
|
163
|
-
}
|
|
186
|
+
"args": ["-y", "mock-mcp", "adapter"]
|
|
164
187
|
}
|
|
165
188
|
}
|
|
166
189
|
}
|
|
167
190
|
```
|
|
168
191
|
|
|
169
|
-
|
|
192
|
+
**That's it!** The daemon uses IPC (Unix Domain Sockets on macOS/Linux, Named Pipes on Windows) which:
|
|
193
|
+
|
|
194
|
+
- Eliminates port conflicts between multiple MCP clients
|
|
195
|
+
- Automatically shares state between all adapters in the same project
|
|
196
|
+
- Requires no manual coordination or environment variables
|
|
197
|
+
|
|
198
|
+
Restart your MCP client and confirm that the `mock-mcp` server exposes the tools (`get_status`, `claim_next_batch`, `provide_batch_mock_data`, etc.).
|
|
170
199
|
|
|
171
200
|
## Connect From Tests
|
|
172
201
|
|
|
173
|
-
Tests call `connect` to spin up a `BatchMockCollector
|
|
202
|
+
Tests call `connect` to spin up a `BatchMockCollector` that automatically discovers and connects to the daemon:
|
|
174
203
|
|
|
175
204
|
```ts
|
|
176
205
|
// tests/mocks.ts
|
|
177
206
|
import { connect } from "mock-mcp";
|
|
178
207
|
|
|
208
|
+
// Auto-discovers daemon via IPC
|
|
179
209
|
const mockClient = await connect({
|
|
180
|
-
port: 3002,
|
|
181
210
|
timeout: 60000,
|
|
182
211
|
});
|
|
183
212
|
|
|
184
213
|
await page.route("**/api/users", async (route) => {
|
|
185
214
|
const url = new URL(route.request().url());
|
|
186
|
-
const data = await mockClient.requestMock(
|
|
215
|
+
const { data } = await mockClient.requestMock(
|
|
187
216
|
url.pathname,
|
|
188
217
|
route.request().method()
|
|
189
218
|
);
|
|
@@ -206,6 +235,8 @@ await mockClient.waitForPendingRequests();
|
|
|
206
235
|
// Safe to assert on the results produced by the mocked responses
|
|
207
236
|
```
|
|
208
237
|
|
|
238
|
+
**Multiple test processes** can run concurrently - each gets a unique `runId` and their batches are isolated from each other.
|
|
239
|
+
|
|
209
240
|
## Describe Requests with Metadata
|
|
210
241
|
|
|
211
242
|
`requestMock` accepts an optional third argument (`RequestMockOptions`) that is forwarded without modification to the MCP server. The most important field in that object is `metadata`, which lets the test process describe each request with the exact OpenAPI JSON Schema fragment, sample payloads, or test context that the AI client needs to build a response.
|
|
@@ -249,144 +280,202 @@ await mockClient.requestMock("/api/products", "GET", {
|
|
|
249
280
|
- Keep the metadata JSON-serializable and deterministic; large binary blobs or class instances will be dropped.
|
|
250
281
|
- Reuse helper functions to centralize schema definitions so each test only supplies the endpoint-specific instructions.
|
|
251
282
|
|
|
252
|
-
## MCP
|
|
283
|
+
## MCP Tools
|
|
284
|
+
|
|
285
|
+
The new architecture provides a richer set of tools with claim-based concurrency control:
|
|
253
286
|
|
|
254
|
-
|
|
287
|
+
| Tool | Purpose | Input |
|
|
288
|
+
| ------------------------- | ----------------------------------------------- | ------------------------------------------ |
|
|
289
|
+
| `get_status` | Get daemon status (runs, pending, claimed) | None |
|
|
290
|
+
| `list_runs` | List all active test runs | None |
|
|
291
|
+
| `claim_next_batch` | Claim the next pending batch (with lease) | `{ runId?, leaseMs? }` |
|
|
292
|
+
| `get_batch` | Get details of a specific batch (read-only) | `{ batchId }` |
|
|
293
|
+
| `provide_batch_mock_data` | Provide mock data for a claimed batch | `{ batchId, claimToken, mocks }` |
|
|
294
|
+
| `release_batch` | Release a claimed batch without providing mocks | `{ batchId, claimToken, reason? }` |
|
|
255
295
|
|
|
256
|
-
|
|
257
|
-
| ------------------------- | ------------------------------------------ | ------------------------------------------------------- |
|
|
258
|
-
| `get_pending_batches` | Lists queued batches with request metadata | JSON string (array of `{batchId, timestamp, requests}`) |
|
|
259
|
-
| `provide_batch_mock_data` | Sends mock payloads for a specific batch | JSON string reporting success |
|
|
296
|
+
### Workflow
|
|
260
297
|
|
|
261
|
-
|
|
298
|
+
The new workflow uses **claim → provide** to prevent race conditions:
|
|
299
|
+
|
|
300
|
+
1. **Claim a batch** - Call `claim_next_batch` to acquire a lease on a pending batch
|
|
301
|
+
2. **Receive batch details** - Get `batchId`, `claimToken`, and `requests` array
|
|
302
|
+
3. **Generate mocks** - Create mock responses for each request
|
|
303
|
+
4. **Provide mocks** - Call `provide_batch_mock_data` with the claim token
|
|
262
304
|
|
|
263
305
|
```jsonc
|
|
306
|
+
// Step 1: Claim
|
|
264
307
|
{
|
|
265
|
-
"
|
|
266
|
-
"
|
|
267
|
-
{
|
|
268
|
-
"requestId": "req-7",
|
|
269
|
-
"data": { "users": [{ "id": 1, "name": "Alice" }] }
|
|
270
|
-
}
|
|
271
|
-
]
|
|
308
|
+
"name": "claim_next_batch",
|
|
309
|
+
"arguments": { "leaseMs": 30000 }
|
|
272
310
|
}
|
|
311
|
+
// Returns: { "batchId": "batch:abc:1", "claimToken": "xyz", "requests": [...] }
|
|
312
|
+
|
|
313
|
+
// Step 2: Provide
|
|
314
|
+
{
|
|
315
|
+
"name": "provide_batch_mock_data",
|
|
316
|
+
"arguments": {
|
|
317
|
+
"batchId": "batch:abc:1",
|
|
318
|
+
"claimToken": "xyz",
|
|
319
|
+
"mocks": [
|
|
320
|
+
{ "requestId": "req-1", "data": { "id": 1, "name": "Alice" } }
|
|
321
|
+
]
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**Lease expiration**: If you don't provide mocks within the lease time (default 30s), the batch is automatically released for another adapter to claim.
|
|
327
|
+
|
|
328
|
+
## CLI Commands
|
|
329
|
+
|
|
330
|
+
| Command | Description |
|
|
331
|
+
| ------------------- | ----------------------------------------------------- |
|
|
332
|
+
| `mock-mcp adapter` | Start the MCP adapter (default, for MCP clients) |
|
|
333
|
+
| `mock-mcp daemon` | Start the daemon process (usually auto-started) |
|
|
334
|
+
| `mock-mcp status` | Show daemon status for current project |
|
|
335
|
+
| `mock-mcp stop` | Stop the daemon for current project |
|
|
336
|
+
| `mock-mcp help` | Show help |
|
|
337
|
+
| `mock-mcp version` | Show version |
|
|
338
|
+
|
|
339
|
+
Example usage:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
# Check if daemon is running
|
|
343
|
+
mock-mcp status
|
|
344
|
+
|
|
345
|
+
# Manually stop daemon
|
|
346
|
+
mock-mcp stop
|
|
273
347
|
```
|
|
274
348
|
|
|
275
349
|
## Available APIs
|
|
276
350
|
|
|
277
351
|
The library exports primitives so you can embed the workflow inside bespoke runners or scripts:
|
|
278
352
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
- `
|
|
282
|
-
- `
|
|
353
|
+
### Client APIs
|
|
354
|
+
|
|
355
|
+
- `connect(options?)` - Creates a `BatchMockCollector` and waits for daemon connection.
|
|
356
|
+
- `BatchMockCollector` - Low-level batching client for test environments.
|
|
357
|
+
- `BatchMockCollector.requestMock(endpoint, method, options?)` - Request mock data for an endpoint.
|
|
358
|
+
- `BatchMockCollector.waitForPendingRequests()` - Wait for pending requests to settle.
|
|
359
|
+
- `BatchMockCollector.getRunId()` - Get the unique run ID for this collector.
|
|
360
|
+
|
|
361
|
+
### Server APIs
|
|
283
362
|
|
|
284
|
-
|
|
363
|
+
- `MockMcpDaemon` - The daemon process that manages runs and batches.
|
|
364
|
+
- `runAdapter()` - Start the MCP adapter (stdio transport).
|
|
365
|
+
- `DaemonClient` - JSON-RPC client for communicating with the daemon.
|
|
366
|
+
|
|
367
|
+
### Discovery APIs
|
|
368
|
+
|
|
369
|
+
- `ensureDaemonRunning(options?)` - Ensure daemon is running, start if needed.
|
|
370
|
+
- `resolveProjectRoot(startDir?)` - Find project root by searching for `.git` or `package.json`.
|
|
371
|
+
- `computeProjectId(projectRoot)` - Compute stable project ID from path.
|
|
372
|
+
|
|
373
|
+
Each class accepts logger overrides, timeout tweaks, and other ergonomics.
|
|
285
374
|
|
|
286
375
|
## Environment Variables
|
|
287
376
|
|
|
288
|
-
| Variable
|
|
289
|
-
|
|
|
290
|
-
| `
|
|
291
|
-
| `
|
|
377
|
+
| Variable | Description | Default |
|
|
378
|
+
| -------------------- | ------------------------------------------------------------------------ | ------------------ |
|
|
379
|
+
| `MOCK_MCP` | Enables the test runner hook so intercepted requests are routed to mock-mcp. | unset |
|
|
380
|
+
| `MOCK_MCP_CACHE_DIR` | Override the cache directory for daemon files (registry, socket, lock). | `~/.cache/mock-mcp`|
|
|
292
381
|
|
|
293
382
|
## How It Works
|
|
294
383
|
|
|
295
|
-
|
|
384
|
+
The new **Daemon + Adapter** architecture uses four collaborating processes:
|
|
296
385
|
|
|
297
|
-
| Process | Responsibility | Technology | Communication
|
|
298
|
-
| ---------------- | ----------------------------------------------------- | ---------------------------------------- |
|
|
299
|
-
| **Test Process** | Executes test cases and intercepts HTTP requests | Playwright/Puppeteer +
|
|
300
|
-
| **
|
|
301
|
-
| **
|
|
386
|
+
| Process | Responsibility | Technology | Communication |
|
|
387
|
+
| ---------------- | ----------------------------------------------------- | ---------------------------------------- | ------------------------------- |
|
|
388
|
+
| **Test Process** | Executes test cases and intercepts HTTP requests | Playwright/Puppeteer + BatchMockCollector| WebSocket over IPC → Daemon |
|
|
389
|
+
| **Daemon** | Manages runs, batches, claims with lease control | Node.js + HTTP/WS on Unix socket | IPC ↔ Test & Adapter |
|
|
390
|
+
| **Adapter** | Bridges MCP protocol to daemon RPC | Node.js + MCP SDK (stdio) | stdio ↔ MCP Client, RPC → Daemon|
|
|
391
|
+
| **MCP Client** | Uses AI to produce mock data via MCP tools | Cursor / Claude Desktop / custom clients | MCP protocol → Adapter |
|
|
302
392
|
|
|
303
|
-
### Data flow sequence
|
|
393
|
+
### Data flow sequence with claim-based concurrency
|
|
304
394
|
|
|
305
395
|
```
|
|
306
|
-
┌──────────────────┐
|
|
307
|
-
│ Test Process │
|
|
308
|
-
│ (Browser Test) │
|
|
309
|
-
└────────┬─────────┘
|
|
310
|
-
│
|
|
311
|
-
│ 1.
|
|
312
|
-
│
|
|
313
|
-
|
|
314
|
-
│
|
|
315
|
-
│ 2.
|
|
316
|
-
│
|
|
317
|
-
│
|
|
318
|
-
│
|
|
319
|
-
│
|
|
320
|
-
│
|
|
321
|
-
│
|
|
322
|
-
│
|
|
323
|
-
│
|
|
324
|
-
│
|
|
325
|
-
|
|
326
|
-
│
|
|
327
|
-
│
|
|
328
|
-
│
|
|
329
|
-
│
|
|
330
|
-
│
|
|
331
|
-
│
|
|
332
|
-
│
|
|
333
|
-
│
|
|
334
|
-
│
|
|
335
|
-
│
|
|
336
|
-
│
|
|
337
|
-
│
|
|
338
|
-
│
|
|
339
|
-
│
|
|
340
|
-
│
|
|
341
|
-
│
|
|
342
|
-
│
|
|
343
|
-
│
|
|
344
|
-
│
|
|
345
|
-
│
|
|
346
|
-
│
|
|
347
|
-
│
|
|
348
|
-
│
|
|
349
|
-
│
|
|
350
|
-
│
|
|
351
|
-
|
|
352
|
-
│
|
|
353
|
-
│
|
|
354
|
-
|
|
355
|
-
│ req-2.resolve() │ │
|
|
356
|
-
│ req-3.resolve() │ │
|
|
357
|
-
│ │ │
|
|
358
|
-
│ 12. Test continues │ │
|
|
359
|
-
│ Assertions & │ │
|
|
360
|
-
│ Verification │ │
|
|
361
|
-
│ │ │
|
|
362
|
-
│ 13. Test Complete ✓ │ │
|
|
363
|
-
▼ ▼ ▼
|
|
396
|
+
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
|
|
397
|
+
│ Test Process │ │ Daemon │ │ Adapter │ │ MCP Client │
|
|
398
|
+
│ (Browser Test) │ │ (per-project) │ │ (per MCP client) │ │ (AI) │
|
|
399
|
+
└────────┬─────────┘ └────────┬─────────┘ └────────┬─────────┘ └────────┬─────────┘
|
|
400
|
+
│ │ │ │
|
|
401
|
+
│ 1. Connect via IPC │ │ │
|
|
402
|
+
│ HELLO_TEST │ │ │
|
|
403
|
+
├════════════════════════►│ │ │
|
|
404
|
+
│ │ │ │
|
|
405
|
+
│ 2. HELLO_ACK │ │ │
|
|
406
|
+
│◄════════════════════════┤ │ │
|
|
407
|
+
│ │ │ │
|
|
408
|
+
│ 3. BATCH_MOCK_REQUEST │ │ │
|
|
409
|
+
│ [req-1, req-2, ...] │ │ │
|
|
410
|
+
├════════════════════════►│ │ │
|
|
411
|
+
│ │ │ │
|
|
412
|
+
│ Test paused... │ 4. Store in pending │ │
|
|
413
|
+
│ Awaiting mocks │ queue │ │
|
|
414
|
+
│ │ │ │
|
|
415
|
+
│ │ │◄────────────────────────┤
|
|
416
|
+
│ │ │ 5. claim_next_batch │
|
|
417
|
+
│ │ │ │
|
|
418
|
+
│ │◄────────────────────────┤ │
|
|
419
|
+
│ │ 6. RPC: claimNextBatch │ │
|
|
420
|
+
│ │ │ │
|
|
421
|
+
│ ├────────────────────────►│ │
|
|
422
|
+
│ │ 7. {batch, claimToken} │ │
|
|
423
|
+
│ │ │ │
|
|
424
|
+
│ │ ├────────────────────────►│
|
|
425
|
+
│ │ │ 8. Return batch info │
|
|
426
|
+
│ │ │ │
|
|
427
|
+
│ │ │ 9. AI generates │
|
|
428
|
+
│ │ │ mock data │
|
|
429
|
+
│ │ │ │
|
|
430
|
+
│ │ │◄────────────────────────┤
|
|
431
|
+
│ │ │ 10. provide_batch_ │
|
|
432
|
+
│ │ │ mock_data │
|
|
433
|
+
│ │ │ │
|
|
434
|
+
│ │◄────────────────────────┤ │
|
|
435
|
+
│ │ 11. RPC: provideBatch │ │
|
|
436
|
+
│ │ + claimToken │ │
|
|
437
|
+
│ │ │ │
|
|
438
|
+
│ 12. BATCH_MOCK_RESULT │ │ │
|
|
439
|
+
│ [mock-1, mock-2] │ │ │
|
|
440
|
+
│◄════════════════════════┤ │ │
|
|
441
|
+
│ │ │ │
|
|
442
|
+
│ 13. Resolve promises │ │ │
|
|
443
|
+
│ Test continues │ │ │
|
|
444
|
+
▼ ▼ ▼ ▼
|
|
364
445
|
|
|
365
446
|
Protocol Summary:
|
|
366
447
|
─────────────────
|
|
367
|
-
- Test Process ←→
|
|
368
|
-
Message types: BATCH_MOCK_REQUEST,
|
|
448
|
+
- Test Process ←→ Daemon: WebSocket over IPC (Unix socket / Named pipe)
|
|
449
|
+
Message types: HELLO_TEST, BATCH_MOCK_REQUEST, BATCH_MOCK_RESULT
|
|
450
|
+
|
|
451
|
+
- Adapter ←→ Daemon: HTTP JSON-RPC over IPC
|
|
452
|
+
Methods: claimNextBatch, provideBatch, getStatus, listRuns
|
|
369
453
|
|
|
370
|
-
- MCP
|
|
371
|
-
Tools:
|
|
454
|
+
- MCP Client ←→ Adapter: MCP protocol (stdio)
|
|
455
|
+
Tools: claim_next_batch, provide_batch_mock_data, get_status, list_runs
|
|
372
456
|
|
|
373
457
|
Key Features:
|
|
374
458
|
──────────────
|
|
375
|
-
✓
|
|
376
|
-
✓
|
|
377
|
-
✓
|
|
378
|
-
✓
|
|
459
|
+
✓ uses IPC instead of TCP - No port conflicts
|
|
460
|
+
✓ Multi-client support - multiple MCP clients can run simultaneously
|
|
461
|
+
✓ Claim-based concurrency - prevents race conditions on batches
|
|
462
|
+
✓ Lease expiration - auto-recovery if adapter crashes
|
|
463
|
+
✓ Multi-run isolation - concurrent test processes are isolated
|
|
464
|
+
✓ Auto-discovery - no manual configuration needed
|
|
379
465
|
```
|
|
380
466
|
|
|
381
467
|
## Use the development scripts
|
|
382
468
|
|
|
383
469
|
```bash
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
470
|
+
yarn test # runs Vitest suites
|
|
471
|
+
yarn test:concurrency # runs concurrency tests specifically
|
|
472
|
+
yarn dev # tsx watch mode for the CLI
|
|
473
|
+
yarn dev:adapter # tsx watch mode for adapter
|
|
474
|
+
yarn lint # eslint --ext .ts
|
|
475
|
+
yarn build # compile TypeScript
|
|
387
476
|
```
|
|
388
477
|
|
|
389
|
-
|
|
478
|
+
Tests create isolated daemon instances with temporary cache directories, so they can run safely without affecting your development environment.
|
|
390
479
|
|
|
391
480
|
## License
|
|
392
481
|
|