mock-mcp 0.5.0 → 0.5.1

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/dist/index.d.cts CHANGED
@@ -8,7 +8,7 @@
8
8
  * - Manage runs, batches, claims with lease-based concurrency control
9
9
  * - Clean up expired claims and disconnected runs
10
10
  */
11
- type Logger$2 = Pick<Console, "log" | "warn" | "error"> & {
11
+ type Logger$3 = Pick<Console, "log" | "warn" | "error"> & {
12
12
  debug?: (...args: unknown[]) => void;
13
13
  };
14
14
  interface MockMcpDaemonOptions {
@@ -16,7 +16,7 @@ interface MockMcpDaemonOptions {
16
16
  token: string;
17
17
  version: string;
18
18
  cacheDir?: string;
19
- logger?: Logger$2;
19
+ logger?: Logger$3;
20
20
  /** Default lease time for batch claims (ms). Default: 30000 */
21
21
  defaultLeaseMs?: number;
22
22
  /** Interval for sweeping expired claims (ms). Default: 5000 */
@@ -65,14 +65,15 @@ declare class MockMcpDaemon {
65
65
  * Each MCP client (Cursor, Claude Desktop, etc.) spawns one Adapter process.
66
66
  * The Adapter:
67
67
  * - Exposes MCP tools (claim_next_batch, provide_batch_mock_data, get_status)
68
- * - Connects to the Daemon via IPC
68
+ * - Discovers and connects to ALL active Daemons via IPC
69
69
  * - Does NOT bind any ports (avoids conflicts)
70
+ * - Works across projects without requiring --project-root
70
71
  */
71
- type Logger$1 = Pick<Console, "log" | "warn" | "error"> & {
72
+ type Logger$2 = Pick<Console, "log" | "warn" | "error"> & {
72
73
  debug?: (...args: unknown[]) => void;
73
74
  };
74
75
  interface AdapterOptions {
75
- logger?: Logger$1;
76
+ logger?: Logger$2;
76
77
  version?: string;
77
78
  }
78
79
  declare function runAdapter(opts?: AdapterOptions): Promise<void>;
@@ -262,6 +263,127 @@ declare function computeProjectId(projectRoot: string): string;
262
263
  * Thread-safe: multiple processes calling this concurrently will only start one daemon.
263
264
  */
264
265
  declare function ensureDaemonRunning(opts?: EnsureDaemonOptions): Promise<DaemonRegistry>;
266
+ /**
267
+ * Entry in the global active daemons index.
268
+ */
269
+ interface ActiveDaemonEntry {
270
+ projectId: string;
271
+ projectRoot: string;
272
+ ipcPath: string;
273
+ registryPath: string;
274
+ pid: number;
275
+ startedAt: string;
276
+ version: string;
277
+ }
278
+ /**
279
+ * Global index of all active daemons.
280
+ */
281
+ interface ActiveDaemonsIndex {
282
+ daemons: ActiveDaemonEntry[];
283
+ updatedAt: string;
284
+ }
285
+ /**
286
+ * Read the global active daemons index.
287
+ */
288
+ declare function readGlobalIndex(cacheDir?: string): Promise<ActiveDaemonsIndex>;
289
+ /**
290
+ * Clean up stale entries from the global index.
291
+ * Removes entries where the daemon is no longer running.
292
+ */
293
+ declare function cleanupGlobalIndex(cacheDir?: string): Promise<void>;
294
+ /**
295
+ * Discover all active daemons.
296
+ * Returns list of daemons with their connection info.
297
+ */
298
+ declare function discoverAllDaemons(cacheDir?: string): Promise<{
299
+ registry: DaemonRegistry;
300
+ healthy: boolean;
301
+ }[]>;
302
+
303
+ /**
304
+ * MultiDaemonClient - Aggregates multiple daemon connections for cross-project operation.
305
+ *
306
+ * This client discovers all active daemons and can perform operations across them.
307
+ * It's designed for MCP adapters that need to work without knowing the specific project root.
308
+ */
309
+
310
+ type Logger$1 = Pick<Console, "log" | "warn" | "error"> & {
311
+ debug?: (...args: unknown[]) => void;
312
+ };
313
+ interface MultiDaemonClientOptions {
314
+ logger?: Logger$1;
315
+ cacheDir?: string;
316
+ }
317
+ interface DaemonConnection {
318
+ registry: DaemonRegistry;
319
+ healthy: boolean;
320
+ }
321
+ interface ExtendedRunInfo extends RunInfo {
322
+ projectId: string;
323
+ projectRoot: string;
324
+ }
325
+ interface AggregatedStatusResult {
326
+ daemons: (GetStatusResult & {
327
+ healthy: boolean;
328
+ })[];
329
+ totalRuns: number;
330
+ totalPending: number;
331
+ totalClaimed: number;
332
+ }
333
+ declare class MultiDaemonClient {
334
+ private readonly logger;
335
+ private readonly cacheDir?;
336
+ private readonly adapterId;
337
+ constructor(opts?: MultiDaemonClientOptions);
338
+ /**
339
+ * Discover all active and healthy daemons.
340
+ */
341
+ discoverDaemons(): Promise<DaemonConnection[]>;
342
+ /**
343
+ * Get aggregated status from all daemons.
344
+ */
345
+ getAggregatedStatus(): Promise<AggregatedStatusResult>;
346
+ /**
347
+ * List all runs across all daemons.
348
+ */
349
+ listAllRuns(): Promise<ExtendedRunInfo[]>;
350
+ /**
351
+ * Claim the next available batch from any daemon.
352
+ * Searches through all daemons in order until finding one with a pending batch.
353
+ */
354
+ claimNextBatch(args: {
355
+ runId?: string;
356
+ leaseMs?: number;
357
+ }): Promise<(ClaimNextBatchResult & {
358
+ projectId: string;
359
+ projectRoot: string;
360
+ }) | null>;
361
+ /**
362
+ * Provide mock data for a batch.
363
+ * Automatically routes to the correct daemon based on batchId.
364
+ */
365
+ provideBatch(args: {
366
+ batchId: string;
367
+ claimToken: string;
368
+ mocks: MockResponseDescriptor[];
369
+ }): Promise<ProvideBatchResult>;
370
+ /**
371
+ * Release a batch.
372
+ */
373
+ releaseBatch(args: {
374
+ batchId: string;
375
+ claimToken: string;
376
+ reason?: string;
377
+ }): Promise<{
378
+ ok: boolean;
379
+ message?: string;
380
+ }>;
381
+ /**
382
+ * Get a specific batch by ID.
383
+ */
384
+ getBatch(batchId: string): Promise<GetBatchResult | null>;
385
+ private rpc;
386
+ }
265
387
 
266
388
  /**
267
389
  * BatchMockCollector - Collects HTTP requests and sends them to the daemon for mock generation.
@@ -381,9 +503,17 @@ declare class BatchMockCollector {
381
503
  constructor(options?: BatchMockCollectorOptions);
382
504
  /**
383
505
  * Resolve projectRoot from options.
384
- * Priority: projectRoot > filePath > undefined (auto-detect)
506
+ * Priority: projectRoot (if valid) > filePath > projectRoot (fallback) > undefined (auto-detect)
507
+ *
508
+ * A projectRoot is "valid" if it contains .git or package.json. This prevents
509
+ * accidentally using a wrong directory (e.g., user's home directory) when the
510
+ * caller mistakenly passes process.cwd() as projectRoot.
385
511
  */
386
512
  private resolveProjectRootFromOptions;
513
+ /**
514
+ * Check if a directory contains .git or package.json
515
+ */
516
+ private hasGitOrPackageJson;
387
517
  /**
388
518
  * Ensures the underlying connection is ready for use.
389
519
  */
@@ -469,4 +599,4 @@ interface MockClient {
469
599
  */
470
600
  declare const connect: (options?: ConnectOptions) => Promise<MockClient>;
471
601
 
472
- export { type AdapterOptions, BatchMockCollector, type BatchMockCollectorOptions, type ConnectOptions, DaemonClient, type DaemonRegistry, type MockClient, MockMcpDaemon, type MockMcpDaemonOptions, type MockRequestDescriptor, type MockResponseDescriptor, type RequestMockOptions, type ResolvedMock, computeProjectId, connect, ensureDaemonRunning, resolveProjectRoot, runAdapter };
602
+ export { type ActiveDaemonEntry, type ActiveDaemonsIndex, type AdapterOptions, type AggregatedStatusResult, BatchMockCollector, type BatchMockCollectorOptions, type ConnectOptions, DaemonClient, type DaemonRegistry, type ExtendedRunInfo, type MockClient, MockMcpDaemon, type MockMcpDaemonOptions, type MockRequestDescriptor, type MockResponseDescriptor, MultiDaemonClient, type MultiDaemonClientOptions, type RequestMockOptions, type ResolvedMock, cleanupGlobalIndex, computeProjectId, connect, discoverAllDaemons, ensureDaemonRunning, readGlobalIndex, resolveProjectRoot, runAdapter };
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * - Manage runs, batches, claims with lease-based concurrency control
9
9
  * - Clean up expired claims and disconnected runs
10
10
  */
11
- type Logger$2 = Pick<Console, "log" | "warn" | "error"> & {
11
+ type Logger$3 = Pick<Console, "log" | "warn" | "error"> & {
12
12
  debug?: (...args: unknown[]) => void;
13
13
  };
14
14
  interface MockMcpDaemonOptions {
@@ -16,7 +16,7 @@ interface MockMcpDaemonOptions {
16
16
  token: string;
17
17
  version: string;
18
18
  cacheDir?: string;
19
- logger?: Logger$2;
19
+ logger?: Logger$3;
20
20
  /** Default lease time for batch claims (ms). Default: 30000 */
21
21
  defaultLeaseMs?: number;
22
22
  /** Interval for sweeping expired claims (ms). Default: 5000 */
@@ -65,14 +65,15 @@ declare class MockMcpDaemon {
65
65
  * Each MCP client (Cursor, Claude Desktop, etc.) spawns one Adapter process.
66
66
  * The Adapter:
67
67
  * - Exposes MCP tools (claim_next_batch, provide_batch_mock_data, get_status)
68
- * - Connects to the Daemon via IPC
68
+ * - Discovers and connects to ALL active Daemons via IPC
69
69
  * - Does NOT bind any ports (avoids conflicts)
70
+ * - Works across projects without requiring --project-root
70
71
  */
71
- type Logger$1 = Pick<Console, "log" | "warn" | "error"> & {
72
+ type Logger$2 = Pick<Console, "log" | "warn" | "error"> & {
72
73
  debug?: (...args: unknown[]) => void;
73
74
  };
74
75
  interface AdapterOptions {
75
- logger?: Logger$1;
76
+ logger?: Logger$2;
76
77
  version?: string;
77
78
  }
78
79
  declare function runAdapter(opts?: AdapterOptions): Promise<void>;
@@ -262,6 +263,127 @@ declare function computeProjectId(projectRoot: string): string;
262
263
  * Thread-safe: multiple processes calling this concurrently will only start one daemon.
263
264
  */
264
265
  declare function ensureDaemonRunning(opts?: EnsureDaemonOptions): Promise<DaemonRegistry>;
266
+ /**
267
+ * Entry in the global active daemons index.
268
+ */
269
+ interface ActiveDaemonEntry {
270
+ projectId: string;
271
+ projectRoot: string;
272
+ ipcPath: string;
273
+ registryPath: string;
274
+ pid: number;
275
+ startedAt: string;
276
+ version: string;
277
+ }
278
+ /**
279
+ * Global index of all active daemons.
280
+ */
281
+ interface ActiveDaemonsIndex {
282
+ daemons: ActiveDaemonEntry[];
283
+ updatedAt: string;
284
+ }
285
+ /**
286
+ * Read the global active daemons index.
287
+ */
288
+ declare function readGlobalIndex(cacheDir?: string): Promise<ActiveDaemonsIndex>;
289
+ /**
290
+ * Clean up stale entries from the global index.
291
+ * Removes entries where the daemon is no longer running.
292
+ */
293
+ declare function cleanupGlobalIndex(cacheDir?: string): Promise<void>;
294
+ /**
295
+ * Discover all active daemons.
296
+ * Returns list of daemons with their connection info.
297
+ */
298
+ declare function discoverAllDaemons(cacheDir?: string): Promise<{
299
+ registry: DaemonRegistry;
300
+ healthy: boolean;
301
+ }[]>;
302
+
303
+ /**
304
+ * MultiDaemonClient - Aggregates multiple daemon connections for cross-project operation.
305
+ *
306
+ * This client discovers all active daemons and can perform operations across them.
307
+ * It's designed for MCP adapters that need to work without knowing the specific project root.
308
+ */
309
+
310
+ type Logger$1 = Pick<Console, "log" | "warn" | "error"> & {
311
+ debug?: (...args: unknown[]) => void;
312
+ };
313
+ interface MultiDaemonClientOptions {
314
+ logger?: Logger$1;
315
+ cacheDir?: string;
316
+ }
317
+ interface DaemonConnection {
318
+ registry: DaemonRegistry;
319
+ healthy: boolean;
320
+ }
321
+ interface ExtendedRunInfo extends RunInfo {
322
+ projectId: string;
323
+ projectRoot: string;
324
+ }
325
+ interface AggregatedStatusResult {
326
+ daemons: (GetStatusResult & {
327
+ healthy: boolean;
328
+ })[];
329
+ totalRuns: number;
330
+ totalPending: number;
331
+ totalClaimed: number;
332
+ }
333
+ declare class MultiDaemonClient {
334
+ private readonly logger;
335
+ private readonly cacheDir?;
336
+ private readonly adapterId;
337
+ constructor(opts?: MultiDaemonClientOptions);
338
+ /**
339
+ * Discover all active and healthy daemons.
340
+ */
341
+ discoverDaemons(): Promise<DaemonConnection[]>;
342
+ /**
343
+ * Get aggregated status from all daemons.
344
+ */
345
+ getAggregatedStatus(): Promise<AggregatedStatusResult>;
346
+ /**
347
+ * List all runs across all daemons.
348
+ */
349
+ listAllRuns(): Promise<ExtendedRunInfo[]>;
350
+ /**
351
+ * Claim the next available batch from any daemon.
352
+ * Searches through all daemons in order until finding one with a pending batch.
353
+ */
354
+ claimNextBatch(args: {
355
+ runId?: string;
356
+ leaseMs?: number;
357
+ }): Promise<(ClaimNextBatchResult & {
358
+ projectId: string;
359
+ projectRoot: string;
360
+ }) | null>;
361
+ /**
362
+ * Provide mock data for a batch.
363
+ * Automatically routes to the correct daemon based on batchId.
364
+ */
365
+ provideBatch(args: {
366
+ batchId: string;
367
+ claimToken: string;
368
+ mocks: MockResponseDescriptor[];
369
+ }): Promise<ProvideBatchResult>;
370
+ /**
371
+ * Release a batch.
372
+ */
373
+ releaseBatch(args: {
374
+ batchId: string;
375
+ claimToken: string;
376
+ reason?: string;
377
+ }): Promise<{
378
+ ok: boolean;
379
+ message?: string;
380
+ }>;
381
+ /**
382
+ * Get a specific batch by ID.
383
+ */
384
+ getBatch(batchId: string): Promise<GetBatchResult | null>;
385
+ private rpc;
386
+ }
265
387
 
266
388
  /**
267
389
  * BatchMockCollector - Collects HTTP requests and sends them to the daemon for mock generation.
@@ -381,9 +503,17 @@ declare class BatchMockCollector {
381
503
  constructor(options?: BatchMockCollectorOptions);
382
504
  /**
383
505
  * Resolve projectRoot from options.
384
- * Priority: projectRoot > filePath > undefined (auto-detect)
506
+ * Priority: projectRoot (if valid) > filePath > projectRoot (fallback) > undefined (auto-detect)
507
+ *
508
+ * A projectRoot is "valid" if it contains .git or package.json. This prevents
509
+ * accidentally using a wrong directory (e.g., user's home directory) when the
510
+ * caller mistakenly passes process.cwd() as projectRoot.
385
511
  */
386
512
  private resolveProjectRootFromOptions;
513
+ /**
514
+ * Check if a directory contains .git or package.json
515
+ */
516
+ private hasGitOrPackageJson;
387
517
  /**
388
518
  * Ensures the underlying connection is ready for use.
389
519
  */
@@ -469,4 +599,4 @@ interface MockClient {
469
599
  */
470
600
  declare const connect: (options?: ConnectOptions) => Promise<MockClient>;
471
601
 
472
- export { type AdapterOptions, BatchMockCollector, type BatchMockCollectorOptions, type ConnectOptions, DaemonClient, type DaemonRegistry, type MockClient, MockMcpDaemon, type MockMcpDaemonOptions, type MockRequestDescriptor, type MockResponseDescriptor, type RequestMockOptions, type ResolvedMock, computeProjectId, connect, ensureDaemonRunning, resolveProjectRoot, runAdapter };
602
+ export { type ActiveDaemonEntry, type ActiveDaemonsIndex, type AdapterOptions, type AggregatedStatusResult, BatchMockCollector, type BatchMockCollectorOptions, type ConnectOptions, DaemonClient, type DaemonRegistry, type ExtendedRunInfo, type MockClient, MockMcpDaemon, type MockMcpDaemonOptions, type MockRequestDescriptor, type MockResponseDescriptor, MultiDaemonClient, type MultiDaemonClientOptions, type RequestMockOptions, type ResolvedMock, cleanupGlobalIndex, computeProjectId, connect, discoverAllDaemons, ensureDaemonRunning, readGlobalIndex, resolveProjectRoot, runAdapter };