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.
Files changed (44) hide show
  1. package/README.md +217 -128
  2. package/dist/adapter/index.cjs +712 -0
  3. package/dist/adapter/index.d.cts +55 -0
  4. package/dist/adapter/index.d.ts +55 -0
  5. package/dist/adapter/index.js +672 -0
  6. package/dist/client/connect.cjs +913 -0
  7. package/dist/client/connect.d.cts +211 -0
  8. package/dist/client/connect.d.ts +209 -6
  9. package/dist/client/connect.js +867 -10
  10. package/dist/client/index.cjs +914 -0
  11. package/dist/client/index.d.cts +4 -0
  12. package/dist/client/index.d.ts +4 -2
  13. package/dist/client/index.js +873 -2
  14. package/dist/daemon/index.cjs +667 -0
  15. package/dist/daemon/index.d.cts +62 -0
  16. package/dist/daemon/index.d.ts +62 -0
  17. package/dist/daemon/index.js +628 -0
  18. package/dist/discovery-Dc2LdF8q.d.cts +105 -0
  19. package/dist/discovery-Dc2LdF8q.d.ts +105 -0
  20. package/dist/index.cjs +2238 -0
  21. package/dist/index.d.cts +472 -0
  22. package/dist/index.d.ts +472 -10
  23. package/dist/index.js +2185 -53
  24. package/dist/protocol-CiwaQFOt.d.ts +239 -0
  25. package/dist/protocol-xZu-wb0n.d.cts +239 -0
  26. package/dist/shared/index.cjs +386 -0
  27. package/dist/shared/index.d.cts +4 -0
  28. package/dist/shared/index.d.ts +4 -0
  29. package/dist/shared/index.js +310 -0
  30. package/dist/types-BKREdsyr.d.cts +32 -0
  31. package/dist/types-BKREdsyr.d.ts +32 -0
  32. package/package.json +44 -4
  33. package/dist/client/batch-mock-collector.d.ts +0 -87
  34. package/dist/client/batch-mock-collector.js +0 -223
  35. package/dist/client/util.d.ts +0 -1
  36. package/dist/client/util.js +0 -3
  37. package/dist/connect.cjs +0 -299
  38. package/dist/connect.d.cts +0 -95
  39. package/dist/server/index.d.ts +0 -1
  40. package/dist/server/index.js +0 -1
  41. package/dist/server/test-mock-mcp-server.d.ts +0 -73
  42. package/dist/server/test-mock-mcp-server.js +0 -392
  43. package/dist/types.d.ts +0 -42
  44. package/dist/types.js +0 -2
@@ -0,0 +1,105 @@
1
+ import fssync from 'node:fs';
2
+
3
+ /**
4
+ * Discovery module for mock-mcp Daemon + Adapter architecture.
5
+ *
6
+ * Provides:
7
+ * - Project root resolution (up-search for .git / package.json)
8
+ * - Project ID computation (sha256 of realpath)
9
+ * - Registry/lock file path management
10
+ * - IPC path (Unix Domain Socket / Windows Named Pipe)
11
+ * - ensureDaemonRunning() - atomic daemon startup with lock
12
+ */
13
+
14
+ interface DaemonRegistry {
15
+ projectId: string;
16
+ projectRoot: string;
17
+ ipcPath: string;
18
+ token: string;
19
+ pid: number;
20
+ startedAt: string;
21
+ version: string;
22
+ }
23
+ interface EnsureDaemonOptions {
24
+ projectRoot?: string;
25
+ timeoutMs?: number;
26
+ /** For testing: override cache directory */
27
+ cacheDir?: string;
28
+ }
29
+ /**
30
+ * Resolve the project root by searching upward for .git or package.json.
31
+ * Falls back to the starting directory if nothing is found.
32
+ */
33
+ declare function resolveProjectRoot(startDir?: string): string;
34
+ /**
35
+ * Compute a stable project ID from the project root path.
36
+ * Uses sha256 of the realpath, truncated to 16 characters.
37
+ */
38
+ declare function computeProjectId(projectRoot: string): string;
39
+ /**
40
+ * Get the cache directory for mock-mcp files.
41
+ * Priority: override > MOCK_MCP_CACHE_DIR env > XDG_CACHE_HOME > LOCALAPPDATA (Windows) > ~/.cache
42
+ */
43
+ declare function getCacheDir(override?: string): string;
44
+ interface DaemonPaths {
45
+ base: string;
46
+ registryPath: string;
47
+ lockPath: string;
48
+ ipcPath: string;
49
+ }
50
+ /**
51
+ * Get all relevant paths for a given project ID.
52
+ */
53
+ declare function getPaths(projectId: string, cacheDir?: string): DaemonPaths;
54
+ /**
55
+ * Read the daemon registry file.
56
+ */
57
+ declare function readRegistry(registryPath: string): Promise<DaemonRegistry | null>;
58
+ /**
59
+ * Write the daemon registry file with restricted permissions.
60
+ */
61
+ declare function writeRegistry(registryPath: string, registry: DaemonRegistry): Promise<void>;
62
+ /**
63
+ * Check if the daemon is healthy by making an HTTP request to /health.
64
+ */
65
+ declare function healthCheck(ipcPath: string, timeoutMs?: number): Promise<boolean>;
66
+ /**
67
+ * Try to acquire an exclusive lock file.
68
+ * Returns the file handle if successful, null otherwise.
69
+ */
70
+ declare function tryAcquireLock(lockPath: string): Promise<fssync.promises.FileHandle | null>;
71
+ /**
72
+ * Release the lock file.
73
+ */
74
+ declare function releaseLock(lockPath: string, fh: fssync.promises.FileHandle): Promise<void>;
75
+ /**
76
+ * Generate a random token for daemon authentication.
77
+ */
78
+ declare function randomToken(): string;
79
+ /**
80
+ * Get the path to the daemon entry point.
81
+ *
82
+ * This function handles multiple scenarios:
83
+ * 1. Direct execution from source (development)
84
+ * 2. Execution from dist (production)
85
+ * 3. When re-bundled by another tool (Vitest, esbuild, webpack)
86
+ *
87
+ * We use require.resolve to reliably find the mock-mcp package location,
88
+ * which works even when the code is re-bundled by another tool.
89
+ */
90
+ declare function getDaemonEntryPath(): string;
91
+ /**
92
+ * Ensure the daemon is running for the given project.
93
+ *
94
+ * This function:
95
+ * 1. Checks if a daemon is already running (via registry + health check)
96
+ * 2. If not, acquires a lock and spawns a new daemon
97
+ * 3. Waits for the daemon to become healthy
98
+ * 4. Returns the registry information
99
+ *
100
+ * Thread-safe: multiple processes calling this concurrently will only start one daemon.
101
+ */
102
+ declare function ensureDaemonRunning(opts?: EnsureDaemonOptions): Promise<DaemonRegistry>;
103
+ declare function sleep(ms: number): Promise<void>;
104
+
105
+ export { type DaemonRegistry as D, type EnsureDaemonOptions as E, getPaths as a, readRegistry as b, computeProjectId as c, releaseLock as d, randomToken as e, getDaemonEntryPath as f, getCacheDir as g, healthCheck as h, ensureDaemonRunning as i, type DaemonPaths as j, resolveProjectRoot as r, sleep as s, tryAcquireLock as t, writeRegistry as w };
@@ -0,0 +1,105 @@
1
+ import fssync from 'node:fs';
2
+
3
+ /**
4
+ * Discovery module for mock-mcp Daemon + Adapter architecture.
5
+ *
6
+ * Provides:
7
+ * - Project root resolution (up-search for .git / package.json)
8
+ * - Project ID computation (sha256 of realpath)
9
+ * - Registry/lock file path management
10
+ * - IPC path (Unix Domain Socket / Windows Named Pipe)
11
+ * - ensureDaemonRunning() - atomic daemon startup with lock
12
+ */
13
+
14
+ interface DaemonRegistry {
15
+ projectId: string;
16
+ projectRoot: string;
17
+ ipcPath: string;
18
+ token: string;
19
+ pid: number;
20
+ startedAt: string;
21
+ version: string;
22
+ }
23
+ interface EnsureDaemonOptions {
24
+ projectRoot?: string;
25
+ timeoutMs?: number;
26
+ /** For testing: override cache directory */
27
+ cacheDir?: string;
28
+ }
29
+ /**
30
+ * Resolve the project root by searching upward for .git or package.json.
31
+ * Falls back to the starting directory if nothing is found.
32
+ */
33
+ declare function resolveProjectRoot(startDir?: string): string;
34
+ /**
35
+ * Compute a stable project ID from the project root path.
36
+ * Uses sha256 of the realpath, truncated to 16 characters.
37
+ */
38
+ declare function computeProjectId(projectRoot: string): string;
39
+ /**
40
+ * Get the cache directory for mock-mcp files.
41
+ * Priority: override > MOCK_MCP_CACHE_DIR env > XDG_CACHE_HOME > LOCALAPPDATA (Windows) > ~/.cache
42
+ */
43
+ declare function getCacheDir(override?: string): string;
44
+ interface DaemonPaths {
45
+ base: string;
46
+ registryPath: string;
47
+ lockPath: string;
48
+ ipcPath: string;
49
+ }
50
+ /**
51
+ * Get all relevant paths for a given project ID.
52
+ */
53
+ declare function getPaths(projectId: string, cacheDir?: string): DaemonPaths;
54
+ /**
55
+ * Read the daemon registry file.
56
+ */
57
+ declare function readRegistry(registryPath: string): Promise<DaemonRegistry | null>;
58
+ /**
59
+ * Write the daemon registry file with restricted permissions.
60
+ */
61
+ declare function writeRegistry(registryPath: string, registry: DaemonRegistry): Promise<void>;
62
+ /**
63
+ * Check if the daemon is healthy by making an HTTP request to /health.
64
+ */
65
+ declare function healthCheck(ipcPath: string, timeoutMs?: number): Promise<boolean>;
66
+ /**
67
+ * Try to acquire an exclusive lock file.
68
+ * Returns the file handle if successful, null otherwise.
69
+ */
70
+ declare function tryAcquireLock(lockPath: string): Promise<fssync.promises.FileHandle | null>;
71
+ /**
72
+ * Release the lock file.
73
+ */
74
+ declare function releaseLock(lockPath: string, fh: fssync.promises.FileHandle): Promise<void>;
75
+ /**
76
+ * Generate a random token for daemon authentication.
77
+ */
78
+ declare function randomToken(): string;
79
+ /**
80
+ * Get the path to the daemon entry point.
81
+ *
82
+ * This function handles multiple scenarios:
83
+ * 1. Direct execution from source (development)
84
+ * 2. Execution from dist (production)
85
+ * 3. When re-bundled by another tool (Vitest, esbuild, webpack)
86
+ *
87
+ * We use require.resolve to reliably find the mock-mcp package location,
88
+ * which works even when the code is re-bundled by another tool.
89
+ */
90
+ declare function getDaemonEntryPath(): string;
91
+ /**
92
+ * Ensure the daemon is running for the given project.
93
+ *
94
+ * This function:
95
+ * 1. Checks if a daemon is already running (via registry + health check)
96
+ * 2. If not, acquires a lock and spawns a new daemon
97
+ * 3. Waits for the daemon to become healthy
98
+ * 4. Returns the registry information
99
+ *
100
+ * Thread-safe: multiple processes calling this concurrently will only start one daemon.
101
+ */
102
+ declare function ensureDaemonRunning(opts?: EnsureDaemonOptions): Promise<DaemonRegistry>;
103
+ declare function sleep(ms: number): Promise<void>;
104
+
105
+ export { type DaemonRegistry as D, type EnsureDaemonOptions as E, getPaths as a, readRegistry as b, computeProjectId as c, releaseLock as d, randomToken as e, getDaemonEntryPath as f, getCacheDir as g, healthCheck as h, ensureDaemonRunning as i, type DaemonPaths as j, resolveProjectRoot as r, sleep as s, tryAcquireLock as t, writeRegistry as w };