agents 0.19.0 → 0.20.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 +24 -19
- package/dist/{agent-tool-types-BNUGGBzQ.d.ts → agent-tool-types-Btk9ETS-.d.ts} +997 -356
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-BFbzVLFc.d.ts → agent-tools-UuScsJg3.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/browser/ai.js +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/chat/index.d.ts +2 -2
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/client-invoker-BNSZxAkv.d.ts +20 -0
- package/dist/client-invoker-VNZ7X0nn.js +57 -0
- package/dist/client-invoker-VNZ7X0nn.js.map +1 -0
- package/dist/{client-CcjiFpTf.js → client-zqKcsyFa.js} +434 -168
- package/dist/client-zqKcsyFa.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/{connector-CdldGF3h.js → connector-KEJnl6e5.js} +2 -2
- package/dist/connector-KEJnl6e5.js.map +1 -0
- package/dist/{do-oauth-client-provider-D4ZwyBDu.d.ts → do-oauth-client-provider-VTZj2VtM.d.ts} +23 -11
- package/dist/experimental/webmcp.js +1 -1
- package/dist/handler-stateless-8hQN_kC3.js +367 -0
- package/dist/handler-stateless-8hQN_kC3.js.map +1 -0
- package/dist/handler-stateless-C_bo-Ytq.d.ts +107 -0
- package/dist/index.d.ts +12 -12
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +22 -18
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/do-oauth-client-provider.js +25 -12
- package/dist/mcp/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/index.d.ts +48 -34
- package/dist/mcp/index.js +84 -79
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/server.d.ts +17 -0
- package/dist/mcp/server.js +2 -0
- package/dist/mcp/x402.d.ts +21 -9
- package/dist/mcp/x402.js +8 -7
- package/dist/mcp/x402.js.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/sub-routing.d.ts +6 -6
- package/dist/workflows.d.ts +1 -1
- package/docs/human-in-the-loop.md +63 -82
- package/docs/mcp-client.md +31 -7
- package/docs/mcp-servers.md +125 -88
- package/docs/securing-mcp-servers.md +9 -6
- package/package.json +28 -7
- package/dist/client-CcjiFpTf.js.map +0 -1
- package/dist/connector-CdldGF3h.js.map +0 -1
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { WebStandardStreamableHTTPServerTransport, createMcpHandler, hostHeaderValidationResponse, isJSONRPCRequest, isLegacyRequest, localhostAllowedHostnames, localhostAllowedOrigins, originValidationResponse } from "@modelcontextprotocol/server";
|
|
3
|
+
//#region src/mcp/sse-keepalive.ts
|
|
4
|
+
/**
|
|
5
|
+
* Shared SSE keepalive utility for MCP transports.
|
|
6
|
+
*
|
|
7
|
+
* Cloudflare's edge closes idle SSE responses after ~5 minutes. Writers
|
|
8
|
+
* that may sit silent for that long (long-running tool calls, idle
|
|
9
|
+
* standalone GET streams) arm a keepalive to keep the response under the
|
|
10
|
+
* watchdog.
|
|
11
|
+
*
|
|
12
|
+
* See cloudflare/agents#1583.
|
|
13
|
+
*/
|
|
14
|
+
/** Interval between SSE keepalive comment frames, in ms.
|
|
15
|
+
*
|
|
16
|
+
* The WHATWG SSE spec recommends a comment line every "15 seconds or so"
|
|
17
|
+
* (html.spec.whatwg.org §9.2.7). 25s gives comfortable headroom below
|
|
18
|
+
* both the ~30s post-handler background-work cancellation window on
|
|
19
|
+
* Workers and the ~5min Cloudflare edge idle-stream watchdog.
|
|
20
|
+
*/
|
|
21
|
+
const KEEPALIVE_INTERVAL_MS = 25e3;
|
|
22
|
+
/** SSE comment frame the parser drops before any event dispatch. */
|
|
23
|
+
const KEEPALIVE_FRAME = ": keepalive\n\n";
|
|
24
|
+
/**
|
|
25
|
+
* Start an SSE keepalive on `writer`. Returns a `clearInterval` handle
|
|
26
|
+
* that the stream cleanup must invoke when the stream closes.
|
|
27
|
+
*/
|
|
28
|
+
function startKeepalive(writer, encoder) {
|
|
29
|
+
const handle = setInterval(() => {
|
|
30
|
+
writer.write(encoder.encode(KEEPALIVE_FRAME)).catch(() => clearInterval(handle));
|
|
31
|
+
}, KEEPALIVE_INTERVAL_MS);
|
|
32
|
+
return handle;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/mcp/auth-context.ts
|
|
36
|
+
const VERIFIED_OAUTH_CONTEXT = Symbol.for("cloudflare.workers-oauth-provider.verified-context.v1");
|
|
37
|
+
const authContextStorage = new AsyncLocalStorage();
|
|
38
|
+
function getMcpAuthContext() {
|
|
39
|
+
return authContextStorage.getStore();
|
|
40
|
+
}
|
|
41
|
+
function runWithAuthContext(context, fn) {
|
|
42
|
+
return authContextStorage.run(context, fn);
|
|
43
|
+
}
|
|
44
|
+
function isPlainRecord(value) {
|
|
45
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
46
|
+
const prototype = Object.getPrototypeOf(value);
|
|
47
|
+
return prototype === Object.prototype || prototype === null;
|
|
48
|
+
}
|
|
49
|
+
function invalidVerifiedContext() {
|
|
50
|
+
throw new TypeError("Invalid verified OAuth request context");
|
|
51
|
+
}
|
|
52
|
+
function getVerifiedOAuthAuthInfo(ctx) {
|
|
53
|
+
const symbolContext = ctx;
|
|
54
|
+
if (!(VERIFIED_OAUTH_CONTEXT in symbolContext)) return void 0;
|
|
55
|
+
const value = symbolContext[VERIFIED_OAUTH_CONTEXT];
|
|
56
|
+
if (!isPlainRecord(value) || value.version !== 1) invalidVerifiedContext();
|
|
57
|
+
const { token, clientId, scopes, expiresAt, resource, props } = value;
|
|
58
|
+
if (typeof token !== "string" || token.length === 0 || typeof clientId !== "string" || clientId.length === 0 || !Array.isArray(scopes) || !scopes.every((scope) => typeof scope === "string") || !isPlainRecord(props)) invalidVerifiedContext();
|
|
59
|
+
if (expiresAt !== void 0 && (typeof expiresAt !== "number" || !Number.isFinite(expiresAt) || expiresAt <= 0)) invalidVerifiedContext();
|
|
60
|
+
let resourceUrl;
|
|
61
|
+
if (resource !== void 0) {
|
|
62
|
+
if (typeof resource !== "string") invalidVerifiedContext();
|
|
63
|
+
try {
|
|
64
|
+
resourceUrl = new URL(resource);
|
|
65
|
+
} catch {
|
|
66
|
+
invalidVerifiedContext();
|
|
67
|
+
}
|
|
68
|
+
if (resourceUrl.protocol !== "http:" && resourceUrl.protocol !== "https:") invalidVerifiedContext();
|
|
69
|
+
}
|
|
70
|
+
if (ctx.props !== props) invalidVerifiedContext();
|
|
71
|
+
return {
|
|
72
|
+
props,
|
|
73
|
+
authInfo: {
|
|
74
|
+
token,
|
|
75
|
+
clientId,
|
|
76
|
+
scopes: [...scopes],
|
|
77
|
+
...expiresAt !== void 0 && { expiresAt },
|
|
78
|
+
...resourceUrl !== void 0 && { resource: resourceUrl },
|
|
79
|
+
extra: { props }
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/mcp/handler-errors.ts
|
|
85
|
+
function internalErrorResponse(id = null) {
|
|
86
|
+
return Response.json({
|
|
87
|
+
jsonrpc: "2.0",
|
|
88
|
+
error: {
|
|
89
|
+
code: -32603,
|
|
90
|
+
message: "Internal server error"
|
|
91
|
+
},
|
|
92
|
+
id
|
|
93
|
+
}, { status: 500 });
|
|
94
|
+
}
|
|
95
|
+
function requestIdFromParsedBody(body) {
|
|
96
|
+
if (typeof body !== "object" || body === null || Array.isArray(body) || !("method" in body) || typeof body.method !== "string" || !("id" in body)) return null;
|
|
97
|
+
return typeof body.id === "string" || typeof body.id === "number" ? body.id : null;
|
|
98
|
+
}
|
|
99
|
+
function reportHandlerError(onerror, error) {
|
|
100
|
+
try {
|
|
101
|
+
onerror?.(error instanceof Error ? error : new Error(String(error)));
|
|
102
|
+
} catch {}
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/mcp/handler-legacy-compat.ts
|
|
106
|
+
/**
|
|
107
|
+
* Temporary adapter for Legacy compatibility on the SDK v2 transport.
|
|
108
|
+
*
|
|
109
|
+
* Local deltas from the upstream stateless fallback:
|
|
110
|
+
*
|
|
111
|
+
* - impossible stateless server-to-client requests fail immediately rather
|
|
112
|
+
* than leaving the tool handler waiting for a session response;
|
|
113
|
+
* - streamed POST responses receive Cloudflare's 25-second SSE keepalive.
|
|
114
|
+
*
|
|
115
|
+
* Remove this adapter once the SDK exposes both policies directly.
|
|
116
|
+
*/
|
|
117
|
+
function createLegacyCompatibilityRequestHandler(factory, onerror) {
|
|
118
|
+
const fetch = async (request, options) => {
|
|
119
|
+
if (request.method.toUpperCase() !== "POST") return Response.json({
|
|
120
|
+
jsonrpc: "2.0",
|
|
121
|
+
error: {
|
|
122
|
+
code: -32e3,
|
|
123
|
+
message: "Method not allowed."
|
|
124
|
+
},
|
|
125
|
+
id: null
|
|
126
|
+
}, { status: 405 });
|
|
127
|
+
if (request.signal.aborted) return new Response(null, { status: 499 });
|
|
128
|
+
let product;
|
|
129
|
+
let transport;
|
|
130
|
+
let clearResponseKeepalive = () => {};
|
|
131
|
+
let teardownPromise;
|
|
132
|
+
const teardown = () => teardownPromise ??= (async () => {
|
|
133
|
+
clearResponseKeepalive();
|
|
134
|
+
await Promise.all([transport?.close().catch(() => {}), product?.close().catch(() => {})]);
|
|
135
|
+
})();
|
|
136
|
+
const onAbort = () => void teardown();
|
|
137
|
+
try {
|
|
138
|
+
product = await factory({
|
|
139
|
+
era: "legacy",
|
|
140
|
+
...options?.authInfo !== void 0 && { authInfo: options.authInfo },
|
|
141
|
+
requestInfo: request
|
|
142
|
+
});
|
|
143
|
+
transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
|
|
144
|
+
const send = transport.send.bind(transport);
|
|
145
|
+
transport.send = async (message, sendOptions) => {
|
|
146
|
+
if (isJSONRPCRequest(message)) {
|
|
147
|
+
transport?.onmessage?.({
|
|
148
|
+
jsonrpc: "2.0",
|
|
149
|
+
id: message.id,
|
|
150
|
+
error: {
|
|
151
|
+
code: -32603,
|
|
152
|
+
message: "Server-to-client requests are unavailable in the Legacy compatibility lane. Use inputRequired(...) for Stateless clients, or route Legacy traffic to a sessionful transport."
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
await send(message, sendOptions);
|
|
158
|
+
};
|
|
159
|
+
await product.connect(transport);
|
|
160
|
+
if (request.signal.aborted) {
|
|
161
|
+
await teardown();
|
|
162
|
+
return new Response(null, { status: 499 });
|
|
163
|
+
}
|
|
164
|
+
request.signal.addEventListener("abort", onAbort, { once: true });
|
|
165
|
+
const response = await transport.handleRequest(request, {
|
|
166
|
+
...options?.authInfo !== void 0 && { authInfo: options.authInfo },
|
|
167
|
+
...options?.parsedBody !== void 0 && { parsedBody: options.parsedBody }
|
|
168
|
+
});
|
|
169
|
+
if (response.body === null || !response.headers.get("content-type")?.includes("text/event-stream")) {
|
|
170
|
+
request.signal.removeEventListener("abort", onAbort);
|
|
171
|
+
await teardown();
|
|
172
|
+
return response;
|
|
173
|
+
}
|
|
174
|
+
const reader = response.body.getReader();
|
|
175
|
+
const encoder = new TextEncoder();
|
|
176
|
+
let keepalive;
|
|
177
|
+
const clearKeepalive = () => {
|
|
178
|
+
if (keepalive !== void 0) {
|
|
179
|
+
clearInterval(keepalive);
|
|
180
|
+
keepalive = void 0;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
clearResponseKeepalive = clearKeepalive;
|
|
184
|
+
const body = new ReadableStream({
|
|
185
|
+
start(controller) {
|
|
186
|
+
if (teardownPromise) return;
|
|
187
|
+
keepalive = setInterval(() => {
|
|
188
|
+
try {
|
|
189
|
+
controller.enqueue(encoder.encode(KEEPALIVE_FRAME));
|
|
190
|
+
} catch {
|
|
191
|
+
clearKeepalive();
|
|
192
|
+
}
|
|
193
|
+
}, KEEPALIVE_INTERVAL_MS);
|
|
194
|
+
},
|
|
195
|
+
async pull(controller) {
|
|
196
|
+
try {
|
|
197
|
+
const { done, value } = await reader.read();
|
|
198
|
+
if (done) {
|
|
199
|
+
clearKeepalive();
|
|
200
|
+
request.signal.removeEventListener("abort", onAbort);
|
|
201
|
+
await teardown();
|
|
202
|
+
controller.close();
|
|
203
|
+
} else if (value !== void 0) controller.enqueue(value);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
clearKeepalive();
|
|
206
|
+
request.signal.removeEventListener("abort", onAbort);
|
|
207
|
+
await teardown();
|
|
208
|
+
controller.error(error);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
async cancel(reason) {
|
|
212
|
+
clearKeepalive();
|
|
213
|
+
request.signal.removeEventListener("abort", onAbort);
|
|
214
|
+
await reader.cancel(reason).catch(() => {});
|
|
215
|
+
await teardown();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
return new Response(body, {
|
|
219
|
+
status: response.status,
|
|
220
|
+
statusText: response.statusText,
|
|
221
|
+
headers: response.headers
|
|
222
|
+
});
|
|
223
|
+
} catch (error) {
|
|
224
|
+
request.signal.removeEventListener("abort", onAbort);
|
|
225
|
+
await teardown();
|
|
226
|
+
reportHandlerError(onerror, error);
|
|
227
|
+
return internalErrorResponse(requestIdFromParsedBody(options?.parsedBody));
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
return { fetch };
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/mcp/handler-stateless.ts
|
|
234
|
+
const DEFAULT_CORS_OPTIONS = {
|
|
235
|
+
origin: "*",
|
|
236
|
+
headers: "Content-Type, Accept, Authorization, mcp-session-id, MCP-Protocol-Version, Mcp-Method, Mcp-Name",
|
|
237
|
+
methods: "GET, POST, DELETE, OPTIONS",
|
|
238
|
+
exposeHeaders: "mcp-session-id",
|
|
239
|
+
maxAge: 86400
|
|
240
|
+
};
|
|
241
|
+
function corsHeaders(options = {}) {
|
|
242
|
+
const merged = {
|
|
243
|
+
...DEFAULT_CORS_OPTIONS,
|
|
244
|
+
...options
|
|
245
|
+
};
|
|
246
|
+
return new Headers({
|
|
247
|
+
"Access-Control-Allow-Headers": merged.headers,
|
|
248
|
+
"Access-Control-Allow-Methods": merged.methods,
|
|
249
|
+
"Access-Control-Allow-Origin": merged.origin,
|
|
250
|
+
"Access-Control-Expose-Headers": merged.exposeHeaders,
|
|
251
|
+
"Access-Control-Max-Age": String(merged.maxAge)
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function withCors(response, options) {
|
|
255
|
+
const headers = new Headers(response.headers);
|
|
256
|
+
if (options === false) {
|
|
257
|
+
for (const name of Array.from(headers.keys())) if (name.toLowerCase().startsWith("access-control-")) headers.delete(name);
|
|
258
|
+
} else for (const [name, value] of corsHeaders(options)) headers.set(name, value);
|
|
259
|
+
return new Response(response.body, {
|
|
260
|
+
status: response.status,
|
|
261
|
+
statusText: response.statusText,
|
|
262
|
+
headers
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function wrapResponseBodyWithAuthContext(response, authContext) {
|
|
266
|
+
if (!authContext || !response.body) return response;
|
|
267
|
+
const reader = response.body.getReader();
|
|
268
|
+
const body = new ReadableStream({
|
|
269
|
+
pull(controller) {
|
|
270
|
+
return runWithAuthContext(authContext, async () => {
|
|
271
|
+
try {
|
|
272
|
+
const { done, value } = await reader.read();
|
|
273
|
+
if (done) controller.close();
|
|
274
|
+
else controller.enqueue(value);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
controller.error(error);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
cancel(reason) {
|
|
281
|
+
return runWithAuthContext(authContext, () => reader.cancel(reason));
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
return new Response(body, {
|
|
285
|
+
status: response.status,
|
|
286
|
+
statusText: response.statusText,
|
|
287
|
+
headers: response.headers
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
function createStatelessMcpHandler(factory, options = {}) {
|
|
291
|
+
const optionRecord = options;
|
|
292
|
+
if (optionRecord.bus !== void 0) throw new TypeError("createMcpHandler option \"bus\" is not exposed by the Agents SDK.");
|
|
293
|
+
const legacyOnlyOption = [
|
|
294
|
+
"transport",
|
|
295
|
+
"storage",
|
|
296
|
+
"sessionIdGenerator",
|
|
297
|
+
"onsessioninitialized",
|
|
298
|
+
"onsessionclosed",
|
|
299
|
+
"enableJsonResponse",
|
|
300
|
+
"eventStore",
|
|
301
|
+
"allowedHosts",
|
|
302
|
+
"allowedOrigins",
|
|
303
|
+
"enableDnsRebindingProtection",
|
|
304
|
+
"retryInterval"
|
|
305
|
+
].find((key) => optionRecord[key] !== void 0);
|
|
306
|
+
if (legacyOnlyOption) throw new TypeError(`createMcpHandler option "${legacyOnlyOption}" is only supported with an MCP SDK v1 server. The managed SDK v2 handler is stateless; remove this option or keep the v1 server during migration.`);
|
|
307
|
+
const { route = "/mcp", corsOptions = {}, allowedHostnames, allowedOriginHostnames, authContext, legacy = "stateless", ...sdkOptions } = options;
|
|
308
|
+
const sdkHandler = createMcpHandler(factory, {
|
|
309
|
+
...sdkOptions,
|
|
310
|
+
legacy: "reject"
|
|
311
|
+
});
|
|
312
|
+
const legacyCompatibilityHandler = legacy === "stateless" ? createLegacyCompatibilityRequestHandler(factory, sdkOptions.onerror) : void 0;
|
|
313
|
+
const serve = async (request, requestOptions, workerCtx) => {
|
|
314
|
+
const requestUrl = new URL(request.url);
|
|
315
|
+
if (requestUrl.pathname !== route) return withCors(new Response("Not Found", { status: 404 }), corsOptions);
|
|
316
|
+
const localEndpoint = localhostAllowedHostnames().includes(requestUrl.hostname);
|
|
317
|
+
const workersDevEndpoint = requestUrl.hostname.endsWith(".workers.dev");
|
|
318
|
+
const acceptedHostnames = allowedHostnames ?? (localEndpoint ? localhostAllowedHostnames() : workersDevEndpoint ? [requestUrl.hostname] : void 0);
|
|
319
|
+
const hostRejection = acceptedHostnames ? hostHeaderValidationResponse(request, acceptedHostnames) : void 0;
|
|
320
|
+
if (hostRejection) return withCors(hostRejection, corsOptions);
|
|
321
|
+
if (allowedOriginHostnames !== "*") {
|
|
322
|
+
let acceptedOriginHostnames = allowedOriginHostnames;
|
|
323
|
+
if (acceptedOriginHostnames === void 0) {
|
|
324
|
+
const defaults = new Set(localhostAllowedOrigins());
|
|
325
|
+
if (workersDevEndpoint) defaults.add(requestUrl.hostname);
|
|
326
|
+
if (corsOptions !== false && corsOptions.origin !== void 0) try {
|
|
327
|
+
const configuredOrigin = new URL(corsOptions.origin);
|
|
328
|
+
if ((configuredOrigin.protocol === "http:" || configuredOrigin.protocol === "https:") && configuredOrigin.hostname) defaults.add(configuredOrigin.hostname);
|
|
329
|
+
} catch {}
|
|
330
|
+
acceptedOriginHostnames = [...defaults];
|
|
331
|
+
}
|
|
332
|
+
const originRejection = originValidationResponse(request, acceptedOriginHostnames ?? []);
|
|
333
|
+
if (originRejection) return withCors(originRejection, corsOptions);
|
|
334
|
+
}
|
|
335
|
+
if (request.method === "OPTIONS" && corsOptions !== false) return new Response(null, { headers: corsHeaders(corsOptions) });
|
|
336
|
+
const legacyRequest = legacyCompatibilityHandler !== void 0 && await isLegacyRequest(request, requestOptions?.parsedBody);
|
|
337
|
+
try {
|
|
338
|
+
const verified = workerCtx ? getVerifiedOAuthAuthInfo(workerCtx) : void 0;
|
|
339
|
+
const explicitAuthInfo = requestOptions?.authInfo;
|
|
340
|
+
if (verified && explicitAuthInfo && explicitAuthInfo.clientId !== verified.authInfo.clientId) throw new TypeError("Conflicting verified OAuth client identity");
|
|
341
|
+
const authInfo = explicitAuthInfo ?? verified?.authInfo;
|
|
342
|
+
const resolvedAuthContext = authContext ?? (verified ? { props: verified.props } : workerCtx?.props && Object.keys(workerCtx.props).length > 0 ? { props: workerCtx.props } : void 0);
|
|
343
|
+
const upstreamOptions = requestOptions || authInfo ? {
|
|
344
|
+
...requestOptions,
|
|
345
|
+
...authInfo && { authInfo }
|
|
346
|
+
} : void 0;
|
|
347
|
+
const invoke = async () => {
|
|
348
|
+
if (legacyRequest && legacyCompatibilityHandler) return legacyCompatibilityHandler.fetch(request, upstreamOptions);
|
|
349
|
+
return sdkHandler.fetch(request, upstreamOptions);
|
|
350
|
+
};
|
|
351
|
+
return withCors(wrapResponseBodyWithAuthContext(resolvedAuthContext ? await runWithAuthContext(resolvedAuthContext, invoke) : await invoke(), resolvedAuthContext), corsOptions);
|
|
352
|
+
} catch (error) {
|
|
353
|
+
reportHandlerError(sdkOptions.onerror, error);
|
|
354
|
+
return withCors(internalErrorResponse(), corsOptions);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
const callable = (request, _env, ctx) => serve(request, void 0, ctx);
|
|
358
|
+
const fetch = (request, requestOptions) => serve(request, requestOptions);
|
|
359
|
+
return Object.assign(callable, {
|
|
360
|
+
fetch,
|
|
361
|
+
notify: sdkHandler.notify
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
//#endregion
|
|
365
|
+
export { KEEPALIVE_INTERVAL_MS as a, KEEPALIVE_FRAME as i, getMcpAuthContext as n, startKeepalive as o, runWithAuthContext as r, createStatelessMcpHandler as t };
|
|
366
|
+
|
|
367
|
+
//# sourceMappingURL=handler-stateless-8hQN_kC3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-stateless-8hQN_kC3.js","names":["candidate","createSdkMcpHandler"],"sources":["../src/mcp/sse-keepalive.ts","../src/mcp/auth-context.ts","../src/mcp/handler-errors.ts","../src/mcp/handler-legacy-compat.ts","../src/mcp/handler-stateless.ts"],"sourcesContent":["/**\n * Shared SSE keepalive utility for MCP transports.\n *\n * Cloudflare's edge closes idle SSE responses after ~5 minutes. Writers\n * that may sit silent for that long (long-running tool calls, idle\n * standalone GET streams) arm a keepalive to keep the response under the\n * watchdog.\n *\n * See cloudflare/agents#1583.\n */\n\n/** Interval between SSE keepalive comment frames, in ms.\n *\n * The WHATWG SSE spec recommends a comment line every \"15 seconds or so\"\n * (html.spec.whatwg.org §9.2.7). 25s gives comfortable headroom below\n * both the ~30s post-handler background-work cancellation window on\n * Workers and the ~5min Cloudflare edge idle-stream watchdog.\n */\nexport const KEEPALIVE_INTERVAL_MS = 25_000;\n\n/** SSE comment frame the parser drops before any event dispatch. */\nexport const KEEPALIVE_FRAME = \": keepalive\\n\\n\";\n\n/**\n * Start an SSE keepalive on `writer`. Returns a `clearInterval` handle\n * that the stream cleanup must invoke when the stream closes.\n */\nexport function startKeepalive(\n writer: WritableStreamDefaultWriter<Uint8Array>,\n encoder: TextEncoder\n): ReturnType<typeof setInterval> {\n const handle = setInterval(() => {\n writer\n .write(encoder.encode(KEEPALIVE_FRAME))\n .catch(() => clearInterval(handle));\n }, KEEPALIVE_INTERVAL_MS);\n return handle;\n}\n","import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { AuthInfo } from \"@modelcontextprotocol/server\";\n\nconst VERIFIED_OAUTH_CONTEXT = Symbol.for(\n \"cloudflare.workers-oauth-provider.verified-context.v1\"\n);\n\ninterface VerifiedWorkersOAuthContext {\n version: 1;\n token: string;\n clientId: string;\n scopes: string[];\n expiresAt?: number;\n resource?: string;\n props: Record<string, unknown>;\n}\n\nexport interface McpAuthContext {\n props: Record<string, unknown>;\n}\n\nconst authContextStorage = new AsyncLocalStorage<McpAuthContext>();\n\nexport function getMcpAuthContext(): McpAuthContext | undefined {\n return authContextStorage.getStore();\n}\n\nexport function runWithAuthContext<T>(context: McpAuthContext, fn: () => T): T {\n return authContextStorage.run(context, fn);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction invalidVerifiedContext(): never {\n throw new TypeError(\"Invalid verified OAuth request context\");\n}\n\nexport function getVerifiedOAuthAuthInfo(\n ctx: ExecutionContext\n): { authInfo: AuthInfo; props: Record<string, unknown> } | undefined {\n const symbolContext = ctx as ExecutionContext & Record<symbol, unknown>;\n if (!(VERIFIED_OAUTH_CONTEXT in symbolContext)) return undefined;\n\n const value = symbolContext[VERIFIED_OAUTH_CONTEXT];\n if (!isPlainRecord(value) || value.version !== 1) invalidVerifiedContext();\n\n const candidate = value as Partial<VerifiedWorkersOAuthContext>;\n const { token, clientId, scopes, expiresAt, resource, props } = candidate;\n if (\n typeof token !== \"string\" ||\n token.length === 0 ||\n typeof clientId !== \"string\" ||\n clientId.length === 0 ||\n !Array.isArray(scopes) ||\n !scopes.every((scope) => typeof scope === \"string\") ||\n !isPlainRecord(props)\n ) {\n invalidVerifiedContext();\n }\n\n if (\n expiresAt !== undefined &&\n (typeof expiresAt !== \"number\" ||\n !Number.isFinite(expiresAt) ||\n expiresAt <= 0)\n ) {\n invalidVerifiedContext();\n }\n\n let resourceUrl: URL | undefined;\n if (resource !== undefined) {\n if (typeof resource !== \"string\") invalidVerifiedContext();\n try {\n resourceUrl = new URL(resource);\n } catch {\n invalidVerifiedContext();\n }\n if (resourceUrl.protocol !== \"http:\" && resourceUrl.protocol !== \"https:\") {\n invalidVerifiedContext();\n }\n }\n\n if (ctx.props !== props) invalidVerifiedContext();\n\n return {\n props,\n authInfo: {\n token,\n clientId,\n scopes: [...scopes],\n ...(expiresAt !== undefined && { expiresAt }),\n ...(resourceUrl !== undefined && { resource: resourceUrl }),\n extra: { props }\n }\n };\n}\n","export function internalErrorResponse(\n id: string | number | null = null\n): Response {\n return Response.json(\n {\n jsonrpc: \"2.0\",\n error: { code: -32603, message: \"Internal server error\" },\n id\n },\n { status: 500 }\n );\n}\n\nexport function requestIdFromParsedBody(body: unknown): string | number | null {\n if (\n typeof body !== \"object\" ||\n body === null ||\n Array.isArray(body) ||\n !(\"method\" in body) ||\n typeof body.method !== \"string\" ||\n !(\"id\" in body)\n ) {\n return null;\n }\n return typeof body.id === \"string\" || typeof body.id === \"number\"\n ? body.id\n : null;\n}\n\nexport function reportHandlerError(\n onerror: ((error: Error) => void) | undefined,\n error: unknown\n): void {\n try {\n onerror?.(error instanceof Error ? error : new Error(String(error)));\n } catch {\n // Error reporting must not change the response.\n }\n}\n","import {\n WebStandardStreamableHTTPServerTransport,\n isJSONRPCRequest,\n type McpHandlerRequestOptions,\n type McpServer,\n type McpServerFactory,\n type Server\n} from \"@modelcontextprotocol/server\";\nimport {\n internalErrorResponse,\n reportHandlerError,\n requestIdFromParsedBody\n} from \"./handler-errors\";\nimport { KEEPALIVE_FRAME, KEEPALIVE_INTERVAL_MS } from \"./sse-keepalive\";\n\n/**\n * Temporary adapter for Legacy compatibility on the SDK v2 transport.\n *\n * Local deltas from the upstream stateless fallback:\n *\n * - impossible stateless server-to-client requests fail immediately rather\n * than leaving the tool handler waiting for a session response;\n * - streamed POST responses receive Cloudflare's 25-second SSE keepalive.\n *\n * Remove this adapter once the SDK exposes both policies directly.\n */\nexport function createLegacyCompatibilityRequestHandler(\n factory: McpServerFactory,\n onerror?: (error: Error) => void\n) {\n const fetch = async (\n request: Request,\n options: McpHandlerRequestOptions | undefined\n ): Promise<Response> => {\n // Match the upstream Legacy fallback: GET and DELETE are session operations\n // and cannot be served by a fresh per-request transport. Reject\n // them before running a factory with application-visible side effects.\n if (request.method.toUpperCase() !== \"POST\") {\n return Response.json(\n {\n jsonrpc: \"2.0\",\n error: { code: -32000, message: \"Method not allowed.\" },\n id: null\n },\n { status: 405 }\n );\n }\n\n if (request.signal.aborted) {\n return new Response(null, { status: 499 });\n }\n\n let product: McpServer | Server | undefined;\n let transport: WebStandardStreamableHTTPServerTransport | undefined;\n let clearResponseKeepalive = () => {};\n let teardownPromise: Promise<void> | undefined;\n const teardown = () =>\n (teardownPromise ??= (async () => {\n clearResponseKeepalive();\n await Promise.all([\n transport?.close().catch(() => {}),\n product?.close().catch(() => {})\n ]);\n })());\n const onAbort = () => void teardown();\n\n try {\n product = await factory({\n era: \"legacy\",\n ...(options?.authInfo !== undefined && { authInfo: options.authInfo }),\n requestInfo: request\n });\n transport = new WebStandardStreamableHTTPServerTransport({\n sessionIdGenerator: undefined\n });\n\n const send = transport.send.bind(transport);\n transport.send = async (message, sendOptions) => {\n if (isJSONRPCRequest(message)) {\n transport?.onmessage?.({\n jsonrpc: \"2.0\",\n id: message.id,\n error: {\n code: -32603,\n message:\n \"Server-to-client requests are unavailable in the Legacy compatibility lane. \" +\n \"Use inputRequired(...) for Stateless clients, or route \" +\n \"Legacy traffic to a sessionful transport.\"\n }\n });\n return;\n }\n await send(message, sendOptions);\n };\n\n await product.connect(transport);\n if (request.signal.aborted) {\n await teardown();\n return new Response(null, { status: 499 });\n }\n request.signal.addEventListener(\"abort\", onAbort, { once: true });\n const response = await transport.handleRequest(request, {\n ...(options?.authInfo !== undefined && {\n authInfo: options.authInfo\n }),\n ...(options?.parsedBody !== undefined && {\n parsedBody: options.parsedBody\n })\n });\n\n if (\n response.body === null ||\n !response.headers.get(\"content-type\")?.includes(\"text/event-stream\")\n ) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n return response;\n }\n\n const reader = response.body.getReader();\n const encoder = new TextEncoder();\n let keepalive: ReturnType<typeof setInterval> | undefined;\n const clearKeepalive = () => {\n if (keepalive !== undefined) {\n clearInterval(keepalive);\n keepalive = undefined;\n }\n };\n clearResponseKeepalive = clearKeepalive;\n\n const body = new ReadableStream<Uint8Array>({\n start(controller) {\n if (teardownPromise) return;\n keepalive = setInterval(() => {\n try {\n controller.enqueue(encoder.encode(KEEPALIVE_FRAME));\n } catch {\n clearKeepalive();\n }\n }, KEEPALIVE_INTERVAL_MS);\n },\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n clearKeepalive();\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n controller.close();\n } else if (value !== undefined) {\n controller.enqueue(value);\n }\n } catch (error) {\n clearKeepalive();\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n controller.error(error);\n }\n },\n async cancel(reason) {\n clearKeepalive();\n request.signal.removeEventListener(\"abort\", onAbort);\n await reader.cancel(reason).catch(() => {});\n await teardown();\n }\n });\n return new Response(body, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers\n });\n } catch (error) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n reportHandlerError(onerror, error);\n return internalErrorResponse(\n requestIdFromParsedBody(options?.parsedBody)\n );\n }\n };\n\n return { fetch };\n}\n","import {\n createMcpHandler as createSdkMcpHandler,\n hostHeaderValidationResponse,\n isLegacyRequest,\n localhostAllowedHostnames,\n localhostAllowedOrigins,\n originValidationResponse,\n type AuthInfo,\n type CreateMcpHandlerOptions as SdkCreateMcpHandlerOptions,\n type McpHandlerRequestOptions,\n type McpServerFactory,\n type ServerNotifier\n} from \"@modelcontextprotocol/server\";\nimport {\n getVerifiedOAuthAuthInfo,\n runWithAuthContext,\n type McpAuthContext\n} from \"./auth-context\";\nimport { internalErrorResponse, reportHandlerError } from \"./handler-errors\";\nimport { createLegacyCompatibilityRequestHandler } from \"./handler-legacy-compat\";\nimport type { CORSOptions } from \"./types\";\n\nexport interface CreateStatelessMcpHandlerOptions extends Omit<\n SdkCreateMcpHandlerOptions,\n \"bus\"\n> {\n /** Exact pathname handled by this Worker wrapper. @default \"/mcp\" */\n route?: string;\n /** CORS headers applied by the Worker wrapper. Pass `false` to disable. */\n corsOptions?: CORSOptions | false;\n /**\n * Restrict `Host` headers to these hostnames. Localhost and `workers.dev`\n * endpoints receive matching defaults; custom domains rely on Cloudflare\n * routing unless this option is set.\n */\n allowedHostnames?: string[];\n /**\n * Restrict present browser `Origin` headers to these hostnames. Requests\n * without an Origin (including non-browser MCP clients) remain valid. The\n * default includes localhost-class Origins, the endpoint's `workers.dev`\n * hostname, and a concrete `corsOptions.origin` hostname. Pass `\"*\"` only\n * when equivalent Origin validation runs in trusted middleware upstream.\n */\n allowedOriginHostnames?: string[] | \"*\";\n /** Application props exposed through {@link getMcpAuthContext}. */\n authContext?: McpAuthContext;\n}\n\nexport type StatelessMcpHandler = {\n (request: Request, env: unknown, ctx: ExecutionContext): Promise<Response>;\n fetch(\n request: Request,\n options?: McpHandlerRequestOptions\n ): Promise<Response>;\n notify: ServerNotifier;\n};\n\nexport type StatelessMcpServerInput = McpServerFactory;\n\nconst DEFAULT_CORS_OPTIONS: Required<CORSOptions> = {\n origin: \"*\",\n headers:\n \"Content-Type, Accept, Authorization, mcp-session-id, MCP-Protocol-Version, Mcp-Method, Mcp-Name\",\n methods: \"GET, POST, DELETE, OPTIONS\",\n exposeHeaders: \"mcp-session-id\",\n maxAge: 86400\n};\n\nfunction corsHeaders(options: CORSOptions = {}): Headers {\n const merged = { ...DEFAULT_CORS_OPTIONS, ...options };\n return new Headers({\n \"Access-Control-Allow-Headers\": merged.headers,\n \"Access-Control-Allow-Methods\": merged.methods,\n \"Access-Control-Allow-Origin\": merged.origin,\n \"Access-Control-Expose-Headers\": merged.exposeHeaders,\n \"Access-Control-Max-Age\": String(merged.maxAge)\n });\n}\n\nfunction withCors(response: Response, options: CORSOptions | false): Response {\n const headers = new Headers(response.headers);\n if (options === false) {\n for (const name of Array.from(headers.keys())) {\n if (name.toLowerCase().startsWith(\"access-control-\")) {\n headers.delete(name);\n }\n }\n } else {\n for (const [name, value] of corsHeaders(options)) {\n headers.set(name, value);\n }\n }\n return new Response(response.body, {\n status: response.status,\n statusText: response.statusText,\n headers\n });\n}\n\nfunction wrapResponseBodyWithAuthContext(\n response: Response,\n authContext: McpAuthContext | undefined\n): Response {\n if (!authContext || !response.body) return response;\n\n const reader = response.body.getReader();\n const body = new ReadableStream<Uint8Array>({\n pull(controller) {\n return runWithAuthContext(authContext, async () => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n controller.close();\n } else {\n controller.enqueue(value);\n }\n } catch (error) {\n controller.error(error);\n }\n });\n },\n cancel(reason) {\n return runWithAuthContext(authContext, () => reader.cancel(reason));\n }\n });\n\n return new Response(body, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers\n });\n}\n\nexport function createStatelessMcpHandler(\n factory: StatelessMcpServerInput,\n options: CreateStatelessMcpHandlerOptions = {}\n): StatelessMcpHandler {\n const optionRecord = options as Record<string, unknown>;\n if (optionRecord.bus !== undefined) {\n throw new TypeError(\n 'createMcpHandler option \"bus\" is not exposed by the Agents SDK.'\n );\n }\n const legacyOnlyOption = [\n \"transport\",\n \"storage\",\n \"sessionIdGenerator\",\n \"onsessioninitialized\",\n \"onsessionclosed\",\n \"enableJsonResponse\",\n \"eventStore\",\n \"allowedHosts\",\n \"allowedOrigins\",\n \"enableDnsRebindingProtection\",\n \"retryInterval\"\n ].find((key) => optionRecord[key] !== undefined);\n if (legacyOnlyOption) {\n throw new TypeError(\n `createMcpHandler option \"${legacyOnlyOption}\" is only supported with an MCP SDK v1 server. The managed SDK v2 handler is stateless; remove this option or keep the v1 server during migration.`\n );\n }\n\n const {\n route = \"/mcp\",\n corsOptions = {},\n allowedHostnames,\n allowedOriginHostnames,\n authContext,\n legacy = \"stateless\",\n ...sdkOptions\n } = options;\n\n const sdkHandler = createSdkMcpHandler(factory, {\n ...sdkOptions,\n legacy: \"reject\"\n });\n const legacyCompatibilityHandler =\n legacy === \"stateless\"\n ? createLegacyCompatibilityRequestHandler(factory, sdkOptions.onerror)\n : undefined;\n\n const serve = async (\n request: Request,\n requestOptions?: McpHandlerRequestOptions,\n workerCtx?: ExecutionContext\n ): Promise<Response> => {\n const requestUrl = new URL(request.url);\n if (requestUrl.pathname !== route) {\n return withCors(new Response(\"Not Found\", { status: 404 }), corsOptions);\n }\n\n // The SDK app factories can distinguish their bind address from an\n // attacker-controlled Host header. A bare Worker cannot. Use defaults we\n // can establish independently: localhost-class names, a standard\n // workers.dev route, and any concrete CORS Origin the application chose.\n // Custom-domain deployments can provide explicit Host and Origin lists.\n const localEndpoint = localhostAllowedHostnames().includes(\n requestUrl.hostname\n );\n const workersDevEndpoint = requestUrl.hostname.endsWith(\".workers.dev\");\n const acceptedHostnames =\n allowedHostnames ??\n (localEndpoint\n ? localhostAllowedHostnames()\n : workersDevEndpoint\n ? [requestUrl.hostname]\n : undefined);\n const hostRejection = acceptedHostnames\n ? hostHeaderValidationResponse(request, acceptedHostnames)\n : undefined;\n if (hostRejection) {\n return withCors(hostRejection, corsOptions);\n }\n if (allowedOriginHostnames !== \"*\") {\n let acceptedOriginHostnames = allowedOriginHostnames;\n if (acceptedOriginHostnames === undefined) {\n const defaults = new Set(localhostAllowedOrigins());\n if (workersDevEndpoint) defaults.add(requestUrl.hostname);\n if (corsOptions !== false && corsOptions.origin !== undefined) {\n try {\n const configuredOrigin = new URL(corsOptions.origin);\n if (\n (configuredOrigin.protocol === \"http:\" ||\n configuredOrigin.protocol === \"https:\") &&\n configuredOrigin.hostname\n ) {\n defaults.add(configuredOrigin.hostname);\n }\n } catch {\n // A wildcard or malformed CORS value does not expand the allowlist.\n }\n }\n acceptedOriginHostnames = [...defaults];\n }\n const originRejection = originValidationResponse(\n request,\n acceptedOriginHostnames ?? []\n );\n if (originRejection) {\n return withCors(originRejection, corsOptions);\n }\n }\n\n if (request.method === \"OPTIONS\" && corsOptions !== false) {\n return new Response(null, { headers: corsHeaders(corsOptions) });\n }\n\n const legacyRequest =\n legacyCompatibilityHandler !== undefined &&\n (await isLegacyRequest(request, requestOptions?.parsedBody));\n\n try {\n const verified = workerCtx\n ? getVerifiedOAuthAuthInfo(workerCtx)\n : undefined;\n const explicitAuthInfo = requestOptions?.authInfo;\n if (\n verified &&\n explicitAuthInfo &&\n explicitAuthInfo.clientId !== verified.authInfo.clientId\n ) {\n throw new TypeError(\"Conflicting verified OAuth client identity\");\n }\n\n const authInfo: AuthInfo | undefined =\n explicitAuthInfo ?? verified?.authInfo;\n const resolvedAuthContext =\n authContext ??\n (verified\n ? { props: verified.props }\n : workerCtx?.props && Object.keys(workerCtx.props).length > 0\n ? { props: workerCtx.props as Record<string, unknown> }\n : undefined);\n const upstreamOptions: McpHandlerRequestOptions | undefined =\n requestOptions || authInfo\n ? { ...requestOptions, ...(authInfo && { authInfo }) }\n : undefined;\n const invoke = async () => {\n if (legacyRequest && legacyCompatibilityHandler) {\n return legacyCompatibilityHandler.fetch(request, upstreamOptions);\n }\n return sdkHandler.fetch(request, upstreamOptions);\n };\n const response = resolvedAuthContext\n ? await runWithAuthContext(resolvedAuthContext, invoke)\n : await invoke();\n return withCors(\n wrapResponseBodyWithAuthContext(response, resolvedAuthContext),\n corsOptions\n );\n } catch (error) {\n reportHandlerError(sdkOptions.onerror, error);\n return withCors(internalErrorResponse(), corsOptions);\n }\n };\n\n const callable = (request: Request, _env: unknown, ctx: ExecutionContext) =>\n serve(request, undefined, ctx);\n const fetch = (request: Request, requestOptions?: McpHandlerRequestOptions) =>\n serve(request, requestOptions);\n\n return Object.assign(callable, {\n fetch,\n notify: sdkHandler.notify\n }) as StatelessMcpHandler;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkBA,MAAa,wBAAwB;;AAGrC,MAAa,kBAAkB;;;;;AAM/B,SAAgB,eACd,QACA,SACgC;CAChC,MAAM,SAAS,kBAAkB;EAC/B,OACG,MAAM,QAAQ,OAAO,eAAe,CAAC,CAAC,CACtC,YAAY,cAAc,MAAM,CAAC;CACtC,GAAG,qBAAqB;CACxB,OAAO;AACT;;;AClCA,MAAM,yBAAyB,OAAO,IACpC,uDACF;AAgBA,MAAM,qBAAqB,IAAI,kBAAkC;AAEjE,SAAgB,oBAAgD;CAC9D,OAAO,mBAAmB,SAAS;AACrC;AAEA,SAAgB,mBAAsB,SAAyB,IAAgB;CAC7E,OAAO,mBAAmB,IAAI,SAAS,EAAE;AAC3C;AAEA,SAAS,cAAc,OAAkD;CACvE,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,OAAO;CAET,MAAM,YAAY,OAAO,eAAe,KAAK;CAC7C,OAAO,cAAc,OAAO,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AA,KAC9B,MAAM,gBAAgB,SAAS,gBAAgB,UAAU;EAE5D,IAAI;GACF,MAAM,WAAW,YACb,yBAAyB,SAAS,IAClC,KAAA;GACJ,MAAM,mBAAmB,gBAAgB;GACzC,IACE,YACA,oBACA,iBAAiB,aAAa,SAAS,SAAS,UAEhD,MAAM,IAAI,UAAU,4CAA4C;GAGlE,MAAM,WACJ,oBAAoB,UAAU;GAChC,MAAM,sBACJ,gBACC,WACG,EAAE,OAAO,SAAS,MAAM,IACxB,WAAW,SAAS,OAAO,KAAK,UAAU,KAAK,CAAC,CAAC,SAAS,IACxD,EAAE,OAAO,UAAU,MAAiC,IACpD,KAAA;GACR,MAAM,kBACJ,kBAAkB,WACd;IAAE,GAAG;IAAgB,GAAI,YAAY,EAAE,SAAS;GAAG,IACnD,KAAA;GACN,MAAM,SAAS,YAAY;IACzB,IAAI,iBAAiB,4BACnB,OAAO,2BAA2B,MAAM,SAAS,eAAe;IAElE,OAAO,WAAW,MAAM,SAAS,eAAe;GAClD;GAIA,OAAO,SACL,gCAJe,sBACb,MAAM,mBAAmB,qBAAqB,MAAM,IACpD,MAAM,OAAO,GAE2B,mBAAmB,GAC7D,WACF;EACF,SAAS,OAAO;GACd,mBAAmB,WAAW,SAAS,KAAK;GAC5C,OAAO,SAAS,sBAAsB,GAAG,WAAW;EACtD;CACF;CAEA,MAAM,YAAY,SAAkB,MAAe,QACjD,MAAM,SAAS,KAAA,GAAW,GAAG;CAC/B,MAAM,SAAS,SAAkB,mBAC/B,MAAM,SAAS,cAAc;CAE/B,OAAO,OAAO,OAAO,UAAU;EAC7B;EACA,QAAQ,WAAW;CACrB,CAAC;AACH"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ClientOptions } from "@modelcontextprotocol/client";
|
|
2
|
+
import {
|
|
3
|
+
CreateMcpHandlerOptions,
|
|
4
|
+
McpHandlerRequestOptions,
|
|
5
|
+
McpServerFactory,
|
|
6
|
+
ServerNotifier
|
|
7
|
+
} from "@modelcontextprotocol/server";
|
|
8
|
+
|
|
9
|
+
//#region src/mcp/types.d.ts
|
|
10
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
11
|
+
type HttpTransportType = "sse" | "streamable-http";
|
|
12
|
+
type BaseTransportType = HttpTransportType | "rpc";
|
|
13
|
+
type TransportType = BaseTransportType | "auto";
|
|
14
|
+
/**
|
|
15
|
+
* Agents-owned MCP client configuration. Only these SDK behaviours are part of
|
|
16
|
+
* the supported interface; new beta SDK fields are not persisted or exposed
|
|
17
|
+
* accidentally.
|
|
18
|
+
*/
|
|
19
|
+
interface McpClientOptions {
|
|
20
|
+
capabilities?: ClientOptions["capabilities"];
|
|
21
|
+
jsonSchemaValidator?: ClientOptions["jsonSchemaValidator"];
|
|
22
|
+
versionNegotiation?: ClientOptions["versionNegotiation"];
|
|
23
|
+
inputRequired?: ClientOptions["inputRequired"];
|
|
24
|
+
listChanged?: ClientOptions["listChanged"];
|
|
25
|
+
supportedProtocolVersions?: ClientOptions["supportedProtocolVersions"];
|
|
26
|
+
enforceStrictCapabilities?: ClientOptions["enforceStrictCapabilities"];
|
|
27
|
+
debouncedNotificationMethods?: ClientOptions["debouncedNotificationMethods"];
|
|
28
|
+
listMaxPages?: ClientOptions["listMaxPages"];
|
|
29
|
+
responseCacheStore?: ClientOptions["responseCacheStore"];
|
|
30
|
+
cachePartition?: ClientOptions["cachePartition"];
|
|
31
|
+
defaultCacheTtlMs?: ClientOptions["defaultCacheTtlMs"];
|
|
32
|
+
}
|
|
33
|
+
interface CORSOptions {
|
|
34
|
+
origin?: string;
|
|
35
|
+
methods?: string;
|
|
36
|
+
headers?: string;
|
|
37
|
+
maxAge?: number;
|
|
38
|
+
exposeHeaders?: string;
|
|
39
|
+
}
|
|
40
|
+
interface ServeOptions {
|
|
41
|
+
binding?: string;
|
|
42
|
+
corsOptions?: CORSOptions;
|
|
43
|
+
transport?: TransportType;
|
|
44
|
+
jurisdiction?: DurableObjectJurisdiction;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/mcp/auth-context.d.ts
|
|
48
|
+
interface McpAuthContext {
|
|
49
|
+
props: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
declare function getMcpAuthContext(): McpAuthContext | undefined;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/mcp/handler-stateless.d.ts
|
|
54
|
+
interface CreateStatelessMcpHandlerOptions extends Omit<
|
|
55
|
+
CreateMcpHandlerOptions,
|
|
56
|
+
"bus"
|
|
57
|
+
> {
|
|
58
|
+
/** Exact pathname handled by this Worker wrapper. @default "/mcp" */
|
|
59
|
+
route?: string;
|
|
60
|
+
/** CORS headers applied by the Worker wrapper. Pass `false` to disable. */
|
|
61
|
+
corsOptions?: CORSOptions | false;
|
|
62
|
+
/**
|
|
63
|
+
* Restrict `Host` headers to these hostnames. Localhost and `workers.dev`
|
|
64
|
+
* endpoints receive matching defaults; custom domains rely on Cloudflare
|
|
65
|
+
* routing unless this option is set.
|
|
66
|
+
*/
|
|
67
|
+
allowedHostnames?: string[];
|
|
68
|
+
/**
|
|
69
|
+
* Restrict present browser `Origin` headers to these hostnames. Requests
|
|
70
|
+
* without an Origin (including non-browser MCP clients) remain valid. The
|
|
71
|
+
* default includes localhost-class Origins, the endpoint's `workers.dev`
|
|
72
|
+
* hostname, and a concrete `corsOptions.origin` hostname. Pass `"*"` only
|
|
73
|
+
* when equivalent Origin validation runs in trusted middleware upstream.
|
|
74
|
+
*/
|
|
75
|
+
allowedOriginHostnames?: string[] | "*";
|
|
76
|
+
/** Application props exposed through {@link getMcpAuthContext}. */
|
|
77
|
+
authContext?: McpAuthContext;
|
|
78
|
+
}
|
|
79
|
+
type StatelessMcpHandler = {
|
|
80
|
+
(request: Request, env: unknown, ctx: ExecutionContext): Promise<Response>;
|
|
81
|
+
fetch(
|
|
82
|
+
request: Request,
|
|
83
|
+
options?: McpHandlerRequestOptions
|
|
84
|
+
): Promise<Response>;
|
|
85
|
+
notify: ServerNotifier;
|
|
86
|
+
};
|
|
87
|
+
type StatelessMcpServerInput = McpServerFactory;
|
|
88
|
+
declare function createStatelessMcpHandler(
|
|
89
|
+
factory: StatelessMcpServerInput,
|
|
90
|
+
options?: CreateStatelessMcpHandlerOptions
|
|
91
|
+
): StatelessMcpHandler;
|
|
92
|
+
//#endregion
|
|
93
|
+
export {
|
|
94
|
+
McpAuthContext as a,
|
|
95
|
+
CORSOptions as c,
|
|
96
|
+
ServeOptions as d,
|
|
97
|
+
TransportType as f,
|
|
98
|
+
createStatelessMcpHandler as i,
|
|
99
|
+
MaybePromise as l,
|
|
100
|
+
StatelessMcpHandler as n,
|
|
101
|
+
getMcpAuthContext as o,
|
|
102
|
+
StatelessMcpServerInput as r,
|
|
103
|
+
BaseTransportType as s,
|
|
104
|
+
CreateStatelessMcpHandlerOptions as t,
|
|
105
|
+
McpClientOptions as u
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=handler-stateless-C_bo-Ytq.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { r as __DO_NOT_USE_WILL_BREAK__agentContext } from "./internal_context-D
|
|
|
3
3
|
import {
|
|
4
4
|
$ as RoutingRetryOptions,
|
|
5
5
|
A as AgentGetOptions,
|
|
6
|
-
At as MCP_SERVER_ID_MAX_LENGTH,
|
|
7
6
|
B as EmailSendBinding,
|
|
8
7
|
C as DetachedRunAgentToolResult,
|
|
9
8
|
D as AddRpcMcpServerOptions,
|
|
10
9
|
E as AddMcpServerOptions,
|
|
11
10
|
F as Connection,
|
|
11
|
+
Ft as normalizeServerId,
|
|
12
12
|
G as FiberStatus,
|
|
13
13
|
H as FiberInspection,
|
|
14
14
|
I as ConnectionContext,
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
K as ListFibersOptions,
|
|
17
17
|
L as DEFAULT_AGENT_STATIC_OPTIONS,
|
|
18
18
|
M as AgentOptions,
|
|
19
|
+
Mt as MCP_SERVER_ID_MAX_LENGTH,
|
|
19
20
|
N as AgentStaticOptions,
|
|
20
|
-
Nt as normalizeServerId,
|
|
21
21
|
O as Agent,
|
|
22
22
|
P as CallableMetadata,
|
|
23
23
|
Q as RPCResponse,
|
|
@@ -31,15 +31,15 @@ import {
|
|
|
31
31
|
Y as MCPServersState,
|
|
32
32
|
Z as RPCRequest,
|
|
33
33
|
_ as AgentToolRunState,
|
|
34
|
-
_t as MCPAITool,
|
|
35
34
|
a as AgentToolEvent,
|
|
36
|
-
an as SUB_PREFIX,
|
|
37
35
|
at as StartFiberResult,
|
|
38
36
|
b as AgentToolTerminalStatus,
|
|
37
|
+
bt as MCPAIToolSet,
|
|
39
38
|
c as AgentToolFailure,
|
|
40
|
-
cn as
|
|
39
|
+
cn as SubAgentPathMatch,
|
|
41
40
|
ct as SubAgentClass,
|
|
42
41
|
d as AgentToolMilestone,
|
|
42
|
+
dn as routeSubAgentRequest,
|
|
43
43
|
dt as callable,
|
|
44
44
|
et as Schedule,
|
|
45
45
|
f as AgentToolProgress,
|
|
@@ -49,19 +49,17 @@ import {
|
|
|
49
49
|
h as AgentToolRunInspection,
|
|
50
50
|
ht as routeAgentRequest,
|
|
51
51
|
i as AgentToolDisplayMetadata,
|
|
52
|
-
in as TransportType,
|
|
53
52
|
it as StartFiberOptions,
|
|
54
53
|
j as AgentNamespace,
|
|
55
54
|
k as AgentContext,
|
|
56
55
|
l as AgentToolInterruptedReason,
|
|
57
|
-
ln as
|
|
56
|
+
ln as getSubAgentByName,
|
|
58
57
|
lt as SubAgentStub,
|
|
59
58
|
m as AgentToolRunInfo,
|
|
60
59
|
mt as routeAgentEmail,
|
|
61
60
|
n as AGENT_TOOL_PROGRESS_PART,
|
|
62
61
|
nt as SendEmailOptions,
|
|
63
62
|
o as AgentToolEventMessage,
|
|
64
|
-
on as SubAgentPathMatch,
|
|
65
63
|
ot as StateUpdateMessage,
|
|
66
64
|
p as AgentToolProgressSnapshot,
|
|
67
65
|
pt as getCurrentAgent,
|
|
@@ -69,19 +67,20 @@ import {
|
|
|
69
67
|
r as AgentToolChildAdapter,
|
|
70
68
|
rt as SqlError,
|
|
71
69
|
s as AgentToolEventState,
|
|
72
|
-
sn as
|
|
70
|
+
sn as SUB_PREFIX,
|
|
73
71
|
st as StreamingResponse,
|
|
74
72
|
t as AGENT_TOOL_MILESTONE_PART,
|
|
75
73
|
tt as ScheduleCriteria,
|
|
76
74
|
u as AgentToolLifecycleResult,
|
|
75
|
+
un as parseSubAgentPath,
|
|
77
76
|
ut as WSMessage,
|
|
78
77
|
v as AgentToolRunStatus,
|
|
79
|
-
vt as MCPAIToolSet,
|
|
80
78
|
w as RunAgentToolOptions,
|
|
81
79
|
x as ChatCapableAgentClass,
|
|
82
80
|
y as AgentToolStoredChunk,
|
|
81
|
+
yt as MCPAITool,
|
|
83
82
|
z as EmailRoutingOptions
|
|
84
|
-
} from "./agent-tool-types-
|
|
83
|
+
} from "./agent-tool-types-Btk9ETS-.js";
|
|
85
84
|
import { n as camelCaseToKebabCase } from "./utils-CGtGDSgA.js";
|
|
86
85
|
import {
|
|
87
86
|
i as isDurableObjectStorageReset,
|
|
@@ -94,7 +93,8 @@ import {
|
|
|
94
93
|
n as AgentsOAuthProvider,
|
|
95
94
|
r as DurableObjectOAuthClientProvider,
|
|
96
95
|
t as AgentMcpOAuthProvider
|
|
97
|
-
} from "./do-oauth-client-provider-
|
|
96
|
+
} from "./do-oauth-client-provider-VTZj2VtM.js";
|
|
97
|
+
import { f as TransportType } from "./handler-stateless-C_bo-Ytq.js";
|
|
98
98
|
import { t as MessageType } from "./types-6Zo2zfoO.js";
|
|
99
99
|
import { l as createHeaderBasedEmailResolver } from "./email-CL27preh.js";
|
|
100
100
|
export {
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createHeaderBasedEmailResolver, signAgentHeaders } from "./email.js";
|
|
|
6
6
|
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, t as _classPrivateFieldGet2 } from "./classPrivateFieldGet2-DZBYAB34.js";
|
|
7
7
|
import { SUB_PREFIX, getSubAgentByName, parseSubAgentPath, routeSubAgentRequest } from "./sub-routing.js";
|
|
8
8
|
import { isDurableObjectCodeUpdateReset, isDurableObjectMemoryLimitReset, isDurableObjectStorageReset, isErrorRetryable, isPlatformTransientError, tryN, validateRetryOptions } from "./retries.js";
|
|
9
|
-
import { a as MCPConnectionState, c as RPC_DO_PREFIX, i as normalizeServerId, l as DisposableStore, n as MCP_SERVER_ID_MAX_LENGTH, t as MCPClientManager } from "./client-
|
|
9
|
+
import { a as MCPConnectionState, c as RPC_DO_PREFIX, i as normalizeServerId, l as DisposableStore, n as MCP_SERVER_ID_MAX_LENGTH, t as MCPClientManager } from "./client-zqKcsyFa.js";
|
|
10
10
|
import { DurableObjectOAuthClientProvider } from "./mcp/do-oauth-client-provider.js";
|
|
11
11
|
import { genericObservability } from "./observability/index.js";
|
|
12
12
|
import { n as writeSpanAttributes, t as tracer } from "./cloudflare-BldFV0Pa.js";
|
|
@@ -6895,7 +6895,8 @@ var Agent = class Agent extends Server {
|
|
|
6895
6895
|
transport: {
|
|
6896
6896
|
...headerTransportOpts,
|
|
6897
6897
|
authProvider,
|
|
6898
|
-
type: transportType
|
|
6898
|
+
type: transportType,
|
|
6899
|
+
skipIssuerMetadataValidation: resolvedOptions?.transport?.skipIssuerMetadataValidation
|
|
6899
6900
|
},
|
|
6900
6901
|
retry: resolvedOptions?.retry
|
|
6901
6902
|
});
|