@mcpmesh/sdk 1.3.4 → 1.4.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.
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Worker entry for the mesh tool worker pool.
3
+ *
4
+ * Launched as a `worker_threads.Worker` from `tool-worker-pool.ts`. Each
5
+ * worker:
6
+ *
7
+ * 1. Resolves the user's `tsx` loader from THEIR node_modules (the Worker
8
+ * `execArgv` does not propagate the parent process's tsx loader, so .ts
9
+ * imports would otherwise throw `ERR_UNKNOWN_FILE_EXTENSION`).
10
+ * 2. Sets a worker-mode symbol on `globalThis` so the SDK skips main-thread
11
+ * init (HTTP server, registry heartbeat, Rust core agent start) when the
12
+ * user module imports `mesh()`.
13
+ * 3. Dynamic-imports the user module — this triggers `agent.addTool(...)` calls
14
+ * which the SDK redirects into a worker-local tool map.
15
+ * 4. Reports `ready` to the parent.
16
+ * 5. Listens for `{kind: "call"}` messages, executes the tool with
17
+ * reconstructed DI proxies + restored ALS scope, and replies with
18
+ * `{kind: "result"}` or `{kind: "error"}`.
19
+ */
20
+ import { parentPort, workerData, isMainThread } from "node:worker_threads";
21
+ import { createRequire } from "node:module";
22
+ import { pathToFileURL } from "node:url";
23
+ if (isMainThread) {
24
+ throw new Error("tool-worker-entry.js must be loaded inside a worker thread");
25
+ }
26
+ if (!parentPort) {
27
+ throw new Error("tool-worker-entry.js requires a parent port");
28
+ }
29
+ const data = workerData;
30
+ const userModulePath = data.userModulePath;
31
+ const sdkEntryPath = data.sdkEntryPath;
32
+ // Mark worker mode BEFORE importing the user module. The SDK checks this
33
+ // symbol in MeshAgent.constructor / addTool to short-circuit main-thread
34
+ // init and stash tool functions in a worker-local map instead.
35
+ const WORKER_MODE_SYMBOL = Symbol.for("@mcpmesh/sdk/worker-mode");
36
+ globalThis[WORKER_MODE_SYMBOL] = true;
37
+ // User-facing in-worker flag. Distinct from the SDK-internal worker-mode flag
38
+ // above. User code can check this to guard their own top-level side effects
39
+ // (custom HTTP servers, OTel init, prometheus registries) that should not
40
+ // run in worker threads. Exported as IN_WORKER_SYMBOL from the SDK index.
41
+ globalThis[Symbol.for("@mcpmesh/sdk/in-worker")] = true;
42
+ async function bootstrap() {
43
+ // 1. Register tsx loader for the worker if user runs .ts directly.
44
+ const isTs = userModulePath.endsWith(".ts") ||
45
+ userModulePath.endsWith(".mts") ||
46
+ userModulePath.endsWith(".cts") ||
47
+ userModulePath.endsWith(".tsx");
48
+ if (isTs) {
49
+ try {
50
+ const userRequire = createRequire(userModulePath);
51
+ const tsxApiPath = userRequire.resolve("tsx/esm/api");
52
+ const tsxApi = await import(pathToFileURL(tsxApiPath).href);
53
+ if (typeof tsxApi.register === "function") {
54
+ tsxApi.register();
55
+ }
56
+ else {
57
+ throw new Error("tsx/esm/api does not export register()");
58
+ }
59
+ }
60
+ catch (e) {
61
+ const msg = "MCP_MESH_TOOL_ISOLATION requires `tsx` in your dependencies when " +
62
+ "running .ts directly. Add `tsx` to package.json or set " +
63
+ "MCP_MESH_TOOL_ISOLATION=false to disable isolation.";
64
+ parentPort.postMessage({
65
+ kind: "fatal",
66
+ error: {
67
+ name: "TsxResolutionError",
68
+ message: msg,
69
+ cause: String(e),
70
+ },
71
+ });
72
+ process.exit(1);
73
+ return;
74
+ }
75
+ }
76
+ // 2. Import the SDK first so the worker-mode flag takes effect before the
77
+ // user's import of mesh() touches MeshAgent.constructor.
78
+ const sdk = await import(pathToFileURL(sdkEntryPath).href);
79
+ // 3. Import the user's module — fires addTool() calls.
80
+ await import(pathToFileURL(userModulePath).href);
81
+ // 4. Pull the tool map populated during user module init.
82
+ const tools = typeof sdk.__getWorkerToolMap === "function"
83
+ ? sdk.__getWorkerToolMap()
84
+ : new Map();
85
+ // 5. Get ALS helpers + proxy factory for per-call setup.
86
+ const { createProxy, runWithTraceContext, runWithPropagatedHeaders } = sdk;
87
+ parentPort.on("message", (msg) => {
88
+ handleMessage(msg, tools, createProxy, runWithTraceContext, runWithPropagatedHeaders);
89
+ });
90
+ parentPort.postMessage({ kind: "ready" });
91
+ }
92
+ function serializeError(err) {
93
+ if (!(err instanceof Error)) {
94
+ return { name: "Error", message: String(err) };
95
+ }
96
+ const out = { name: err.name, message: err.message, stack: err.stack };
97
+ const errAny = err;
98
+ if (errAny.code !== undefined)
99
+ out.code = errAny.code;
100
+ if (errAny.cause !== undefined)
101
+ out.cause = serializeError(errAny.cause);
102
+ return out;
103
+ }
104
+ function handleMessage(msg, tools, createProxy, runWithTraceContext, runWithPropagatedHeaders) {
105
+ if (!msg || typeof msg !== "object")
106
+ return;
107
+ const m = msg;
108
+ if (m.kind !== "call" || typeof m.id !== "number")
109
+ return;
110
+ const respond = (payload) => {
111
+ parentPort.postMessage({ id: m.id, ...payload });
112
+ };
113
+ const tool = tools.get(m.toolName);
114
+ if (!tool) {
115
+ respond({
116
+ kind: "error",
117
+ error: {
118
+ name: "ToolNotFound",
119
+ message: `Tool '${m.toolName}' not registered in worker`,
120
+ },
121
+ });
122
+ return;
123
+ }
124
+ // Reconstruct DI proxies — workers can't share the main-thread proxies, so
125
+ // each worker builds its own with its own undici Agent (Python parity).
126
+ const deps = m.depsConfig.map((cfg) => cfg === null
127
+ ? null
128
+ : createProxy(cfg.endpoint, cfg.capability, cfg.functionName, cfg.kwargs));
129
+ // Restore ALS scopes so user code sees the same trace context + headers as
130
+ // the main-thread caller, then invoke the tool. When traceContext is null,
131
+ // skip runWithTraceContext entirely so user's getCurrentTraceContext()
132
+ // returns null — matching the MCP_MESH_TOOL_ISOLATION=false legacy path.
133
+ const headers = m.propagatedHeaders ?? {};
134
+ const invokeUser = () => runWithPropagatedHeaders(headers, () => tool(m.cleanArgs, ...deps));
135
+ const wrapWithTrace = () => m.traceContext === null
136
+ ? invokeUser()
137
+ : runWithTraceContext(m.traceContext, invokeUser);
138
+ Promise.resolve()
139
+ .then(wrapWithTrace)
140
+ .then((value) => respond({ kind: "result", value }))
141
+ .catch((err) => {
142
+ respond({ kind: "error", error: serializeError(err) });
143
+ });
144
+ }
145
+ bootstrap().catch((e) => {
146
+ const err = e;
147
+ try {
148
+ parentPort.postMessage({
149
+ kind: "fatal",
150
+ error: {
151
+ name: err?.name ?? "Error",
152
+ message: err?.message ?? String(e),
153
+ stack: err?.stack,
154
+ },
155
+ });
156
+ }
157
+ catch {
158
+ // ignore
159
+ }
160
+ process.exit(1);
161
+ });
162
+ //# sourceMappingURL=tool-worker-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-worker-entry.js","sourceRoot":"","sources":["../src/tool-worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,IAAI,YAAY,EAAE,CAAC;IACjB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;AAChF,CAAC;AACD,IAAI,CAAC,UAAU,EAAE,CAAC;IAChB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;AACjE,CAAC;AAQD,MAAM,IAAI,GAAG,UAAwB,CAAC;AACtC,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;AAC3C,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;AAEvC,yEAAyE;AACzE,yEAAyE;AACzE,+DAA+D;AAC/D,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AACjE,UAAiD,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC;AAE9E,8EAA8E;AAC9E,4EAA4E;AAC5E,0EAA0E;AAC1E,0EAA0E;AACzE,UAAkB,CAAC,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC,GAAG,IAAI,CAAC;AAEjE,KAAK,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,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAChE,CAAC;IAEJ,MAAM,aAAa,GAAG,GAAG,EAAE,CACzB,CAAC,CAAC,YAAY,KAAK,IAAI;QACrB,CAAC,CAAC,UAAU,EAAE;QACd,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAEtD,OAAO,CAAC,OAAO,EAAE;SACd,IAAI,CAAC,aAAa,CAAC;SACnB,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;SACnD,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;QACtB,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;IAC/B,MAAM,GAAG,GAAG,CAAU,CAAC;IACvB,IAAI,CAAC;QACH,UAAW,CAAC,WAAW,CAAC;YACtB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,GAAG,EAAE,IAAI,IAAI,OAAO;gBAC1B,OAAO,EAAE,GAAG,EAAE,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC;gBAClC,KAAK,EAAE,GAAG,EAAE,KAAK;aAClB;SACF,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,SAAS;IACX,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Tool worker pool for isolating user tool execution from the main event loop.
3
+ *
4
+ * Mirrors the Python `_mcp_mesh.shared.tool_executor` design: spawn N worker
5
+ * threads (V8 isolates here, since Node has no GIL/asyncio split), each with
6
+ * its own event loop and undici connection pool, and dispatch tool calls
7
+ * round-robin across them. A user's blocking call (`execFileSync`, CPU spin,
8
+ * etc.) blocks one worker thread, NOT the main thread that serves
9
+ * /health, /ready, FastMCP HTTP, and registry heartbeats.
10
+ *
11
+ * Pool size:
12
+ * Default `min(8, max(2, os.availableParallelism() ?? 2))`.
13
+ * Override via `MCP_MESH_TOOL_WORKERS=<N>`.
14
+ *
15
+ * The pool is created lazily on first dispatch (matches Python parity) and
16
+ * cached for the process lifetime. Workers that crash are respawned on the
17
+ * next dispatch.
18
+ */
19
+ export interface DepConfig {
20
+ endpoint: string;
21
+ capability: string;
22
+ functionName: string;
23
+ kwargs: Record<string, unknown>;
24
+ }
25
+ export interface DispatchPayload {
26
+ toolName: string;
27
+ cleanArgs: unknown;
28
+ depsConfig: (DepConfig | null)[];
29
+ traceContext: unknown;
30
+ propagatedHeaders: Record<string, string>;
31
+ }
32
+ /**
33
+ * Dispatch a tool call to a worker.
34
+ *
35
+ * Round-robin selects a worker, awaits its readiness (first call only),
36
+ * sends the payload, and resolves with the worker's `{result}` or rejects
37
+ * with its `{error}`. Worker crashes propagate as a rejection.
38
+ */
39
+ export declare function dispatch(payload: DispatchPayload): Promise<unknown>;
40
+ /**
41
+ * Drain in-flight calls (up to deadlineMs), then forcefully terminate all
42
+ * workers. Calls still pending after the deadline are rejected with a
43
+ * descriptive error.
44
+ *
45
+ * Called automatically on `process.exit`; can be invoked explicitly during
46
+ * shutdown if you want to await completion.
47
+ */
48
+ export declare function closePool(deadlineMs?: number): Promise<void>;
49
+ //# sourceMappingURL=tool-worker-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-worker-pool.d.ts","sourceRoot":"","sources":["../src/tool-worker-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAQH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC;IACjC,YAAY,EAAE,OAAO,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AA4MD;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAiCzE;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,UAAU,SAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BhE"}
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Tool worker pool for isolating user tool execution from the main event loop.
3
+ *
4
+ * Mirrors the Python `_mcp_mesh.shared.tool_executor` design: spawn N worker
5
+ * threads (V8 isolates here, since Node has no GIL/asyncio split), each with
6
+ * its own event loop and undici connection pool, and dispatch tool calls
7
+ * round-robin across them. A user's blocking call (`execFileSync`, CPU spin,
8
+ * etc.) blocks one worker thread, NOT the main thread that serves
9
+ * /health, /ready, FastMCP HTTP, and registry heartbeats.
10
+ *
11
+ * Pool size:
12
+ * Default `min(8, max(2, os.availableParallelism() ?? 2))`.
13
+ * Override via `MCP_MESH_TOOL_WORKERS=<N>`.
14
+ *
15
+ * The pool is created lazily on first dispatch (matches Python parity) and
16
+ * cached for the process lifetime. Workers that crash are respawned on the
17
+ * next dispatch.
18
+ */
19
+ import { Worker } from "node:worker_threads";
20
+ import { fileURLToPath } from "node:url";
21
+ import os from "node:os";
22
+ import path from "node:path";
23
+ import fs from "node:fs";
24
+ const _slots = [];
25
+ let _poolSize = 0;
26
+ let _initialized = false;
27
+ let _nextIdx = 0;
28
+ let _msgId = 0;
29
+ let _shutdownRegistered = false;
30
+ function deserializeError(serialized) {
31
+ const err = new Error(serialized?.message ?? "worker error");
32
+ if (serialized?.name)
33
+ err.name = serialized.name;
34
+ if (serialized?.stack)
35
+ err.stack = serialized.stack;
36
+ if (serialized?.code !== undefined)
37
+ err.code = serialized.code;
38
+ if (serialized?.cause !== undefined)
39
+ err.cause = deserializeError(serialized.cause);
40
+ return err;
41
+ }
42
+ function _resolvePoolSize() {
43
+ const envVal = process.env.MCP_MESH_TOOL_WORKERS;
44
+ if (envVal) {
45
+ const n = parseInt(envVal, 10);
46
+ if (!isNaN(n) && n >= 1)
47
+ return n;
48
+ console.warn(`MCP_MESH_TOOL_WORKERS=${envVal} is invalid; falling back to default`);
49
+ }
50
+ // os.availableParallelism is Node 19.4+; fall back to cpus().length.
51
+ const cpu = typeof os.availableParallelism === "function"
52
+ ? os.availableParallelism()
53
+ : os.cpus().length || 2;
54
+ return Math.min(8, Math.max(2, cpu || 2));
55
+ }
56
+ function _resolveWorkerEntryPath() {
57
+ // tool-worker-pool.js sits next to tool-worker-entry.js in dist/.
58
+ const here = fileURLToPath(import.meta.url);
59
+ return path.join(path.dirname(here), "tool-worker-entry.js");
60
+ }
61
+ function _resolveSdkEntryPath() {
62
+ // dist/tool-worker-pool.js → dist/index.js
63
+ const here = fileURLToPath(import.meta.url);
64
+ return path.join(path.dirname(here), "index.js");
65
+ }
66
+ function _resolveUserModulePath() {
67
+ // process.argv[1] is the user's entry script when launched via `npx tsx <file>`
68
+ // or `node <file>`. Resolve to absolute for consistent worker resolution.
69
+ const argv1 = process.argv[1];
70
+ if (!argv1) {
71
+ throw new Error("Cannot determine user module path for worker isolation: process.argv[1] is empty. " +
72
+ "Mesh worker isolation expects the agent entry to be the launched script. " +
73
+ "If you have an unusual launch context, set MCP_MESH_TOOL_ISOLATION=false to disable isolation.");
74
+ }
75
+ const resolved = path.resolve(argv1);
76
+ if (!fs.existsSync(resolved)) {
77
+ throw new Error(`User module path does not exist: ${resolved} (resolved from process.argv[1]=${argv1}). ` +
78
+ "Set MCP_MESH_TOOL_ISOLATION=false to disable worker isolation.");
79
+ }
80
+ return resolved;
81
+ }
82
+ function _initPool() {
83
+ if (_initialized)
84
+ return;
85
+ _initialized = true;
86
+ _poolSize = _resolvePoolSize();
87
+ for (let i = 0; i < _poolSize; i++) {
88
+ _slots.push({ worker: null, ready: null, pending: new Map(), alive: false });
89
+ }
90
+ if (!_shutdownRegistered) {
91
+ _shutdownRegistered = true;
92
+ process.once("exit", () => {
93
+ // Synchronous best-effort termination on exit.
94
+ for (const slot of _slots) {
95
+ if (slot.worker) {
96
+ try {
97
+ slot.worker.terminate();
98
+ }
99
+ catch {
100
+ // ignore
101
+ }
102
+ }
103
+ }
104
+ });
105
+ }
106
+ }
107
+ function _spawnWorker(slot, slotIdx) {
108
+ const workerEntry = _resolveWorkerEntryPath();
109
+ const userModulePath = _resolveUserModulePath();
110
+ const sdkEntryPath = _resolveSdkEntryPath();
111
+ const worker = new Worker(workerEntry, {
112
+ workerData: {
113
+ userModulePath,
114
+ sdkEntryPath,
115
+ slotIdx,
116
+ },
117
+ });
118
+ slot.worker = worker;
119
+ slot.alive = true;
120
+ slot.pending = new Map();
121
+ slot.ready = new Promise((resolveReady, rejectReady) => {
122
+ let readyResolved = false;
123
+ worker.on("message", (msg) => {
124
+ if (msg && msg.kind === "ready") {
125
+ if (!readyResolved) {
126
+ readyResolved = true;
127
+ resolveReady();
128
+ }
129
+ return;
130
+ }
131
+ if (msg && msg.kind === "fatal") {
132
+ const err = new Error(msg.error?.message ?? "Worker fatal error during init");
133
+ if (msg.error?.name)
134
+ err.name = msg.error.name;
135
+ if (!readyResolved) {
136
+ readyResolved = true;
137
+ rejectReady(err);
138
+ }
139
+ // Fail any in-flight calls too.
140
+ for (const [, pending] of slot.pending)
141
+ pending.reject(err);
142
+ slot.pending.clear();
143
+ slot.alive = false;
144
+ return;
145
+ }
146
+ if (msg && typeof msg.id === "number") {
147
+ const pending = slot.pending.get(msg.id);
148
+ if (!pending)
149
+ return;
150
+ slot.pending.delete(msg.id);
151
+ if (msg.kind === "result") {
152
+ pending.resolve(msg.value);
153
+ }
154
+ else if (msg.kind === "error") {
155
+ pending.reject(deserializeError(msg.error));
156
+ }
157
+ }
158
+ });
159
+ worker.on("error", (err) => {
160
+ slot.alive = false;
161
+ if (!readyResolved) {
162
+ readyResolved = true;
163
+ rejectReady(err);
164
+ }
165
+ for (const [, pending] of slot.pending)
166
+ pending.reject(err);
167
+ slot.pending.clear();
168
+ slot.worker = null;
169
+ slot.ready = null;
170
+ });
171
+ worker.on("exit", (code) => {
172
+ slot.alive = false;
173
+ if (slot.pending.size > 0) {
174
+ const err = new Error(`Worker exited (code=${code}) with pending calls`);
175
+ for (const [, pending] of slot.pending)
176
+ pending.reject(err);
177
+ slot.pending.clear();
178
+ }
179
+ if (!readyResolved) {
180
+ readyResolved = true;
181
+ rejectReady(new Error(`Worker exited (code=${code}) before ready`));
182
+ }
183
+ slot.worker = null;
184
+ slot.ready = null;
185
+ });
186
+ });
187
+ }
188
+ function _pickSlot() {
189
+ const idx = _nextIdx % _poolSize;
190
+ _nextIdx = (_nextIdx + 1) % _poolSize;
191
+ const slot = _slots[idx];
192
+ if (!slot.worker || !slot.alive) {
193
+ _spawnWorker(slot, idx);
194
+ }
195
+ return slot;
196
+ }
197
+ /**
198
+ * Dispatch a tool call to a worker.
199
+ *
200
+ * Round-robin selects a worker, awaits its readiness (first call only),
201
+ * sends the payload, and resolves with the worker's `{result}` or rejects
202
+ * with its `{error}`. Worker crashes propagate as a rejection.
203
+ */
204
+ export async function dispatch(payload) {
205
+ _initPool();
206
+ const slot = _pickSlot();
207
+ // Wait for readiness before enqueuing the first call. After ready, pending
208
+ // calls are buffered by Node's MessagePort regardless.
209
+ if (slot.ready) {
210
+ await slot.ready;
211
+ }
212
+ const id = ++_msgId;
213
+ return new Promise((resolve, reject) => {
214
+ slot.pending.set(id, { resolve, reject });
215
+ if (!slot.worker) {
216
+ slot.pending.delete(id);
217
+ reject(new Error("Worker died during dispatch"));
218
+ return;
219
+ }
220
+ try {
221
+ slot.worker.postMessage({
222
+ id,
223
+ kind: "call",
224
+ toolName: payload.toolName,
225
+ cleanArgs: payload.cleanArgs,
226
+ depsConfig: payload.depsConfig,
227
+ traceContext: payload.traceContext,
228
+ propagatedHeaders: payload.propagatedHeaders,
229
+ });
230
+ }
231
+ catch (err) {
232
+ slot.pending.delete(id);
233
+ reject(err instanceof Error ? err : new Error(String(err)));
234
+ }
235
+ });
236
+ }
237
+ /**
238
+ * Drain in-flight calls (up to deadlineMs), then forcefully terminate all
239
+ * workers. Calls still pending after the deadline are rejected with a
240
+ * descriptive error.
241
+ *
242
+ * Called automatically on `process.exit`; can be invoked explicitly during
243
+ * shutdown if you want to await completion.
244
+ */
245
+ export async function closePool(deadlineMs = 5000) {
246
+ if (!_initialized)
247
+ return;
248
+ const workers = _slots.slice();
249
+ _slots.length = 0;
250
+ _initialized = false;
251
+ _poolSize = 0;
252
+ _nextIdx = 0;
253
+ // Phase 1: drain — wait up to `deadlineMs` for in-flight calls to finish.
254
+ const deadline = Date.now() + deadlineMs;
255
+ for (const slot of workers) {
256
+ while (slot.pending.size > 0 && Date.now() < deadline) {
257
+ await new Promise((r) => setTimeout(r, 50));
258
+ }
259
+ }
260
+ // Phase 2: reject anything still pending after the deadline.
261
+ for (const slot of workers) {
262
+ if (slot.pending.size > 0) {
263
+ const err = new Error(`Worker pool closed with ${slot.pending.size} in-flight call(s) still pending after ${deadlineMs}ms drain`);
264
+ for (const [, pending] of slot.pending)
265
+ pending.reject(err);
266
+ slot.pending.clear();
267
+ }
268
+ }
269
+ // Phase 3: terminate workers.
270
+ await Promise.all(workers.map((s) => (s.worker ? s.worker.terminate().catch(() => undefined) : Promise.resolve())));
271
+ }
272
+ //# sourceMappingURL=tool-worker-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-worker-pool.js","sourceRoot":"","sources":["../src/tool-worker-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;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4
4
  "description": "TypeScript SDK for MCP Mesh — build distributed AI agents with auto-discovery, dependency injection, and LLM integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -33,8 +33,9 @@
33
33
  "dependencies": {
34
34
  "@ai-sdk/anthropic": "^3.0.0",
35
35
  "@ai-sdk/google": "^3.0.0",
36
+ "@ai-sdk/google-vertex": "^3.0.0",
36
37
  "@ai-sdk/openai": "^3.0.0",
37
- "@mcpmesh/core": "1.3.4",
38
+ "@mcpmesh/core": "1.4.1",
38
39
  "ai": "^6.0.0",
39
40
  "fastmcp": "^3.34.0",
40
41
  "mcp-proxy": "6.4.4",