@finalai/agent-provider 0.2.3 → 0.4.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 +61 -0
- package/dist/modules/sandbox/client.mjs +3 -0
- package/dist/modules/sandbox/client.mjs.map +2 -2
- package/dist/modules/sandbox/confined-files.d.mts +2 -2
- package/dist/modules/sandbox/confined-files.mjs +5 -2
- package/dist/modules/sandbox/confined-files.mjs.map +2 -2
- package/dist/modules/sandbox/execution-guard.d.mts +36 -0
- package/dist/modules/sandbox/execution-guard.mjs +322 -0
- package/dist/modules/sandbox/execution-guard.mjs.map +7 -0
- package/dist/modules/sandbox/file-kind.d.mts +6 -0
- package/dist/modules/sandbox/file-kind.mjs +11 -0
- package/dist/modules/sandbox/file-kind.mjs.map +7 -0
- package/dist/modules/sandbox/file-schemas.d.mts +15 -0
- package/dist/modules/sandbox/file-schemas.mjs +22 -0
- package/dist/modules/sandbox/file-schemas.mjs.map +7 -0
- package/dist/modules/sandbox/handle.d.mts +15 -0
- package/dist/modules/sandbox/handle.mjs +47 -0
- package/dist/modules/sandbox/handle.mjs.map +7 -0
- package/dist/modules/sandbox/index.d.mts +8 -0
- package/dist/modules/sandbox/index.mjs +30 -1
- package/dist/modules/sandbox/index.mjs.map +2 -2
- package/dist/modules/sandbox/mcp-channel.d.mts +8 -1
- package/dist/modules/sandbox/mcp-channel.mjs +217 -15
- package/dist/modules/sandbox/mcp-channel.mjs.map +3 -3
- package/dist/modules/sandbox/mcp-hosted-marker.d.mts +3 -0
- package/dist/modules/sandbox/mcp-hosted-marker.mjs +10 -0
- package/dist/modules/sandbox/mcp-hosted-marker.mjs.map +7 -0
- package/dist/modules/sandbox/mcp-hosted.d.mts +6 -1
- package/dist/modules/sandbox/mcp-hosted.mjs +127 -41
- package/dist/modules/sandbox/mcp-hosted.mjs.map +2 -2
- package/dist/modules/sandbox/mcp-shell.mjs +14 -4
- package/dist/modules/sandbox/mcp-shell.mjs.map +2 -2
- package/dist/modules/sandbox/mcp.d.mts +5 -2
- package/dist/modules/sandbox/mcp.mjs +102 -27
- package/dist/modules/sandbox/mcp.mjs.map +2 -2
- package/dist/modules/sandbox/networking.d.mts +73 -0
- package/dist/modules/sandbox/networking.mjs +149 -0
- package/dist/modules/sandbox/networking.mjs.map +7 -0
- package/dist/modules/sandbox/overrides.d.mts +2 -0
- package/dist/modules/sandbox/overrides.mjs +44 -0
- package/dist/modules/sandbox/overrides.mjs.map +7 -0
- package/dist/modules/sandbox/server.d.mts +1 -0
- package/dist/modules/sandbox/server.mjs +38 -2
- package/dist/modules/sandbox/server.mjs.map +2 -2
- package/dist/modules/sandbox/testing.d.mts +1 -0
- package/dist/modules/sandbox/testing.mjs +1 -0
- package/dist/modules/sandbox/testing.mjs.map +2 -2
- package/dist/modules/sandbox/tool-policy.d.mts +5 -0
- package/dist/modules/sandbox/tool-policy.mjs +62 -0
- package/dist/modules/sandbox/tool-policy.mjs.map +7 -0
- package/dist/modules/sandbox/types.d.mts +17 -16
- package/dist/modules/sandbox/types.mjs +54 -23
- package/dist/modules/sandbox/types.mjs.map +3 -3
- package/dist/modules/sandbox/wire.d.mts +23 -18
- package/dist/modules/sandbox/wire.mjs +21 -20
- package/dist/modules/sandbox/wire.mjs.map +3 -3
- package/dist/modules/sandbox/workspace-identity.d.mts +5 -0
- package/dist/modules/sandbox/workspace-identity.mjs +14 -0
- package/dist/modules/sandbox/workspace-identity.mjs.map +7 -0
- package/package.json +2 -2
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { type Transport } from '@modelcontextprotocol/client';
|
|
2
|
-
import type { McpChannelIface } from "./types.mjs";
|
|
2
|
+
import type { McpChannelIface, McpChannelEndpointIface, McpEndpointIface } from "./types.mjs";
|
|
3
|
+
export declare const mcpMessageNotSent: unique symbol;
|
|
3
4
|
export interface McpChannelTransportArgsIface {
|
|
4
5
|
channel: McpChannelIface;
|
|
6
|
+
receiveWhileIdle?: boolean;
|
|
5
7
|
sleep?: (ms: number) => Promise<void>;
|
|
6
8
|
pollMinMs?: number;
|
|
7
9
|
pollMaxMs?: number;
|
|
8
10
|
}
|
|
9
11
|
export declare const createMcpChannelTransport: (args: McpChannelTransportArgsIface) => Transport;
|
|
12
|
+
interface HttpMcpChannelOptionsIface {
|
|
13
|
+
beforeRequest?: () => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare const createHttpMcpChannelEndpoint: (endpoint: McpEndpointIface, fetch?: typeof globalThis.fetch, guardOptions?: HttpMcpChannelOptionsIface) => McpChannelEndpointIface;
|
|
16
|
+
export {};
|
|
@@ -1,58 +1,121 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
1
2
|
import {
|
|
3
|
+
SdkError,
|
|
4
|
+
SdkErrorCode,
|
|
5
|
+
StreamableHTTPClientTransport,
|
|
2
6
|
isJSONRPCRequest,
|
|
3
7
|
isJSONRPCResponse,
|
|
4
8
|
parseJSONRPCMessage
|
|
5
9
|
} from "@modelcontextprotocol/client";
|
|
6
10
|
import { jsonValueSchema } from "../json.mjs";
|
|
11
|
+
const mcpMessageNotSent = /* @__PURE__ */ Symbol("mcpMessageNotSent");
|
|
7
12
|
const POLL_MIN_MS = 25;
|
|
8
13
|
const POLL_MAX_MS = 1e3;
|
|
9
14
|
const INTERNAL_ERROR = -32603;
|
|
10
|
-
const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
15
|
const createMcpChannelTransport = (args) => {
|
|
12
|
-
const sleep = args.sleep ?? defaultSleep;
|
|
13
16
|
const pollMinMs = args.pollMinMs ?? POLL_MIN_MS;
|
|
14
17
|
const pollMaxMs = args.pollMaxMs ?? POLL_MAX_MS;
|
|
15
18
|
const pending = /* @__PURE__ */ new Set();
|
|
19
|
+
const requestControllers = /* @__PURE__ */ new Map();
|
|
16
20
|
let polling = null;
|
|
17
21
|
let closed = false;
|
|
22
|
+
let closing = null;
|
|
23
|
+
let wakePoll = null;
|
|
24
|
+
let activity = 0;
|
|
25
|
+
const pause = (ms) => new Promise((resolve, reject) => {
|
|
26
|
+
let timer;
|
|
27
|
+
const done = (woken = true) => {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
if (wakePoll === done) wakePoll = null;
|
|
30
|
+
resolve(woken);
|
|
31
|
+
};
|
|
32
|
+
wakePoll = done;
|
|
33
|
+
if (args.sleep == null) timer = setTimeout(() => done(false), ms);
|
|
34
|
+
else void args.sleep(ms).then(() => done(false), reject);
|
|
35
|
+
});
|
|
18
36
|
const transport = {
|
|
19
|
-
start: async () =>
|
|
20
|
-
|
|
37
|
+
start: async () => {
|
|
38
|
+
if (args.receiveWhileIdle === false) return;
|
|
39
|
+
startPolling();
|
|
40
|
+
},
|
|
41
|
+
send: async (message, options) => {
|
|
21
42
|
if (closed) throw new Error("the MCP channel is closed");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
43
|
+
const requestId = isJSONRPCRequest(message) ? message.id : null;
|
|
44
|
+
const requestController = requestId == null ? null : new AbortController();
|
|
45
|
+
if (requestId != null && requestController != null) {
|
|
46
|
+
requestControllers.set(requestId, requestController);
|
|
47
|
+
pending.add(requestId);
|
|
48
|
+
activity++;
|
|
49
|
+
wakePoll?.();
|
|
50
|
+
} else {
|
|
51
|
+
const cancelled = z.object({
|
|
52
|
+
method: z.literal("notifications/cancelled"),
|
|
53
|
+
params: z.object({ requestId: z.union([z.string(), z.number()]) })
|
|
54
|
+
}).safeParse(message);
|
|
55
|
+
if (cancelled.success) {
|
|
56
|
+
const id = cancelled.data.params.requestId;
|
|
57
|
+
requestControllers.get(id)?.abort(new Error("MCP request cancelled"));
|
|
58
|
+
requestControllers.delete(id);
|
|
59
|
+
pending.delete(id);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
await args.channel.send(jsonValueSchema.parse(JSON.parse(JSON.stringify(message))), {
|
|
64
|
+
abortSignal: requestController == null ? options?.requestSignal : AbortSignal.any([
|
|
65
|
+
requestController.signal,
|
|
66
|
+
...options?.requestSignal == null ? [] : [options.requestSignal]
|
|
67
|
+
])
|
|
27
68
|
});
|
|
69
|
+
wakePoll?.();
|
|
70
|
+
} catch (cause) {
|
|
71
|
+
if (requestId != null) {
|
|
72
|
+
pending.delete(requestId);
|
|
73
|
+
requestControllers.delete(requestId);
|
|
74
|
+
}
|
|
75
|
+
throw cause;
|
|
28
76
|
}
|
|
77
|
+
if (pending.size > 0) startPolling();
|
|
29
78
|
},
|
|
30
79
|
close: async () => {
|
|
80
|
+
if (closing != null) return closing;
|
|
31
81
|
if (closed) return;
|
|
32
82
|
closed = true;
|
|
83
|
+
wakePoll?.();
|
|
33
84
|
pending.clear();
|
|
34
|
-
|
|
85
|
+
for (const controller of requestControllers.values())
|
|
86
|
+
controller.abort(new Error("MCP channel closed"));
|
|
87
|
+
requestControllers.clear();
|
|
35
88
|
transport.onclose?.();
|
|
89
|
+
closing = args.channel.close().catch(() => void 0);
|
|
90
|
+
await closing;
|
|
36
91
|
}
|
|
37
92
|
};
|
|
38
93
|
const deliver = (message) => {
|
|
39
|
-
if (isJSONRPCResponse(message) && message.id != null)
|
|
94
|
+
if (isJSONRPCResponse(message) && message.id != null) {
|
|
95
|
+
pending.delete(message.id);
|
|
96
|
+
requestControllers.delete(message.id);
|
|
97
|
+
}
|
|
40
98
|
transport.onmessage?.(message);
|
|
41
99
|
};
|
|
42
100
|
const failPending = (error) => {
|
|
43
101
|
transport.onerror?.(error);
|
|
44
102
|
for (const id of [...pending]) {
|
|
103
|
+
requestControllers.get(id)?.abort(error);
|
|
45
104
|
deliver({ jsonrpc: "2.0", id, error: { code: INTERNAL_ERROR, message: error.message } });
|
|
46
105
|
}
|
|
47
106
|
};
|
|
48
107
|
const poll = async () => {
|
|
49
108
|
let delay = pollMinMs;
|
|
50
|
-
while (!closed && pending.size > 0) {
|
|
109
|
+
while (!closed && (args.receiveWhileIdle !== false || pending.size > 0)) {
|
|
51
110
|
let messages;
|
|
111
|
+
const receivingActivity = activity;
|
|
52
112
|
try {
|
|
53
113
|
messages = await args.channel.receive();
|
|
114
|
+
if (closed) return;
|
|
54
115
|
} catch (error) {
|
|
116
|
+
if (closed) return;
|
|
55
117
|
failPending(error instanceof Error ? error : new Error(String(error)));
|
|
118
|
+
await transport.close();
|
|
56
119
|
return;
|
|
57
120
|
}
|
|
58
121
|
for (const raw of messages) {
|
|
@@ -65,13 +128,152 @@ const createMcpChannelTransport = (args) => {
|
|
|
65
128
|
delay = pollMinMs;
|
|
66
129
|
continue;
|
|
67
130
|
}
|
|
68
|
-
|
|
69
|
-
|
|
131
|
+
if (activity !== receivingActivity) {
|
|
132
|
+
delay = pollMinMs;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const woken = await pause(delay);
|
|
136
|
+
delay = woken ? pollMinMs : Math.min(delay * 2, pollMaxMs);
|
|
70
137
|
}
|
|
71
138
|
};
|
|
139
|
+
const startPolling = () => {
|
|
140
|
+
if (closed || polling != null) return;
|
|
141
|
+
polling = poll().catch(async (cause) => {
|
|
142
|
+
if (!closed) {
|
|
143
|
+
failPending(cause instanceof Error ? cause : new Error(String(cause)));
|
|
144
|
+
await transport.close();
|
|
145
|
+
}
|
|
146
|
+
}).finally(() => {
|
|
147
|
+
polling = null;
|
|
148
|
+
if (!closed && pending.size > 0) startPolling();
|
|
149
|
+
});
|
|
150
|
+
};
|
|
72
151
|
return transport;
|
|
73
152
|
};
|
|
153
|
+
const createHttpMcpChannelEndpoint = (endpoint, fetch, guardOptions) => ({
|
|
154
|
+
name: endpoint.name,
|
|
155
|
+
connect: async (options) => {
|
|
156
|
+
options?.abortSignal?.throwIfAborted();
|
|
157
|
+
const lifetime = new AbortController();
|
|
158
|
+
let closed = false;
|
|
159
|
+
let failure = null;
|
|
160
|
+
const transport = new StreamableHTTPClientTransport(new URL(endpoint.url), {
|
|
161
|
+
requestInit: { headers: endpoint.headers },
|
|
162
|
+
fetch: async (input, init) => {
|
|
163
|
+
lifetime.signal.throwIfAborted();
|
|
164
|
+
if (closed && init?.method !== "DELETE") throw new Error("Hosted MCP channel is closed");
|
|
165
|
+
if (!closed) {
|
|
166
|
+
try {
|
|
167
|
+
await guardOptions?.beforeRequest?.();
|
|
168
|
+
} catch (cause) {
|
|
169
|
+
failure = new SdkError(
|
|
170
|
+
SdkErrorCode.ConnectionClosed,
|
|
171
|
+
cause instanceof Error ? cause.message : String(cause)
|
|
172
|
+
);
|
|
173
|
+
void close().catch(() => void 0);
|
|
174
|
+
throw failure;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
lifetime.signal.throwIfAborted();
|
|
178
|
+
if (closed && init?.method !== "DELETE") throw new Error("Hosted MCP channel is closed");
|
|
179
|
+
const response = await (fetch ?? globalThis.fetch)(input, {
|
|
180
|
+
...init,
|
|
181
|
+
signal: AbortSignal.any([
|
|
182
|
+
lifetime.signal,
|
|
183
|
+
...init?.signal == null ? [] : [init.signal]
|
|
184
|
+
])
|
|
185
|
+
});
|
|
186
|
+
if (response.status === 404 && ["POST", "GET"].includes(init?.method ?? "GET") && transport.sessionId != null) {
|
|
187
|
+
failure = Object.assign(
|
|
188
|
+
new SdkError(SdkErrorCode.ConnectionClosed, "Hosted MCP session no longer exists"),
|
|
189
|
+
{ [mcpMessageNotSent]: true }
|
|
190
|
+
);
|
|
191
|
+
await response.body?.cancel();
|
|
192
|
+
throw failure;
|
|
193
|
+
}
|
|
194
|
+
return response;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
const inbox = [];
|
|
198
|
+
let inboxBytes = 0;
|
|
199
|
+
let closing = null;
|
|
200
|
+
const close = () => closing ??= (async () => {
|
|
201
|
+
closed = true;
|
|
202
|
+
let deadline;
|
|
203
|
+
const timedOut = new Promise((resolve) => {
|
|
204
|
+
deadline = setTimeout(() => {
|
|
205
|
+
lifetime.abort();
|
|
206
|
+
resolve();
|
|
207
|
+
}, 5e3);
|
|
208
|
+
});
|
|
209
|
+
try {
|
|
210
|
+
await Promise.race([transport.terminateSession().catch(() => void 0), timedOut]);
|
|
211
|
+
} finally {
|
|
212
|
+
clearTimeout(deadline);
|
|
213
|
+
lifetime.abort();
|
|
214
|
+
await transport.close();
|
|
215
|
+
}
|
|
216
|
+
})();
|
|
217
|
+
let initializationId = null;
|
|
218
|
+
transport.onclose = () => {
|
|
219
|
+
if (!closed)
|
|
220
|
+
failure ??= new SdkError(SdkErrorCode.ConnectionClosed, "Hosted MCP transport closed");
|
|
221
|
+
};
|
|
222
|
+
transport.onmessage = (message) => {
|
|
223
|
+
if (closed) return;
|
|
224
|
+
if (isJSONRPCResponse(message) && message.id === initializationId) {
|
|
225
|
+
const initialized = z.object({ result: z.object({ protocolVersion: z.string() }) }).safeParse(message);
|
|
226
|
+
if (initialized.success)
|
|
227
|
+
transport.setProtocolVersion(initialized.data.result.protocolVersion);
|
|
228
|
+
}
|
|
229
|
+
const encoded = JSON.stringify(message);
|
|
230
|
+
const bytes = new TextEncoder().encode(encoded).byteLength;
|
|
231
|
+
if (inbox.length >= 4096 || inboxBytes + bytes > 16 * 1024 * 1024) {
|
|
232
|
+
failure = new SdkError(
|
|
233
|
+
SdkErrorCode.ConnectionClosed,
|
|
234
|
+
"Hosted MCP receive buffer exceeded its limit"
|
|
235
|
+
);
|
|
236
|
+
void close().catch(() => void 0);
|
|
237
|
+
} else {
|
|
238
|
+
inbox.push(jsonValueSchema.parse(JSON.parse(encoded)));
|
|
239
|
+
inboxBytes += bytes;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
await transport.start();
|
|
243
|
+
return {
|
|
244
|
+
send: async (message, options2) => {
|
|
245
|
+
options2?.abortSignal?.throwIfAborted();
|
|
246
|
+
if (failure != null || closed)
|
|
247
|
+
throw Object.assign(
|
|
248
|
+
new SdkError(
|
|
249
|
+
SdkErrorCode.ConnectionClosed,
|
|
250
|
+
failure?.message ?? "Hosted MCP channel is closed"
|
|
251
|
+
),
|
|
252
|
+
{ [mcpMessageNotSent]: true }
|
|
253
|
+
);
|
|
254
|
+
const parsed = parseJSONRPCMessage(message);
|
|
255
|
+
if (isJSONRPCRequest(parsed) && parsed.method === "initialize")
|
|
256
|
+
initializationId = parsed.id;
|
|
257
|
+
await transport.send(parsed, { requestSignal: options2?.abortSignal });
|
|
258
|
+
},
|
|
259
|
+
receive: async (options2) => {
|
|
260
|
+
options2?.abortSignal?.throwIfAborted();
|
|
261
|
+
if (inbox.length > 0) {
|
|
262
|
+
inboxBytes = 0;
|
|
263
|
+
return inbox.splice(0);
|
|
264
|
+
}
|
|
265
|
+
if (failure != null) throw failure;
|
|
266
|
+
if (closed)
|
|
267
|
+
throw new SdkError(SdkErrorCode.ConnectionClosed, "Hosted MCP channel is closed");
|
|
268
|
+
return [];
|
|
269
|
+
},
|
|
270
|
+
close
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
});
|
|
74
274
|
export {
|
|
75
|
-
|
|
275
|
+
createHttpMcpChannelEndpoint,
|
|
276
|
+
createMcpChannelTransport,
|
|
277
|
+
mcpMessageNotSent
|
|
76
278
|
};
|
|
77
279
|
//# sourceMappingURL=mcp-channel.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/sandbox/mcp-channel.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n isJSONRPCRequest,\n isJSONRPCResponse,\n parseJSONRPCMessage,\n type JSONRPCMessage,\n type Transport,\n} from '@modelcontextprotocol/client';\nimport { jsonValueSchema } from \"../json.mjs\";\nimport type { McpChannelIface } from \"./types.mjs\";\n\n// An MCP client transport over a sandbox's MCP channel (types.ts\n// McpChannelIface). The channel only answers `receive` with what has arrived,\n// so the transport polls it while requests are outstanding, quickly at first\n// and backing off while the server is busy; an idle channel is not polled.\n\nconst POLL_MIN_MS = 25;\nconst POLL_MAX_MS = 1_000;\nconst INTERNAL_ERROR = -32603;\n\nexport interface McpChannelTransportArgsIface {\n channel: McpChannelIface;\n sleep?: (ms: number) => Promise<void>;\n pollMinMs?: number;\n pollMaxMs?: number;\n}\n\nconst defaultSleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));\n\nexport const createMcpChannelTransport = (args: McpChannelTransportArgsIface): Transport => {\n const sleep = args.sleep ?? defaultSleep;\n const pollMinMs = args.pollMinMs ?? POLL_MIN_MS;\n const pollMaxMs = args.pollMaxMs ?? POLL_MAX_MS;\n // Ids of our requests still waiting for a response.\n const pending = new Set<string | number>();\n let polling: Promise<void> | null = null;\n let closed = false;\n\n const transport: Transport = {\n start: async () => undefined,\n send: async (message) => {\n if (closed) throw new Error('the MCP channel is closed');\n await args.channel.send(jsonValueSchema.parse(JSON.parse(JSON.stringify(message))));\n if (isJSONRPCRequest(message)) {\n pending.add(message.id);\n polling ??= poll().finally(() => {\n polling = null;\n });\n }\n },\n close: async () => {\n if (closed) return;\n closed = true;\n pending.clear();\n await args.channel.close().catch(() => undefined);\n transport.onclose?.();\n },\n };\n\n const deliver = (message: JSONRPCMessage) => {\n if (isJSONRPCResponse(message) && message.id != null) pending.delete(message.id);\n transport.onmessage?.(message);\n };\n\n // A channel that failed answers every outstanding request with the error, so\n // callers fail at once instead of at their request timeout.\n const failPending = (error: Error) => {\n transport.onerror?.(error);\n for (const id of [...pending]) {\n deliver({ jsonrpc: '2.0', id, error: { code: INTERNAL_ERROR, message: error.message } });\n }\n };\n\n const poll = async (): Promise<void> => {\n let delay = pollMinMs;\n while (!closed && pending.size > 0) {\n let messages;\n try {\n messages = await args.channel.receive();\n } catch (error) {\n failPending(error instanceof Error ? error : new Error(String(error)));\n return;\n }\n for (const raw of messages) {\n try {\n deliver(parseJSONRPCMessage(raw));\n } catch {\n // Not JSON-RPC; dropped.\n }\n }\n if (messages.length > 0) {\n delay = pollMinMs;\n continue;\n }\n await sleep(delay);\n delay = Math.min(delay * 2, pollMaxMs);\n }\n };\n\n return transport;\n};\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport {\n SdkError,\n SdkErrorCode,\n StreamableHTTPClientTransport,\n isJSONRPCRequest,\n isJSONRPCResponse,\n parseJSONRPCMessage,\n type JSONRPCMessage,\n type Transport,\n} from '@modelcontextprotocol/client';\nimport { jsonValueSchema, type JsonValue } from \"../json.mjs\";\nimport type { McpChannelIface, McpChannelEndpointIface, McpEndpointIface } from \"./types.mjs\";\n\n// An MCP client transport over a sandbox's MCP channel (types.ts\n// McpChannelIface). The channel only answers `receive` with what has arrived,\n// so the transport polls with bounded backoff, including while idle to deliver\n// server notifications and requests without waiting for another client call.\n\n// Only local owned transports can prove a request has not been sent; this is not a wire field.\nexport const mcpMessageNotSent = Symbol('mcpMessageNotSent');\n\nconst POLL_MIN_MS = 25;\nconst POLL_MAX_MS = 1_000;\nconst INTERNAL_ERROR = -32603;\n\nexport interface McpChannelTransportArgsIface {\n channel: McpChannelIface;\n receiveWhileIdle?: boolean;\n sleep?: (ms: number) => Promise<void>;\n pollMinMs?: number;\n pollMaxMs?: number;\n}\n\nexport const createMcpChannelTransport = (args: McpChannelTransportArgsIface): Transport => {\n const pollMinMs = args.pollMinMs ?? POLL_MIN_MS;\n const pollMaxMs = args.pollMaxMs ?? POLL_MAX_MS;\n // Ids of our requests still waiting for a response.\n const pending = new Set<string | number>();\n const requestControllers = new Map<string | number, AbortController>();\n let polling: Promise<void> | null = null;\n let closed = false;\n let closing: Promise<void> | null = null;\n let wakePoll: (() => void) | null = null;\n let activity = 0;\n const pause = (ms: number): Promise<boolean> =>\n new Promise((resolve, reject) => {\n let timer: ReturnType<typeof setTimeout> | undefined;\n const done = (woken = true) => {\n clearTimeout(timer);\n if (wakePoll === done) wakePoll = null;\n resolve(woken);\n };\n wakePoll = done;\n if (args.sleep == null) timer = setTimeout(() => done(false), ms);\n else void args.sleep(ms).then(() => done(false), reject);\n });\n\n const transport: Transport = {\n start: async () => {\n if (args.receiveWhileIdle === false) return;\n startPolling();\n },\n send: async (message, options) => {\n if (closed) throw new Error('the MCP channel is closed');\n const requestId = isJSONRPCRequest(message) ? message.id : null;\n const requestController = requestId == null ? null : new AbortController();\n if (requestId != null && requestController != null) {\n requestControllers.set(requestId, requestController);\n pending.add(requestId);\n activity++;\n wakePoll?.();\n } else {\n const cancelled = z\n .object({\n method: z.literal('notifications/cancelled'),\n params: z.object({ requestId: z.union([z.string(), z.number()]) }),\n })\n .safeParse(message);\n if (cancelled.success) {\n const id = cancelled.data.params.requestId;\n requestControllers.get(id)?.abort(new Error('MCP request cancelled'));\n requestControllers.delete(id);\n pending.delete(id);\n }\n }\n try {\n await args.channel.send(jsonValueSchema.parse(JSON.parse(JSON.stringify(message))), {\n abortSignal:\n requestController == null\n ? options?.requestSignal\n : AbortSignal.any([\n requestController.signal,\n ...(options?.requestSignal == null ? [] : [options.requestSignal]),\n ]),\n });\n wakePoll?.();\n } catch (cause) {\n if (requestId != null) {\n pending.delete(requestId);\n requestControllers.delete(requestId);\n }\n throw cause;\n }\n if (pending.size > 0) startPolling();\n },\n close: async () => {\n if (closing != null) return closing;\n if (closed) return;\n closed = true;\n wakePoll?.();\n pending.clear();\n for (const controller of requestControllers.values())\n controller.abort(new Error('MCP channel closed'));\n requestControllers.clear();\n transport.onclose?.();\n closing = args.channel.close().catch(() => undefined);\n await closing;\n },\n };\n\n const deliver = (message: JSONRPCMessage) => {\n if (isJSONRPCResponse(message) && message.id != null) {\n pending.delete(message.id);\n requestControllers.delete(message.id);\n }\n transport.onmessage?.(message);\n };\n\n // A channel that failed answers every outstanding request with the error, so\n // callers fail at once instead of at their request timeout.\n const failPending = (error: Error) => {\n transport.onerror?.(error);\n for (const id of [...pending]) {\n requestControllers.get(id)?.abort(error);\n deliver({ jsonrpc: '2.0', id, error: { code: INTERNAL_ERROR, message: error.message } });\n }\n };\n\n const poll = async (): Promise<void> => {\n let delay = pollMinMs;\n while (!closed && (args.receiveWhileIdle !== false || pending.size > 0)) {\n let messages;\n const receivingActivity = activity;\n try {\n messages = await args.channel.receive();\n if (closed) return;\n } catch (error) {\n if (closed) return;\n failPending(error instanceof Error ? error : new Error(String(error)));\n await transport.close();\n return;\n }\n for (const raw of messages) {\n try {\n deliver(parseJSONRPCMessage(raw));\n } catch {\n // Not JSON-RPC; dropped.\n }\n }\n if (messages.length > 0) {\n delay = pollMinMs;\n continue;\n }\n if (activity !== receivingActivity) {\n delay = pollMinMs;\n continue;\n }\n const woken = await pause(delay);\n delay = woken ? pollMinMs : Math.min(delay * 2, pollMaxMs);\n }\n };\n\n const startPolling = () => {\n if (closed || polling != null) return;\n polling = poll()\n .catch(async (cause: unknown) => {\n if (!closed) {\n failPending(cause instanceof Error ? cause : new Error(String(cause)));\n await transport.close();\n }\n })\n .finally(() => {\n polling = null;\n // A new request can arrive after poll returns but before this finalizer runs.\n if (!closed && pending.size > 0) startPolling();\n });\n };\n\n return transport;\n};\n\ninterface HttpMcpChannelOptionsIface {\n beforeRequest?: () => Promise<void>;\n}\n\n// Convert URL endpoints into an owned channel so a host can guard every outgoing message.\nexport const createHttpMcpChannelEndpoint = (\n endpoint: McpEndpointIface,\n fetch?: typeof globalThis.fetch,\n guardOptions?: HttpMcpChannelOptionsIface,\n): McpChannelEndpointIface => ({\n name: endpoint.name,\n connect: async (options) => {\n options?.abortSignal?.throwIfAborted();\n const lifetime = new AbortController();\n let closed = false;\n let failure: Error | null = null;\n const transport = new StreamableHTTPClientTransport(new URL(endpoint.url), {\n requestInit: { headers: endpoint.headers },\n fetch: async (input, init) => {\n lifetime.signal.throwIfAborted();\n if (closed && init?.method !== 'DELETE') throw new Error('Hosted MCP channel is closed');\n // Permit owned-session DELETE cleanup after revocation; every new stream is guarded.\n if (!closed) {\n try {\n await guardOptions?.beforeRequest?.();\n } catch (cause) {\n failure = new SdkError(\n SdkErrorCode.ConnectionClosed,\n cause instanceof Error ? cause.message : String(cause),\n );\n void close().catch(() => undefined);\n throw failure;\n }\n }\n lifetime.signal.throwIfAborted();\n if (closed && init?.method !== 'DELETE') throw new Error('Hosted MCP channel is closed');\n const response = await (fetch ?? globalThis.fetch)(input, {\n ...init,\n signal: AbortSignal.any([\n lifetime.signal,\n ...(init?.signal == null ? [] : [init.signal]),\n ]),\n });\n if (\n response.status === 404 &&\n ['POST', 'GET'].includes(init?.method ?? 'GET') &&\n transport.sessionId != null\n ) {\n failure = Object.assign(\n new SdkError(SdkErrorCode.ConnectionClosed, 'Hosted MCP session no longer exists'),\n { [mcpMessageNotSent]: true },\n );\n await response.body?.cancel();\n throw failure;\n }\n return response;\n },\n });\n const inbox: JsonValue[] = [];\n let inboxBytes = 0;\n let closing: Promise<void> | null = null;\n const close = (): Promise<void> =>\n (closing ??= (async () => {\n closed = true;\n let deadline: ReturnType<typeof setTimeout> | undefined;\n const timedOut = new Promise<void>((resolve) => {\n deadline = setTimeout(() => {\n lifetime.abort();\n resolve();\n }, 5000);\n });\n try {\n await Promise.race([transport.terminateSession().catch(() => undefined), timedOut]);\n } finally {\n clearTimeout(deadline);\n lifetime.abort();\n await transport.close();\n }\n })());\n let initializationId: string | number | null = null;\n transport.onclose = () => {\n if (!closed)\n failure ??= new SdkError(SdkErrorCode.ConnectionClosed, 'Hosted MCP transport closed');\n };\n // A failed POST rejects only its send; SDK SSE recovery retains the other requests.\n transport.onmessage = (message) => {\n if (closed) return;\n if (isJSONRPCResponse(message) && message.id === initializationId) {\n const initialized = z\n .object({ result: z.object({ protocolVersion: z.string() }) })\n .safeParse(message);\n if (initialized.success)\n transport.setProtocolVersion(initialized.data.result.protocolVersion);\n }\n const encoded = JSON.stringify(message);\n const bytes = new TextEncoder().encode(encoded).byteLength;\n if (inbox.length >= 4096 || inboxBytes + bytes > 16 * 1024 * 1024) {\n failure = new SdkError(\n SdkErrorCode.ConnectionClosed,\n 'Hosted MCP receive buffer exceeded its limit',\n );\n void close().catch(() => undefined);\n } else {\n inbox.push(jsonValueSchema.parse(JSON.parse(encoded)));\n inboxBytes += bytes;\n }\n };\n await transport.start();\n return {\n send: async (message, options) => {\n options?.abortSignal?.throwIfAborted();\n if (failure != null || closed)\n throw Object.assign(\n new SdkError(\n SdkErrorCode.ConnectionClosed,\n failure?.message ?? 'Hosted MCP channel is closed',\n ),\n { [mcpMessageNotSent]: true },\n );\n const parsed = parseJSONRPCMessage(message);\n if (isJSONRPCRequest(parsed) && parsed.method === 'initialize')\n initializationId = parsed.id;\n await transport.send(parsed, { requestSignal: options?.abortSignal });\n },\n receive: async (options) => {\n options?.abortSignal?.throwIfAborted();\n if (inbox.length > 0) {\n inboxBytes = 0;\n return inbox.splice(0);\n }\n if (failure != null) throw failure;\n if (closed)\n throw new SdkError(SdkErrorCode.ConnectionClosed, 'Hosted MCP channel is closed');\n return [];\n },\n close,\n };\n },\n});\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,OAAO;AACnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,uBAAuC;AASzC,MAAM,oBAAoB,uBAAO,mBAAmB;AAE3D,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAUhB,MAAM,4BAA4B,CAAC,SAAkD;AAC1F,QAAM,YAAY,KAAK,aAAa;AACpC,QAAM,YAAY,KAAK,aAAa;AAEpC,QAAM,UAAU,oBAAI,IAAqB;AACzC,QAAM,qBAAqB,oBAAI,IAAsC;AACrE,MAAI,UAAgC;AACpC,MAAI,SAAS;AACb,MAAI,UAAgC;AACpC,MAAI,WAAgC;AACpC,MAAI,WAAW;AACf,QAAM,QAAQ,CAAC,OACb,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC/B,QAAI;AACJ,UAAM,OAAO,CAAC,QAAQ,SAAS;AAC7B,mBAAa,KAAK;AAClB,UAAI,aAAa,KAAM,YAAW;AAClC,cAAQ,KAAK;AAAA,IACf;AACA,eAAW;AACX,QAAI,KAAK,SAAS,KAAM,SAAQ,WA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AC9B;AACF,cAAM,SAAS,oBAAoB,OAAO;AAC1C,YAAI,iBAAiB,MAAM,KAAK,OAAO,WAAW;AAChD,6BAAmB,OAAO;AAC5B,cAAM,UAAU,KAAK,QAAQ,EAAE,eAAeA,UAAS,YAAY,CAAC;AAAA,MACtE;AAAA,MACA,SAAS,OAAOA,aAAY;AAC1B,QAAAA,UAAS,aAAa,eAAe;AACrC,YAAI,MAAM,SAAS,GAAG;AACpB,uBAAa;AACb,iBAAO,MAAM,OAAO,CAAC;AAAA,QACvB;AACA,YAAI,WAAW,KAAM,OAAM;AAC3B,YAAI;AACF,gBAAM,IAAI,SAAS,aAAa,kBAAkB,8BAA8B;AAClF,eAAO,CAAC;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["options"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const marker = /* @__PURE__ */ Symbol("hostedMcpEndpoints");
|
|
2
|
+
const hasHostedMcpEndpoints = (sandbox) => Reflect.get(sandbox, marker) === true;
|
|
3
|
+
const markHostedMcpEndpoints = (sandbox) => {
|
|
4
|
+
Object.defineProperty(sandbox, marker, { value: true, enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
hasHostedMcpEndpoints,
|
|
8
|
+
markHostedMcpEndpoints
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=mcp-hosted-marker.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/sandbox/mcp-hosted-marker.ts"],
|
|
4
|
+
"sourcesContent": ["import type { NetworkSandboxSessionIface } from \"./types.mjs\";\n\nconst marker = Symbol('hostedMcpEndpoints');\nexport const hasHostedMcpEndpoints = (sandbox: NetworkSandboxSessionIface): boolean =>\n Reflect.get(sandbox, marker) === true;\nexport const markHostedMcpEndpoints = (sandbox: NetworkSandboxSessionIface): void => {\n Object.defineProperty(sandbox, marker, { value: true, enumerable: true });\n};\n"],
|
|
5
|
+
"mappings": "AAEA,MAAM,SAAS,uBAAO,oBAAoB;AACnC,MAAM,wBAAwB,CAAC,YACpC,QAAQ,IAAI,SAAS,MAAM,MAAM;AAC5B,MAAM,yBAAyB,CAAC,YAA8C;AACnF,SAAO,eAAe,SAAS,QAAQ,EAAE,OAAO,MAAM,YAAY,KAAK,CAAC;AAC1E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -27,9 +27,13 @@ export declare const hostedTools: (args: {
|
|
|
27
27
|
localMcp: boolean;
|
|
28
28
|
localServer?: string;
|
|
29
29
|
taken: ReadonlySet<string>;
|
|
30
|
+
reserveEgress?: boolean;
|
|
30
31
|
}) => HostedToolIface[];
|
|
32
|
+
export interface HostedMcpCallOptionsIface {
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}
|
|
31
35
|
export interface HostedMcpConnectionsIface {
|
|
32
|
-
call(server: SandboxHostedServer, tool: string, input: JsonObject): Promise<CallToolResult>;
|
|
36
|
+
call(server: SandboxHostedServer, tool: string, input: JsonObject, options?: HostedMcpCallOptionsIface): Promise<CallToolResult>;
|
|
33
37
|
tools(server: SandboxHostedServer): Promise<ToolDescriptorIface[]>;
|
|
34
38
|
learn(sandbox: NetworkSandboxSessionIface, needed: {
|
|
35
39
|
computerUse: boolean;
|
|
@@ -42,5 +46,6 @@ export declare const createHostedMcpConnections: (args: {
|
|
|
42
46
|
fetch?: FetchLike;
|
|
43
47
|
name?: string;
|
|
44
48
|
version?: string;
|
|
49
|
+
catalog?: () => SandboxMcpCatalogIface;
|
|
45
50
|
}) => HostedMcpConnectionsIface;
|
|
46
51
|
export declare const withHostedMcpEndpoints: <S extends NetworkSandboxSessionIface>(sandbox: S, endpointFor: (server: SandboxHostedServer) => McpEndpointIface) => S;
|