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
@@ -1,223 +0,0 @@
1
- import WebSocket from "ws";
2
- import { BATCH_MOCK_REQUEST, BATCH_MOCK_RESPONSE, } from "../types.js";
3
- import { isEnabled } from "./util.js";
4
- const DEFAULT_TIMEOUT = 60_000;
5
- const DEFAULT_BATCH_DEBOUNCE_MS = 0;
6
- const DEFAULT_MAX_BATCH_SIZE = 50;
7
- const DEFAULT_PORT = 3002;
8
- /**
9
- * Collects HTTP requests issued during a single macrotask and forwards them to
10
- * the MCP server as a batch for AI-assisted mock generation.
11
- */
12
- export class BatchMockCollector {
13
- ws;
14
- pendingRequests = new Map();
15
- queuedRequestIds = new Set();
16
- timeout;
17
- batchDebounceMs;
18
- maxBatchSize;
19
- logger;
20
- batchTimer = null;
21
- requestIdCounter = 0;
22
- closed = false;
23
- readyResolve;
24
- readyReject;
25
- readyPromise;
26
- constructor(options = {}) {
27
- this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
28
- this.batchDebounceMs = options.batchDebounceMs ?? DEFAULT_BATCH_DEBOUNCE_MS;
29
- this.maxBatchSize = options.maxBatchSize ?? DEFAULT_MAX_BATCH_SIZE;
30
- this.logger = options.logger ?? console;
31
- const port = options.port ?? DEFAULT_PORT;
32
- this.readyPromise = new Promise((resolve, reject) => {
33
- this.readyResolve = resolve;
34
- this.readyReject = reject;
35
- });
36
- const wsUrl = `ws://localhost:${port}`;
37
- this.ws = new WebSocket(wsUrl);
38
- this.setupWebSocket();
39
- }
40
- /**
41
- * Ensures the underlying WebSocket connection is ready for use.
42
- */
43
- async waitUntilReady() {
44
- return this.readyPromise;
45
- }
46
- /**
47
- * Request mock data for a specific endpoint/method pair.
48
- */
49
- async requestMock(endpoint, method, options = {}) {
50
- if (this.closed) {
51
- throw new Error("BatchMockCollector has been closed");
52
- }
53
- await this.waitUntilReady();
54
- const requestId = `req-${++this.requestIdCounter}`;
55
- const request = {
56
- requestId,
57
- endpoint,
58
- method,
59
- body: options.body,
60
- headers: options.headers,
61
- metadata: options.metadata,
62
- };
63
- let settleCompletion;
64
- const completion = new Promise((resolve) => {
65
- settleCompletion = resolve;
66
- });
67
- return new Promise((resolve, reject) => {
68
- const timeoutId = setTimeout(() => {
69
- this.rejectRequest(requestId, new Error(`Mock request timed out after ${this.timeout}ms: ${method} ${endpoint}`));
70
- }, this.timeout);
71
- this.pendingRequests.set(requestId, {
72
- request,
73
- resolve: (data) => {
74
- settleCompletion({ status: "fulfilled", value: undefined });
75
- resolve(data);
76
- },
77
- reject: (error) => {
78
- settleCompletion({ status: "rejected", reason: error });
79
- reject(error);
80
- },
81
- timeoutId,
82
- completion,
83
- });
84
- this.enqueueRequest(requestId);
85
- });
86
- }
87
- /**
88
- * Wait for all requests that are currently pending to settle. Requests
89
- * created after this method is called are not included.
90
- */
91
- async waitForPendingRequests() {
92
- if (!isEnabled()) {
93
- return;
94
- }
95
- const pendingCompletions = Array.from(this.pendingRequests.values()).map((pending) => pending.completion);
96
- const results = await Promise.all(pendingCompletions);
97
- const rejected = results.find((result) => result.status === "rejected");
98
- if (rejected) {
99
- throw rejected.reason;
100
- }
101
- }
102
- /**
103
- * Close the underlying connection and fail all pending requests.
104
- */
105
- async close(code) {
106
- if (this.closed) {
107
- return;
108
- }
109
- this.closed = true;
110
- if (this.batchTimer) {
111
- clearTimeout(this.batchTimer);
112
- this.batchTimer = null;
113
- }
114
- this.queuedRequestIds.clear();
115
- const closePromise = new Promise((resolve) => {
116
- this.ws.once("close", () => resolve());
117
- });
118
- this.ws.close(code);
119
- this.failAllPending(new Error("BatchMockCollector has been closed"));
120
- await closePromise;
121
- }
122
- setupWebSocket() {
123
- this.ws.on("open", () => {
124
- this.logger.log("🔌 Connected to mock MCP WebSocket endpoint");
125
- this.readyResolve?.();
126
- });
127
- this.ws.on("message", (data) => this.handleMessage(data));
128
- this.ws.on("error", (error) => {
129
- this.logger.error("❌ WebSocket error:", error);
130
- this.readyReject?.(error instanceof Error ? error : new Error(String(error)));
131
- this.failAllPending(error instanceof Error ? error : new Error(String(error)));
132
- });
133
- this.ws.on("close", () => {
134
- this.logger.warn("🔌 WebSocket connection closed");
135
- this.failAllPending(new Error("WebSocket connection closed"));
136
- });
137
- }
138
- handleMessage(data) {
139
- let parsed;
140
- try {
141
- parsed = JSON.parse(data.toString());
142
- }
143
- catch (error) {
144
- this.logger.error("Failed to parse server message:", error);
145
- return;
146
- }
147
- if (parsed.type !== BATCH_MOCK_RESPONSE) {
148
- this.logger.warn("Received unsupported message type", parsed.type);
149
- return;
150
- }
151
- this.logger.debug?.(`📦 Received mock data for ${parsed.mocks.length} requests (batch ${parsed.batchId})`);
152
- for (const mock of parsed.mocks) {
153
- this.resolveRequest(mock);
154
- }
155
- }
156
- resolveRequest(mock) {
157
- const pending = this.pendingRequests.get(mock.requestId);
158
- if (!pending) {
159
- this.logger.warn(`Received mock for unknown request: ${mock.requestId}`);
160
- return;
161
- }
162
- clearTimeout(pending.timeoutId);
163
- this.pendingRequests.delete(mock.requestId);
164
- pending.resolve(mock.data);
165
- }
166
- enqueueRequest(requestId) {
167
- this.queuedRequestIds.add(requestId);
168
- if (this.batchTimer) {
169
- return;
170
- }
171
- this.batchTimer = setTimeout(() => {
172
- this.batchTimer = null;
173
- this.flushQueue();
174
- }, this.batchDebounceMs);
175
- }
176
- flushQueue() {
177
- const queuedIds = Array.from(this.queuedRequestIds);
178
- this.queuedRequestIds.clear();
179
- if (queuedIds.length === 0) {
180
- return;
181
- }
182
- for (let i = 0; i < queuedIds.length; i += this.maxBatchSize) {
183
- const chunkIds = queuedIds.slice(i, i + this.maxBatchSize);
184
- const requests = [];
185
- for (const id of chunkIds) {
186
- const pending = this.pendingRequests.get(id);
187
- if (pending) {
188
- requests.push(pending.request);
189
- }
190
- }
191
- if (requests.length > 0) {
192
- this.sendBatch(requests);
193
- }
194
- }
195
- }
196
- sendBatch(requests) {
197
- if (this.ws.readyState !== WebSocket.OPEN) {
198
- const error = new Error("WebSocket is not open");
199
- requests.forEach((request) => this.rejectRequest(request.requestId, error));
200
- return;
201
- }
202
- const payload = {
203
- type: BATCH_MOCK_REQUEST,
204
- requests,
205
- };
206
- this.logger.debug?.(`📤 Sending batch with ${requests.length} request(s) to MCP server`);
207
- this.ws.send(JSON.stringify(payload));
208
- }
209
- rejectRequest(requestId, error) {
210
- const pending = this.pendingRequests.get(requestId);
211
- if (!pending) {
212
- return;
213
- }
214
- clearTimeout(pending.timeoutId);
215
- this.pendingRequests.delete(requestId);
216
- pending.reject(error);
217
- }
218
- failAllPending(error) {
219
- for (const requestId of Array.from(this.pendingRequests.keys())) {
220
- this.rejectRequest(requestId, error);
221
- }
222
- }
223
- }
@@ -1 +0,0 @@
1
- export declare const isEnabled: () => boolean;
@@ -1,3 +0,0 @@
1
- export const isEnabled = () => {
2
- return process.env.MOCK_MCP !== undefined && process.env.MOCK_MCP !== "0";
3
- };
package/dist/connect.cjs DELETED
@@ -1,299 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/client/connect.ts
31
- var connect_exports = {};
32
- __export(connect_exports, {
33
- connect: () => connect
34
- });
35
- module.exports = __toCommonJS(connect_exports);
36
-
37
- // src/client/batch-mock-collector.ts
38
- var import_ws = __toESM(require("ws"), 1);
39
-
40
- // src/types.ts
41
- var BATCH_MOCK_REQUEST = "BATCH_MOCK_REQUEST";
42
- var BATCH_MOCK_RESPONSE = "BATCH_MOCK_RESPONSE";
43
-
44
- // src/client/util.ts
45
- var isEnabled = () => {
46
- return process.env.MOCK_MCP !== void 0 && process.env.MOCK_MCP !== "0";
47
- };
48
-
49
- // src/client/batch-mock-collector.ts
50
- var DEFAULT_TIMEOUT = 6e4;
51
- var DEFAULT_BATCH_DEBOUNCE_MS = 0;
52
- var DEFAULT_MAX_BATCH_SIZE = 50;
53
- var DEFAULT_PORT = 3002;
54
- var BatchMockCollector = class {
55
- ws;
56
- pendingRequests = /* @__PURE__ */ new Map();
57
- queuedRequestIds = /* @__PURE__ */ new Set();
58
- timeout;
59
- batchDebounceMs;
60
- maxBatchSize;
61
- logger;
62
- batchTimer = null;
63
- requestIdCounter = 0;
64
- closed = false;
65
- readyResolve;
66
- readyReject;
67
- readyPromise;
68
- constructor(options = {}) {
69
- this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
70
- this.batchDebounceMs = options.batchDebounceMs ?? DEFAULT_BATCH_DEBOUNCE_MS;
71
- this.maxBatchSize = options.maxBatchSize ?? DEFAULT_MAX_BATCH_SIZE;
72
- this.logger = options.logger ?? console;
73
- const port = options.port ?? DEFAULT_PORT;
74
- this.readyPromise = new Promise((resolve, reject) => {
75
- this.readyResolve = resolve;
76
- this.readyReject = reject;
77
- });
78
- const wsUrl = `ws://localhost:${port}`;
79
- this.ws = new import_ws.default(wsUrl);
80
- this.setupWebSocket();
81
- }
82
- /**
83
- * Ensures the underlying WebSocket connection is ready for use.
84
- */
85
- async waitUntilReady() {
86
- return this.readyPromise;
87
- }
88
- /**
89
- * Request mock data for a specific endpoint/method pair.
90
- */
91
- async requestMock(endpoint, method, options = {}) {
92
- if (this.closed) {
93
- throw new Error("BatchMockCollector has been closed");
94
- }
95
- await this.waitUntilReady();
96
- const requestId = `req-${++this.requestIdCounter}`;
97
- const request = {
98
- requestId,
99
- endpoint,
100
- method,
101
- body: options.body,
102
- headers: options.headers,
103
- metadata: options.metadata
104
- };
105
- let settleCompletion;
106
- const completion = new Promise((resolve) => {
107
- settleCompletion = resolve;
108
- });
109
- return new Promise((resolve, reject) => {
110
- const timeoutId = setTimeout(() => {
111
- this.rejectRequest(
112
- requestId,
113
- new Error(
114
- `Mock request timed out after ${this.timeout}ms: ${method} ${endpoint}`
115
- )
116
- );
117
- }, this.timeout);
118
- this.pendingRequests.set(requestId, {
119
- request,
120
- resolve: (data) => {
121
- settleCompletion({ status: "fulfilled", value: void 0 });
122
- resolve(data);
123
- },
124
- reject: (error) => {
125
- settleCompletion({ status: "rejected", reason: error });
126
- reject(error);
127
- },
128
- timeoutId,
129
- completion
130
- });
131
- this.enqueueRequest(requestId);
132
- });
133
- }
134
- /**
135
- * Wait for all requests that are currently pending to settle. Requests
136
- * created after this method is called are not included.
137
- */
138
- async waitForPendingRequests() {
139
- if (!isEnabled()) {
140
- return;
141
- }
142
- const pendingCompletions = Array.from(this.pendingRequests.values()).map(
143
- (pending) => pending.completion
144
- );
145
- const results = await Promise.all(pendingCompletions);
146
- const rejected = results.find(
147
- (result) => result.status === "rejected"
148
- );
149
- if (rejected) {
150
- throw rejected.reason;
151
- }
152
- }
153
- /**
154
- * Close the underlying connection and fail all pending requests.
155
- */
156
- async close(code) {
157
- if (this.closed) {
158
- return;
159
- }
160
- this.closed = true;
161
- if (this.batchTimer) {
162
- clearTimeout(this.batchTimer);
163
- this.batchTimer = null;
164
- }
165
- this.queuedRequestIds.clear();
166
- const closePromise = new Promise((resolve) => {
167
- this.ws.once("close", () => resolve());
168
- });
169
- this.ws.close(code);
170
- this.failAllPending(new Error("BatchMockCollector has been closed"));
171
- await closePromise;
172
- }
173
- setupWebSocket() {
174
- this.ws.on("open", () => {
175
- this.logger.log("\u{1F50C} Connected to mock MCP WebSocket endpoint");
176
- this.readyResolve?.();
177
- });
178
- this.ws.on("message", (data) => this.handleMessage(data));
179
- this.ws.on("error", (error) => {
180
- this.logger.error("\u274C WebSocket error:", error);
181
- this.readyReject?.(
182
- error instanceof Error ? error : new Error(String(error))
183
- );
184
- this.failAllPending(
185
- error instanceof Error ? error : new Error(String(error))
186
- );
187
- });
188
- this.ws.on("close", () => {
189
- this.logger.warn("\u{1F50C} WebSocket connection closed");
190
- this.failAllPending(new Error("WebSocket connection closed"));
191
- });
192
- }
193
- handleMessage(data) {
194
- let parsed;
195
- try {
196
- parsed = JSON.parse(data.toString());
197
- } catch (error) {
198
- this.logger.error("Failed to parse server message:", error);
199
- return;
200
- }
201
- if (parsed.type !== BATCH_MOCK_RESPONSE) {
202
- this.logger.warn("Received unsupported message type", parsed.type);
203
- return;
204
- }
205
- this.logger.debug?.(
206
- `\u{1F4E6} Received mock data for ${parsed.mocks.length} requests (batch ${parsed.batchId})`
207
- );
208
- for (const mock of parsed.mocks) {
209
- this.resolveRequest(mock);
210
- }
211
- }
212
- resolveRequest(mock) {
213
- const pending = this.pendingRequests.get(mock.requestId);
214
- if (!pending) {
215
- this.logger.warn(`Received mock for unknown request: ${mock.requestId}`);
216
- return;
217
- }
218
- clearTimeout(pending.timeoutId);
219
- this.pendingRequests.delete(mock.requestId);
220
- pending.resolve(mock.data);
221
- }
222
- enqueueRequest(requestId) {
223
- this.queuedRequestIds.add(requestId);
224
- if (this.batchTimer) {
225
- return;
226
- }
227
- this.batchTimer = setTimeout(() => {
228
- this.batchTimer = null;
229
- this.flushQueue();
230
- }, this.batchDebounceMs);
231
- }
232
- flushQueue() {
233
- const queuedIds = Array.from(this.queuedRequestIds);
234
- this.queuedRequestIds.clear();
235
- if (queuedIds.length === 0) {
236
- return;
237
- }
238
- for (let i = 0; i < queuedIds.length; i += this.maxBatchSize) {
239
- const chunkIds = queuedIds.slice(i, i + this.maxBatchSize);
240
- const requests = [];
241
- for (const id of chunkIds) {
242
- const pending = this.pendingRequests.get(id);
243
- if (pending) {
244
- requests.push(pending.request);
245
- }
246
- }
247
- if (requests.length > 0) {
248
- this.sendBatch(requests);
249
- }
250
- }
251
- }
252
- sendBatch(requests) {
253
- if (this.ws.readyState !== import_ws.default.OPEN) {
254
- const error = new Error("WebSocket is not open");
255
- requests.forEach(
256
- (request) => this.rejectRequest(request.requestId, error)
257
- );
258
- return;
259
- }
260
- const payload = {
261
- type: BATCH_MOCK_REQUEST,
262
- requests
263
- };
264
- this.logger.debug?.(
265
- `\u{1F4E4} Sending batch with ${requests.length} request(s) to MCP server`
266
- );
267
- this.ws.send(JSON.stringify(payload));
268
- }
269
- rejectRequest(requestId, error) {
270
- const pending = this.pendingRequests.get(requestId);
271
- if (!pending) {
272
- return;
273
- }
274
- clearTimeout(pending.timeoutId);
275
- this.pendingRequests.delete(requestId);
276
- pending.reject(error);
277
- }
278
- failAllPending(error) {
279
- for (const requestId of Array.from(this.pendingRequests.keys())) {
280
- this.rejectRequest(requestId, error);
281
- }
282
- }
283
- };
284
-
285
- // src/client/connect.ts
286
- var connect = async (options) => {
287
- if (!isEnabled()) {
288
- console.log("[mock-mcp] Skipping (set MOCK_MCP=1 to enable)");
289
- return;
290
- }
291
- const resolvedOptions = typeof options === "number" ? { port: options } : options ?? {};
292
- const collector = new BatchMockCollector(resolvedOptions);
293
- await collector.waitUntilReady();
294
- return collector;
295
- };
296
- // Annotate the CommonJS export names for ESM import in node:
297
- 0 && (module.exports = {
298
- connect
299
- });
@@ -1,95 +0,0 @@
1
- type Logger = Pick<Console, "log" | "warn" | "error"> & {
2
- debug?: (...args: unknown[]) => void;
3
- };
4
- interface BatchMockCollectorOptions {
5
- /**
6
- * TCP port exposed by {@link TestMockMCPServer}.
7
- *
8
- * @default 3002
9
- */
10
- port?: number;
11
- /**
12
- * Timeout for individual mock requests in milliseconds.
13
- *
14
- * @default 60000
15
- */
16
- timeout?: number;
17
- /**
18
- * Delay (in milliseconds) that determines how long the collector waits before
19
- * flushing the current batch. Setting this to 0 mirrors the "flush on the next
20
- * macrotask" approach described in the technical design document.
21
- *
22
- * @default 0
23
- */
24
- batchDebounceMs?: number;
25
- /**
26
- * Maximum number of requests that may be included in a single batch payload.
27
- * Requests that exceed this limit will be split into multiple batches.
28
- *
29
- * @default 50
30
- */
31
- maxBatchSize?: number;
32
- /**
33
- * Optional custom logger. Defaults to `console`.
34
- */
35
- logger?: Logger;
36
- }
37
- interface RequestMockOptions {
38
- body?: unknown;
39
- headers?: Record<string, string>;
40
- metadata?: Record<string, unknown>;
41
- }
42
- /**
43
- * Collects HTTP requests issued during a single macrotask and forwards them to
44
- * the MCP server as a batch for AI-assisted mock generation.
45
- */
46
- declare class BatchMockCollector {
47
- private readonly ws;
48
- private readonly pendingRequests;
49
- private readonly queuedRequestIds;
50
- private readonly timeout;
51
- private readonly batchDebounceMs;
52
- private readonly maxBatchSize;
53
- private readonly logger;
54
- private batchTimer;
55
- private requestIdCounter;
56
- private closed;
57
- private readyResolve?;
58
- private readyReject?;
59
- private readonly readyPromise;
60
- constructor(options?: BatchMockCollectorOptions);
61
- /**
62
- * Ensures the underlying WebSocket connection is ready for use.
63
- */
64
- waitUntilReady(): Promise<void>;
65
- /**
66
- * Request mock data for a specific endpoint/method pair.
67
- */
68
- requestMock<T = unknown>(endpoint: string, method: string, options?: RequestMockOptions): Promise<T>;
69
- /**
70
- * Wait for all requests that are currently pending to settle. Requests
71
- * created after this method is called are not included.
72
- */
73
- waitForPendingRequests(): Promise<void>;
74
- /**
75
- * Close the underlying connection and fail all pending requests.
76
- */
77
- close(code?: number): Promise<void>;
78
- private setupWebSocket;
79
- private handleMessage;
80
- private resolveRequest;
81
- private enqueueRequest;
82
- private flushQueue;
83
- private sendBatch;
84
- private rejectRequest;
85
- private failAllPending;
86
- }
87
-
88
- type ConnectOptions = number | BatchMockCollectorOptions | undefined;
89
- /**
90
- * Convenience helper that creates a {@link BatchMockCollector} and waits for the
91
- * underlying WebSocket connection to become ready before resolving.
92
- */
93
- declare const connect: (options?: ConnectOptions) => Promise<BatchMockCollector | void>;
94
-
95
- export { type ConnectOptions, connect };
@@ -1 +0,0 @@
1
- export { TestMockMCPServer, type TestMockMCPServerOptions, } from "./test-mock-mcp-server.js";
@@ -1 +0,0 @@
1
- export { TestMockMCPServer, } from "./test-mock-mcp-server.js";
@@ -1,73 +0,0 @@
1
- import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
2
- import { type CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
- import { type PendingBatchSummary, type ProvideBatchMockDataArgs } from "../types.js";
4
- type Logger = Pick<Console, "log" | "warn" | "error"> & {
5
- debug?: (...args: unknown[]) => void;
6
- };
7
- export interface TestMockMCPServerOptions {
8
- port?: number;
9
- logger?: Logger;
10
- batchTtlMs?: number;
11
- sweepIntervalMs?: number;
12
- enableMcpTransport?: boolean;
13
- transportFactory?: () => Transport;
14
- serverName?: string;
15
- serverVersion?: string;
16
- mockLogOptions?: MockLogOptions;
17
- }
18
- export interface MockLogOptions {
19
- enabled?: boolean;
20
- directory?: string;
21
- }
22
- /**
23
- * Bridges the integration-test process and the MCP client, making it possible
24
- * to generate realistic mock data on demand.
25
- */
26
- export declare class TestMockMCPServer {
27
- private readonly logger;
28
- private readonly options;
29
- private wss?;
30
- private cleanupTimer?;
31
- private mcpServer?;
32
- private transport?;
33
- private started;
34
- private actualPort?;
35
- private readonly pendingBatches;
36
- private readonly clients;
37
- private batchCounter;
38
- constructor(options?: TestMockMCPServerOptions);
39
- /**
40
- * Start both the WebSocket server (for the test runner) and the MCP server
41
- * (for the AI client).
42
- */
43
- start(): Promise<void>;
44
- /**
45
- * Shut down all transports and clear pending batches.
46
- */
47
- stop(): Promise<void>;
48
- /**
49
- * Expose the TCP port that the WebSocket server is listening on. Useful when
50
- * `port=0` is supplied for ephemeral environments or tests.
51
- */
52
- get port(): number | undefined;
53
- /**
54
- * Return summaries of all batches that are awaiting AI-provided mock data.
55
- */
56
- getPendingBatches(): PendingBatchSummary[];
57
- /**
58
- * Send AI-generated mock data back to the corresponding test process.
59
- */
60
- provideMockData(args: ProvideBatchMockDataArgs): Promise<CallToolResult>;
61
- private startWebSocketServer;
62
- private startMcpServer;
63
- private handleConnection;
64
- private handleClientMessage;
65
- private handleBatchRequest;
66
- private dropBatchesForClient;
67
- private sweepExpiredBatches;
68
- private persistMockBatch;
69
- private buildLogEntry;
70
- private extractBatchContext;
71
- private buildToolResponse;
72
- }
73
- export {};