agents 0.0.0-d4257c1 → 0.0.0-d6d6d60
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/dist/ai-chat-agent.d.ts +10 -10
- package/dist/ai-chat-agent.js +6 -6
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/{ai-chat-v5-migration-gdyLiTd8.js → ai-chat-v5-migration-DBHGW4Hv.js} +2 -2
- package/dist/{ai-chat-v5-migration-gdyLiTd8.js.map → ai-chat-v5-migration-DBHGW4Hv.js.map} +1 -1
- package/dist/ai-chat-v5-migration.js +1 -1
- package/dist/ai-react.d.ts +9 -9
- package/dist/ai-react.js +17 -11
- package/dist/ai-react.js.map +1 -1
- package/dist/{ai-types-UZlfLOYP.js → ai-types-B3aQaFv3.js} +2 -2
- package/dist/{ai-types-UZlfLOYP.js.map → ai-types-B3aQaFv3.js.map} +1 -1
- package/dist/{ai-types-BWW4umHY.d.ts → ai-types-D5YoPrBZ.d.ts} +2 -2
- package/dist/ai-types.d.ts +4 -4
- package/dist/ai-types.js +1 -1
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +27 -0
- package/dist/cli.js.map +1 -0
- package/dist/{client-DjR-lC16.js → client-BfiZ3HQd.js} +3 -3
- package/dist/{client-DjR-lC16.js.map → client-BfiZ3HQd.js.map} +1 -1
- package/dist/{client-C-nwz-3N.d.ts → client-Bws9q38u.d.ts} +189 -75
- package/dist/{client-CmMi85Sj.d.ts → client-CbWe9FBd.d.ts} +10 -10
- package/dist/{client-CZBVDDoO.js → client-DvK0u9vD.js} +236 -124
- package/dist/client-DvK0u9vD.js.map +1 -0
- package/dist/client.d.ts +8 -8
- package/dist/client.js +2 -2
- package/dist/codemode/ai.js +5 -5
- package/dist/do-oauth-client-provider-CcTno-25.d.ts +142 -0
- package/dist/{do-oauth-client-provider-B2jr6UNq.js → do-oauth-client-provider-D2P1lSft.js} +3 -3
- package/dist/do-oauth-client-provider-D2P1lSft.js.map +1 -0
- package/dist/{index-CkQU40oY.d.ts → index-Bdzb2feZ.d.ts} +53 -39
- package/dist/{index-W4JUkafc.d.ts → index-DhJCaDWd.d.ts} +7 -3
- package/dist/index.d.ts +36 -36
- package/dist/index.js +5 -5
- package/dist/mcp/client.d.ts +4 -4
- package/dist/mcp/client.js +2 -1
- package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/do-oauth-client-provider.js +1 -1
- package/dist/mcp/index.d.ts +127 -9
- package/dist/mcp/index.js +619 -26
- package/dist/mcp/index.js.map +1 -1
- package/dist/{mcp-BEwaCsxO.d.ts → mcp-Dw5vDrY8.d.ts} +2 -2
- package/dist/observability/index.d.ts +2 -2
- package/dist/observability/index.js +5 -5
- package/dist/{react-B4e1rDid.d.ts → react-DFNXTQzy.d.ts} +17 -17
- package/dist/react.d.ts +9 -9
- package/dist/react.js +1 -1
- package/dist/{serializable-gtr9YMhp.d.ts → serializable-CymX8ovI.d.ts} +8 -3
- package/dist/serializable.d.ts +5 -5
- package/dist/{src-COfG--3R.js → src-C1WWpbRo.js} +189 -121
- package/dist/src-C1WWpbRo.js.map +1 -0
- package/package.json +54 -39
- package/dist/client-CZBVDDoO.js.map +0 -1
- package/dist/do-oauth-client-provider-B2jr6UNq.js.map +0 -1
- package/dist/do-oauth-client-provider-CCwGwnrA.d.ts +0 -55
- package/dist/src-COfG--3R.js.map +0 -1
- package/src/index.ts +0 -2031
package/dist/mcp/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { MessageType } from "../ai-types-
|
|
2
|
-
import "../client-
|
|
3
|
-
import
|
|
4
|
-
import "../do-oauth-client-provider-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { t as MessageType } from "../ai-types-B3aQaFv3.js";
|
|
2
|
+
import "../client-BfiZ3HQd.js";
|
|
3
|
+
import "../client-DvK0u9vD.js";
|
|
4
|
+
import "../do-oauth-client-provider-D2P1lSft.js";
|
|
5
|
+
import { c as getCurrentAgent, s as getAgentByName, t as Agent } from "../src-C1WWpbRo.js";
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
8
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
9
|
+
import { ElicitRequestSchema, InitializeRequestSchema, JSONRPCMessageSchema, isInitializeRequest, isJSONRPCError, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResponse } from "@modelcontextprotocol/sdk/types.js";
|
|
7
10
|
|
|
8
11
|
//#region src/mcp/utils.ts
|
|
9
12
|
/**
|
|
@@ -20,7 +23,7 @@ const MCP_HTTP_METHOD_HEADER = "cf-mcp-method";
|
|
|
20
23
|
*/
|
|
21
24
|
const MCP_MESSAGE_HEADER = "cf-mcp-message";
|
|
22
25
|
const MAXIMUM_MESSAGE_SIZE_BYTES = 4 * 1024 * 1024;
|
|
23
|
-
const createStreamingHttpHandler = (basePath, namespace,
|
|
26
|
+
const createStreamingHttpHandler = (basePath, namespace, options = {}) => {
|
|
24
27
|
let pathname = basePath;
|
|
25
28
|
if (basePath === "/") pathname = "/*";
|
|
26
29
|
const basePattern = new URLPattern({ pathname });
|
|
@@ -129,7 +132,10 @@ const createStreamingHttpHandler = (basePath, namespace, corsOptions) => {
|
|
|
129
132
|
return new Response(body$1, { status: 400 });
|
|
130
133
|
}
|
|
131
134
|
sessionId = sessionId ?? namespace.newUniqueId().toString();
|
|
132
|
-
const agent = await getAgentByName(namespace, `streamable-http:${sessionId}`, {
|
|
135
|
+
const agent = await getAgentByName(namespace, `streamable-http:${sessionId}`, {
|
|
136
|
+
props: ctx.props,
|
|
137
|
+
jurisdiction: options.jurisdiction
|
|
138
|
+
});
|
|
133
139
|
const isInitialized = await agent.getInitializeRequest();
|
|
134
140
|
if (maybeInitializeRequest) await agent.setInitializeRequest(maybeInitializeRequest);
|
|
135
141
|
else if (!isInitialized) {
|
|
@@ -204,7 +210,7 @@ const createStreamingHttpHandler = (basePath, namespace, corsOptions) => {
|
|
|
204
210
|
if (messages.every((msg) => isJSONRPCNotification(msg) || isJSONRPCResponse(msg))) {
|
|
205
211
|
ws.close();
|
|
206
212
|
return new Response(null, {
|
|
207
|
-
headers: corsHeaders(request, corsOptions),
|
|
213
|
+
headers: corsHeaders(request, options.corsOptions),
|
|
208
214
|
status: 202
|
|
209
215
|
});
|
|
210
216
|
}
|
|
@@ -214,7 +220,7 @@ const createStreamingHttpHandler = (basePath, namespace, corsOptions) => {
|
|
|
214
220
|
Connection: "keep-alive",
|
|
215
221
|
"Content-Type": "text/event-stream",
|
|
216
222
|
"mcp-session-id": sessionId,
|
|
217
|
-
...corsHeaders(request, corsOptions)
|
|
223
|
+
...corsHeaders(request, options.corsOptions)
|
|
218
224
|
},
|
|
219
225
|
status: 200
|
|
220
226
|
});
|
|
@@ -242,7 +248,10 @@ const createStreamingHttpHandler = (basePath, namespace, corsOptions) => {
|
|
|
242
248
|
const { readable, writable } = new TransformStream();
|
|
243
249
|
const writer = writable.getWriter();
|
|
244
250
|
const encoder = new TextEncoder();
|
|
245
|
-
const agent = await getAgentByName(namespace, `streamable-http:${sessionId}`, {
|
|
251
|
+
const agent = await getAgentByName(namespace, `streamable-http:${sessionId}`, {
|
|
252
|
+
props: ctx.props,
|
|
253
|
+
jurisdiction: options.jurisdiction
|
|
254
|
+
});
|
|
246
255
|
if (!await agent.getInitializeRequest()) return new Response(JSON.stringify({
|
|
247
256
|
jsonrpc: "2.0",
|
|
248
257
|
error: {
|
|
@@ -291,7 +300,7 @@ const createStreamingHttpHandler = (basePath, namespace, corsOptions) => {
|
|
|
291
300
|
Connection: "keep-alive",
|
|
292
301
|
"Content-Type": "text/event-stream",
|
|
293
302
|
"mcp-session-id": sessionId,
|
|
294
|
-
...corsHeaders(request, corsOptions)
|
|
303
|
+
...corsHeaders(request, options.corsOptions)
|
|
295
304
|
},
|
|
296
305
|
status: 200
|
|
297
306
|
});
|
|
@@ -306,9 +315,9 @@ const createStreamingHttpHandler = (basePath, namespace, corsOptions) => {
|
|
|
306
315
|
id: null
|
|
307
316
|
}), {
|
|
308
317
|
status: 400,
|
|
309
|
-
headers: corsHeaders(request, corsOptions)
|
|
318
|
+
headers: corsHeaders(request, options.corsOptions)
|
|
310
319
|
});
|
|
311
|
-
const agent = await getAgentByName(namespace, `streamable-http:${sessionId}
|
|
320
|
+
const agent = await getAgentByName(namespace, `streamable-http:${sessionId}`, { jurisdiction: options.jurisdiction });
|
|
312
321
|
if (!await agent.getInitializeRequest()) return new Response(JSON.stringify({
|
|
313
322
|
jsonrpc: "2.0",
|
|
314
323
|
error: {
|
|
@@ -318,12 +327,12 @@ const createStreamingHttpHandler = (basePath, namespace, corsOptions) => {
|
|
|
318
327
|
id: null
|
|
319
328
|
}), {
|
|
320
329
|
status: 404,
|
|
321
|
-
headers: corsHeaders(request, corsOptions)
|
|
330
|
+
headers: corsHeaders(request, options.corsOptions)
|
|
322
331
|
});
|
|
323
332
|
ctx.waitUntil(agent.destroy().catch(() => {}));
|
|
324
333
|
return new Response(null, {
|
|
325
334
|
status: 204,
|
|
326
|
-
headers: corsHeaders(request, corsOptions)
|
|
335
|
+
headers: corsHeaders(request, options.corsOptions)
|
|
327
336
|
});
|
|
328
337
|
}
|
|
329
338
|
}
|
|
@@ -338,7 +347,7 @@ const createStreamingHttpHandler = (basePath, namespace, corsOptions) => {
|
|
|
338
347
|
return new Response(body, { status: 404 });
|
|
339
348
|
};
|
|
340
349
|
};
|
|
341
|
-
const createLegacySseHandler = (basePath, namespace,
|
|
350
|
+
const createLegacySseHandler = (basePath, namespace, options = {}) => {
|
|
342
351
|
let pathname = basePath;
|
|
343
352
|
if (basePath === "/") pathname = "/*";
|
|
344
353
|
const basePattern = new URLPattern({ pathname });
|
|
@@ -355,7 +364,10 @@ const createLegacySseHandler = (basePath, namespace, corsOptions) => {
|
|
|
355
364
|
endpointUrl.searchParams.set("sessionId", sessionId);
|
|
356
365
|
const endpointMessage = `event: endpoint\ndata: ${endpointUrl.pathname + endpointUrl.search + endpointUrl.hash}\n\n`;
|
|
357
366
|
writer.write(encoder.encode(endpointMessage));
|
|
358
|
-
const agent = await getAgentByName(namespace, `sse:${sessionId}`, {
|
|
367
|
+
const agent = await getAgentByName(namespace, `sse:${sessionId}`, {
|
|
368
|
+
props: ctx.props,
|
|
369
|
+
jurisdiction: options.jurisdiction
|
|
370
|
+
});
|
|
359
371
|
const existingHeaders = {};
|
|
360
372
|
request.headers.forEach((value, key) => {
|
|
361
373
|
existingHeaders[key] = value;
|
|
@@ -407,7 +419,7 @@ const createLegacySseHandler = (basePath, namespace, corsOptions) => {
|
|
|
407
419
|
"Cache-Control": "no-cache",
|
|
408
420
|
Connection: "keep-alive",
|
|
409
421
|
"Content-Type": "text/event-stream",
|
|
410
|
-
...corsHeaders(request, corsOptions)
|
|
422
|
+
...corsHeaders(request, options.corsOptions)
|
|
411
423
|
} });
|
|
412
424
|
}
|
|
413
425
|
if (request.method === "POST" && messagePattern.test(url)) {
|
|
@@ -417,7 +429,10 @@ const createLegacySseHandler = (basePath, namespace, corsOptions) => {
|
|
|
417
429
|
if (!contentType.includes("application/json")) return new Response(`Unsupported content-type: ${contentType}`, { status: 400 });
|
|
418
430
|
const contentLength = Number.parseInt(request.headers.get("content-length") || "0", 10);
|
|
419
431
|
if (contentLength > MAXIMUM_MESSAGE_SIZE_BYTES) return new Response(`Request body too large: ${contentLength} bytes`, { status: 400 });
|
|
420
|
-
const agent = await getAgentByName(namespace, `sse:${sessionId}`, {
|
|
432
|
+
const agent = await getAgentByName(namespace, `sse:${sessionId}`, {
|
|
433
|
+
props: ctx.props,
|
|
434
|
+
jurisdiction: options.jurisdiction
|
|
435
|
+
});
|
|
421
436
|
const messageBody = await request.json();
|
|
422
437
|
const error = await agent.onSSEMcpMessage(sessionId, messageBody);
|
|
423
438
|
if (error) return new Response(error.message, {
|
|
@@ -425,7 +440,7 @@ const createLegacySseHandler = (basePath, namespace, corsOptions) => {
|
|
|
425
440
|
"Cache-Control": "no-cache",
|
|
426
441
|
Connection: "keep-alive",
|
|
427
442
|
"Content-Type": "text/event-stream",
|
|
428
|
-
...corsHeaders(request, corsOptions)
|
|
443
|
+
...corsHeaders(request, options.corsOptions)
|
|
429
444
|
},
|
|
430
445
|
status: 400
|
|
431
446
|
});
|
|
@@ -434,7 +449,7 @@ const createLegacySseHandler = (basePath, namespace, corsOptions) => {
|
|
|
434
449
|
"Cache-Control": "no-cache",
|
|
435
450
|
Connection: "keep-alive",
|
|
436
451
|
"Content-Type": "text/event-stream",
|
|
437
|
-
...corsHeaders(request, corsOptions)
|
|
452
|
+
...corsHeaders(request, options.corsOptions)
|
|
438
453
|
},
|
|
439
454
|
status: 202
|
|
440
455
|
});
|
|
@@ -624,6 +639,578 @@ var StreamableHTTPServerTransport = class {
|
|
|
624
639
|
}
|
|
625
640
|
};
|
|
626
641
|
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/mcp/client-transports.ts
|
|
644
|
+
let didWarnAboutSSEEdgeClientTransport = false;
|
|
645
|
+
/**
|
|
646
|
+
* @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
|
|
647
|
+
*/
|
|
648
|
+
var SSEEdgeClientTransport = class extends SSEClientTransport {
|
|
649
|
+
constructor(url, options) {
|
|
650
|
+
super(url, options);
|
|
651
|
+
if (!didWarnAboutSSEEdgeClientTransport) {
|
|
652
|
+
didWarnAboutSSEEdgeClientTransport = true;
|
|
653
|
+
console.warn("SSEEdgeClientTransport is deprecated. Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. SSEEdgeClientTransport will be removed in the next major version.");
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
let didWarnAboutStreamableHTTPEdgeClientTransport = false;
|
|
658
|
+
/**
|
|
659
|
+
* @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
|
|
660
|
+
*/
|
|
661
|
+
var StreamableHTTPEdgeClientTransport = class extends StreamableHTTPClientTransport {
|
|
662
|
+
constructor(url, options) {
|
|
663
|
+
super(url, options);
|
|
664
|
+
if (!didWarnAboutStreamableHTTPEdgeClientTransport) {
|
|
665
|
+
didWarnAboutStreamableHTTPEdgeClientTransport = true;
|
|
666
|
+
console.warn("StreamableHTTPEdgeClientTransport is deprecated. Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. StreamableHTTPEdgeClientTransport will be removed in the next major version.");
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
//#endregion
|
|
672
|
+
//#region src/mcp/worker-transport.ts
|
|
673
|
+
const SUPPORTED_PROTOCOL_VERSIONS = ["2025-03-26", "2025-06-18"];
|
|
674
|
+
const DEFAULT_PROTOCOL_VERSION = "2025-03-26";
|
|
675
|
+
const MCP_PROTOCOL_VERSION_HEADER = "MCP-Protocol-Version";
|
|
676
|
+
var WorkerTransport = class {
|
|
677
|
+
constructor(options) {
|
|
678
|
+
this.started = false;
|
|
679
|
+
this.initialized = false;
|
|
680
|
+
this.enableJsonResponse = false;
|
|
681
|
+
this.standaloneSseStreamId = "_GET_stream";
|
|
682
|
+
this.streamMapping = /* @__PURE__ */ new Map();
|
|
683
|
+
this.requestToStreamMapping = /* @__PURE__ */ new Map();
|
|
684
|
+
this.requestResponseMap = /* @__PURE__ */ new Map();
|
|
685
|
+
this.stateRestored = false;
|
|
686
|
+
this.sessionIdGenerator = options?.sessionIdGenerator;
|
|
687
|
+
this.enableJsonResponse = options?.enableJsonResponse ?? false;
|
|
688
|
+
this.onsessioninitialized = options?.onsessioninitialized;
|
|
689
|
+
this.corsOptions = options?.corsOptions;
|
|
690
|
+
this.storage = options?.storage;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Restore transport state from persistent storage.
|
|
694
|
+
* This is automatically called on start.
|
|
695
|
+
*/
|
|
696
|
+
async restoreState() {
|
|
697
|
+
if (!this.storage || this.stateRestored) return;
|
|
698
|
+
const state = await Promise.resolve(this.storage.get());
|
|
699
|
+
if (state) {
|
|
700
|
+
this.sessionId = state.sessionId;
|
|
701
|
+
this.initialized = state.initialized;
|
|
702
|
+
this.protocolVersion = state.protocolVersion;
|
|
703
|
+
}
|
|
704
|
+
this.stateRestored = true;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Persist current transport state to storage.
|
|
708
|
+
*/
|
|
709
|
+
async saveState() {
|
|
710
|
+
if (!this.storage) return;
|
|
711
|
+
const state = {
|
|
712
|
+
sessionId: this.sessionId,
|
|
713
|
+
initialized: this.initialized,
|
|
714
|
+
protocolVersion: this.protocolVersion
|
|
715
|
+
};
|
|
716
|
+
await Promise.resolve(this.storage.set(state));
|
|
717
|
+
}
|
|
718
|
+
async start() {
|
|
719
|
+
if (this.started) throw new Error("Transport already started");
|
|
720
|
+
this.started = true;
|
|
721
|
+
}
|
|
722
|
+
validateProtocolVersion(request) {
|
|
723
|
+
const versionHeader = request.headers.get(MCP_PROTOCOL_VERSION_HEADER);
|
|
724
|
+
if (!versionHeader) {
|
|
725
|
+
if (!this.protocolVersion || this.protocolVersion === DEFAULT_PROTOCOL_VERSION) return;
|
|
726
|
+
return new Response(JSON.stringify({
|
|
727
|
+
jsonrpc: "2.0",
|
|
728
|
+
error: {
|
|
729
|
+
code: -32e3,
|
|
730
|
+
message: `Bad Request: ${MCP_PROTOCOL_VERSION_HEADER} header is required`
|
|
731
|
+
},
|
|
732
|
+
id: null
|
|
733
|
+
}), {
|
|
734
|
+
status: 400,
|
|
735
|
+
headers: {
|
|
736
|
+
"Content-Type": "application/json",
|
|
737
|
+
...this.getHeaders()
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
if (!SUPPORTED_PROTOCOL_VERSIONS.includes(versionHeader)) return new Response(JSON.stringify({
|
|
742
|
+
jsonrpc: "2.0",
|
|
743
|
+
error: {
|
|
744
|
+
code: -32e3,
|
|
745
|
+
message: `Bad Request: Unsupported ${MCP_PROTOCOL_VERSION_HEADER}: ${versionHeader}. Supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")}`
|
|
746
|
+
},
|
|
747
|
+
id: null
|
|
748
|
+
}), {
|
|
749
|
+
status: 400,
|
|
750
|
+
headers: {
|
|
751
|
+
"Content-Type": "application/json",
|
|
752
|
+
...this.getHeaders()
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
if (this.protocolVersion && versionHeader !== this.protocolVersion) return new Response(JSON.stringify({
|
|
756
|
+
jsonrpc: "2.0",
|
|
757
|
+
error: {
|
|
758
|
+
code: -32e3,
|
|
759
|
+
message: `Bad Request: ${MCP_PROTOCOL_VERSION_HEADER} mismatch. Expected: ${this.protocolVersion}, Got: ${versionHeader}`
|
|
760
|
+
},
|
|
761
|
+
id: null
|
|
762
|
+
}), {
|
|
763
|
+
status: 400,
|
|
764
|
+
headers: {
|
|
765
|
+
"Content-Type": "application/json",
|
|
766
|
+
...this.getHeaders()
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
getHeaders({ forPreflight } = {}) {
|
|
771
|
+
const options = {
|
|
772
|
+
origin: "*",
|
|
773
|
+
headers: "Content-Type, Accept, Authorization, mcp-session-id, MCP-Protocol-Version",
|
|
774
|
+
methods: "GET, POST, DELETE, OPTIONS",
|
|
775
|
+
exposeHeaders: "mcp-session-id",
|
|
776
|
+
maxAge: 86400,
|
|
777
|
+
...this.corsOptions
|
|
778
|
+
};
|
|
779
|
+
if (forPreflight) return {
|
|
780
|
+
"Access-Control-Allow-Origin": options.origin,
|
|
781
|
+
"Access-Control-Allow-Headers": options.headers,
|
|
782
|
+
"Access-Control-Allow-Methods": options.methods,
|
|
783
|
+
"Access-Control-Max-Age": options.maxAge.toString()
|
|
784
|
+
};
|
|
785
|
+
return {
|
|
786
|
+
"Access-Control-Allow-Origin": options.origin,
|
|
787
|
+
"Access-Control-Expose-Headers": options.exposeHeaders
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
async handleRequest(request, parsedBody) {
|
|
791
|
+
await this.restoreState();
|
|
792
|
+
switch (request.method) {
|
|
793
|
+
case "OPTIONS": return this.handleOptionsRequest(request);
|
|
794
|
+
case "GET": return this.handleGetRequest(request);
|
|
795
|
+
case "POST": return this.handlePostRequest(request, parsedBody);
|
|
796
|
+
case "DELETE": return this.handleDeleteRequest(request);
|
|
797
|
+
default: return this.handleUnsupportedRequest();
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
async handleGetRequest(request) {
|
|
801
|
+
if (!request.headers.get("Accept")?.includes("text/event-stream")) return new Response(JSON.stringify({
|
|
802
|
+
jsonrpc: "2.0",
|
|
803
|
+
error: {
|
|
804
|
+
code: -32e3,
|
|
805
|
+
message: "Not Acceptable: Client must accept text/event-stream"
|
|
806
|
+
},
|
|
807
|
+
id: null
|
|
808
|
+
}), {
|
|
809
|
+
status: 406,
|
|
810
|
+
headers: {
|
|
811
|
+
"Content-Type": "application/json",
|
|
812
|
+
...this.getHeaders()
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
const sessionError = this.validateSession(request);
|
|
816
|
+
if (sessionError) return sessionError;
|
|
817
|
+
const versionError = this.validateProtocolVersion(request);
|
|
818
|
+
if (versionError) return versionError;
|
|
819
|
+
const streamId = this.standaloneSseStreamId;
|
|
820
|
+
if (this.streamMapping.get(streamId) !== void 0) return new Response(JSON.stringify({
|
|
821
|
+
jsonrpc: "2.0",
|
|
822
|
+
error: {
|
|
823
|
+
code: -32e3,
|
|
824
|
+
message: "Conflict: Only one SSE stream is allowed per session"
|
|
825
|
+
},
|
|
826
|
+
id: null
|
|
827
|
+
}), {
|
|
828
|
+
status: 409,
|
|
829
|
+
headers: {
|
|
830
|
+
"Content-Type": "application/json",
|
|
831
|
+
...this.getHeaders()
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
const { readable, writable } = new TransformStream();
|
|
835
|
+
const writer = writable.getWriter();
|
|
836
|
+
const encoder = new TextEncoder();
|
|
837
|
+
const headers = new Headers({
|
|
838
|
+
"Content-Type": "text/event-stream",
|
|
839
|
+
"Cache-Control": "no-cache",
|
|
840
|
+
Connection: "keep-alive",
|
|
841
|
+
...this.getHeaders()
|
|
842
|
+
});
|
|
843
|
+
if (this.sessionId !== void 0) headers.set("mcp-session-id", this.sessionId);
|
|
844
|
+
const keepAlive = setInterval(() => {
|
|
845
|
+
try {
|
|
846
|
+
writer.write(encoder.encode("event: ping\ndata: \n\n"));
|
|
847
|
+
} catch {
|
|
848
|
+
clearInterval(keepAlive);
|
|
849
|
+
}
|
|
850
|
+
}, 3e4);
|
|
851
|
+
this.streamMapping.set(streamId, {
|
|
852
|
+
writer,
|
|
853
|
+
encoder,
|
|
854
|
+
cleanup: () => {
|
|
855
|
+
clearInterval(keepAlive);
|
|
856
|
+
this.streamMapping.delete(streamId);
|
|
857
|
+
writer.close().catch(() => {});
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
return new Response(readable, { headers });
|
|
861
|
+
}
|
|
862
|
+
async handlePostRequest(request, parsedBody) {
|
|
863
|
+
const acceptHeader = request.headers.get("Accept");
|
|
864
|
+
if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) return new Response(JSON.stringify({
|
|
865
|
+
jsonrpc: "2.0",
|
|
866
|
+
error: {
|
|
867
|
+
code: -32e3,
|
|
868
|
+
message: "Not Acceptable: Client must accept both application/json and text/event-stream"
|
|
869
|
+
},
|
|
870
|
+
id: null
|
|
871
|
+
}), {
|
|
872
|
+
status: 406,
|
|
873
|
+
headers: {
|
|
874
|
+
"Content-Type": "application/json",
|
|
875
|
+
...this.getHeaders()
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
if (!request.headers.get("Content-Type")?.includes("application/json")) return new Response(JSON.stringify({
|
|
879
|
+
jsonrpc: "2.0",
|
|
880
|
+
error: {
|
|
881
|
+
code: -32e3,
|
|
882
|
+
message: "Unsupported Media Type: Content-Type must be application/json"
|
|
883
|
+
},
|
|
884
|
+
id: null
|
|
885
|
+
}), {
|
|
886
|
+
status: 415,
|
|
887
|
+
headers: {
|
|
888
|
+
"Content-Type": "application/json",
|
|
889
|
+
...this.getHeaders()
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
let rawMessage = parsedBody;
|
|
893
|
+
if (rawMessage === void 0) try {
|
|
894
|
+
rawMessage = await request.json();
|
|
895
|
+
} catch {
|
|
896
|
+
return new Response(JSON.stringify({
|
|
897
|
+
jsonrpc: "2.0",
|
|
898
|
+
error: {
|
|
899
|
+
code: -32700,
|
|
900
|
+
message: "Parse error: Invalid JSON"
|
|
901
|
+
},
|
|
902
|
+
id: null
|
|
903
|
+
}), {
|
|
904
|
+
status: 400,
|
|
905
|
+
headers: {
|
|
906
|
+
"Content-Type": "application/json",
|
|
907
|
+
...this.getHeaders()
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
let messages;
|
|
912
|
+
try {
|
|
913
|
+
if (Array.isArray(rawMessage)) messages = rawMessage.map((msg) => JSONRPCMessageSchema.parse(msg));
|
|
914
|
+
else messages = [JSONRPCMessageSchema.parse(rawMessage)];
|
|
915
|
+
} catch {
|
|
916
|
+
return new Response(JSON.stringify({
|
|
917
|
+
jsonrpc: "2.0",
|
|
918
|
+
error: {
|
|
919
|
+
code: -32700,
|
|
920
|
+
message: "Parse error: Invalid JSON-RPC message"
|
|
921
|
+
},
|
|
922
|
+
id: null
|
|
923
|
+
}), {
|
|
924
|
+
status: 400,
|
|
925
|
+
headers: {
|
|
926
|
+
"Content-Type": "application/json",
|
|
927
|
+
...this.getHeaders()
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
const requestInfo = { headers: Object.fromEntries(request.headers.entries()) };
|
|
932
|
+
const isInitializationRequest = messages.some(isInitializeRequest);
|
|
933
|
+
if (isInitializationRequest) {
|
|
934
|
+
if (this.initialized && this.sessionId !== void 0) return new Response(JSON.stringify({
|
|
935
|
+
jsonrpc: "2.0",
|
|
936
|
+
error: {
|
|
937
|
+
code: -32600,
|
|
938
|
+
message: "Invalid Request: Server already initialized"
|
|
939
|
+
},
|
|
940
|
+
id: null
|
|
941
|
+
}), {
|
|
942
|
+
status: 400,
|
|
943
|
+
headers: {
|
|
944
|
+
"Content-Type": "application/json",
|
|
945
|
+
...this.getHeaders()
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
if (messages.length > 1) return new Response(JSON.stringify({
|
|
949
|
+
jsonrpc: "2.0",
|
|
950
|
+
error: {
|
|
951
|
+
code: -32600,
|
|
952
|
+
message: "Invalid Request: Only one initialization request is allowed"
|
|
953
|
+
},
|
|
954
|
+
id: null
|
|
955
|
+
}), {
|
|
956
|
+
status: 400,
|
|
957
|
+
headers: {
|
|
958
|
+
"Content-Type": "application/json",
|
|
959
|
+
...this.getHeaders()
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
const initRequest = messages.find(isInitializeRequest);
|
|
963
|
+
if (initRequest?.params) {
|
|
964
|
+
const version = initRequest.params.protocolVersion;
|
|
965
|
+
if (version && SUPPORTED_PROTOCOL_VERSIONS.includes(version)) this.protocolVersion = version;
|
|
966
|
+
else this.protocolVersion = DEFAULT_PROTOCOL_VERSION;
|
|
967
|
+
}
|
|
968
|
+
this.sessionId = this.sessionIdGenerator?.();
|
|
969
|
+
this.initialized = true;
|
|
970
|
+
await this.saveState();
|
|
971
|
+
if (this.sessionId && this.onsessioninitialized) this.onsessioninitialized(this.sessionId);
|
|
972
|
+
}
|
|
973
|
+
if (!isInitializationRequest) {
|
|
974
|
+
const sessionError = this.validateSession(request);
|
|
975
|
+
if (sessionError) return sessionError;
|
|
976
|
+
const versionError = this.validateProtocolVersion(request);
|
|
977
|
+
if (versionError) return versionError;
|
|
978
|
+
}
|
|
979
|
+
if (!messages.some(isJSONRPCRequest)) {
|
|
980
|
+
for (const message of messages) this.onmessage?.(message, { requestInfo });
|
|
981
|
+
return new Response(null, {
|
|
982
|
+
status: 202,
|
|
983
|
+
headers: { ...this.getHeaders() }
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
const streamId = crypto.randomUUID();
|
|
987
|
+
if (this.enableJsonResponse) return new Promise((resolve) => {
|
|
988
|
+
this.streamMapping.set(streamId, {
|
|
989
|
+
resolveJson: resolve,
|
|
990
|
+
cleanup: () => {
|
|
991
|
+
this.streamMapping.delete(streamId);
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
for (const message of messages) if (isJSONRPCRequest(message)) this.requestToStreamMapping.set(message.id, streamId);
|
|
995
|
+
for (const message of messages) this.onmessage?.(message, { requestInfo });
|
|
996
|
+
});
|
|
997
|
+
const { readable, writable } = new TransformStream();
|
|
998
|
+
const writer = writable.getWriter();
|
|
999
|
+
const encoder = new TextEncoder();
|
|
1000
|
+
const headers = new Headers({
|
|
1001
|
+
"Content-Type": "text/event-stream",
|
|
1002
|
+
"Cache-Control": "no-cache",
|
|
1003
|
+
Connection: "keep-alive",
|
|
1004
|
+
...this.getHeaders()
|
|
1005
|
+
});
|
|
1006
|
+
if (this.sessionId !== void 0) headers.set("mcp-session-id", this.sessionId);
|
|
1007
|
+
this.streamMapping.set(streamId, {
|
|
1008
|
+
writer,
|
|
1009
|
+
encoder,
|
|
1010
|
+
cleanup: () => {
|
|
1011
|
+
this.streamMapping.delete(streamId);
|
|
1012
|
+
writer.close().catch(() => {});
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
for (const message of messages) if (isJSONRPCRequest(message)) this.requestToStreamMapping.set(message.id, streamId);
|
|
1016
|
+
for (const message of messages) this.onmessage?.(message, { requestInfo });
|
|
1017
|
+
return new Response(readable, { headers });
|
|
1018
|
+
}
|
|
1019
|
+
async handleDeleteRequest(request) {
|
|
1020
|
+
const sessionError = this.validateSession(request);
|
|
1021
|
+
if (sessionError) return sessionError;
|
|
1022
|
+
const versionError = this.validateProtocolVersion(request);
|
|
1023
|
+
if (versionError) return versionError;
|
|
1024
|
+
await this.close();
|
|
1025
|
+
return new Response(null, {
|
|
1026
|
+
status: 200,
|
|
1027
|
+
headers: { ...this.getHeaders() }
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
handleOptionsRequest(_request) {
|
|
1031
|
+
return new Response(null, {
|
|
1032
|
+
status: 200,
|
|
1033
|
+
headers: { ...this.getHeaders({ forPreflight: true }) }
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
handleUnsupportedRequest() {
|
|
1037
|
+
return new Response(JSON.stringify({
|
|
1038
|
+
jsonrpc: "2.0",
|
|
1039
|
+
error: {
|
|
1040
|
+
code: -32e3,
|
|
1041
|
+
message: "Method not allowed."
|
|
1042
|
+
},
|
|
1043
|
+
id: null
|
|
1044
|
+
}), {
|
|
1045
|
+
status: 405,
|
|
1046
|
+
headers: {
|
|
1047
|
+
Allow: "GET, POST, DELETE, OPTIONS",
|
|
1048
|
+
"Content-Type": "application/json"
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
validateSession(request) {
|
|
1053
|
+
if (this.sessionIdGenerator === void 0) return;
|
|
1054
|
+
if (!this.initialized) return new Response(JSON.stringify({
|
|
1055
|
+
jsonrpc: "2.0",
|
|
1056
|
+
error: {
|
|
1057
|
+
code: -32e3,
|
|
1058
|
+
message: "Bad Request: Server not initialized"
|
|
1059
|
+
},
|
|
1060
|
+
id: null
|
|
1061
|
+
}), {
|
|
1062
|
+
status: 400,
|
|
1063
|
+
headers: {
|
|
1064
|
+
"Content-Type": "application/json",
|
|
1065
|
+
...this.getHeaders()
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
const sessionId = request.headers.get("mcp-session-id");
|
|
1069
|
+
if (!sessionId) return new Response(JSON.stringify({
|
|
1070
|
+
jsonrpc: "2.0",
|
|
1071
|
+
error: {
|
|
1072
|
+
code: -32e3,
|
|
1073
|
+
message: "Bad Request: Mcp-Session-Id header is required"
|
|
1074
|
+
},
|
|
1075
|
+
id: null
|
|
1076
|
+
}), {
|
|
1077
|
+
status: 400,
|
|
1078
|
+
headers: {
|
|
1079
|
+
"Content-Type": "application/json",
|
|
1080
|
+
...this.getHeaders()
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
if (sessionId !== this.sessionId) return new Response(JSON.stringify({
|
|
1084
|
+
jsonrpc: "2.0",
|
|
1085
|
+
error: {
|
|
1086
|
+
code: -32001,
|
|
1087
|
+
message: "Session not found"
|
|
1088
|
+
},
|
|
1089
|
+
id: null
|
|
1090
|
+
}), {
|
|
1091
|
+
status: 404,
|
|
1092
|
+
headers: {
|
|
1093
|
+
"Content-Type": "application/json",
|
|
1094
|
+
...this.getHeaders()
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
async close() {
|
|
1099
|
+
for (const { cleanup } of this.streamMapping.values()) cleanup();
|
|
1100
|
+
this.streamMapping.clear();
|
|
1101
|
+
this.requestResponseMap.clear();
|
|
1102
|
+
this.onclose?.();
|
|
1103
|
+
}
|
|
1104
|
+
async send(message) {
|
|
1105
|
+
let requestId;
|
|
1106
|
+
if (isJSONRPCResponse(message) || isJSONRPCError(message)) requestId = message.id;
|
|
1107
|
+
if (requestId === void 0) {
|
|
1108
|
+
if (isJSONRPCResponse(message) || isJSONRPCError(message)) throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
|
|
1109
|
+
const standaloneSse = this.streamMapping.get(this.standaloneSseStreamId);
|
|
1110
|
+
if (standaloneSse === void 0) return;
|
|
1111
|
+
if (standaloneSse.writer && standaloneSse.encoder) {
|
|
1112
|
+
const data = `event: message\ndata: ${JSON.stringify(message)}\n\n`;
|
|
1113
|
+
await standaloneSse.writer.write(standaloneSse.encoder.encode(data));
|
|
1114
|
+
}
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
const streamId = this.requestToStreamMapping.get(requestId);
|
|
1118
|
+
if (!streamId) throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
1119
|
+
const response = this.streamMapping.get(streamId);
|
|
1120
|
+
if (!response) throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
|
1121
|
+
if (!this.enableJsonResponse) {
|
|
1122
|
+
if (response.writer && response.encoder) {
|
|
1123
|
+
const data = `event: message\ndata: ${JSON.stringify(message)}\n\n`;
|
|
1124
|
+
await response.writer.write(response.encoder.encode(data));
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
|
|
1128
|
+
this.requestResponseMap.set(requestId, message);
|
|
1129
|
+
const relatedIds = Array.from(this.requestToStreamMapping.entries()).filter(([, sid]) => sid === streamId).map(([id]) => id);
|
|
1130
|
+
if (relatedIds.every((id) => this.requestResponseMap.has(id))) {
|
|
1131
|
+
if (this.enableJsonResponse && response.resolveJson) {
|
|
1132
|
+
const responses = relatedIds.map((id) => this.requestResponseMap.get(id));
|
|
1133
|
+
const headers = new Headers({
|
|
1134
|
+
"Content-Type": "application/json",
|
|
1135
|
+
...this.getHeaders()
|
|
1136
|
+
});
|
|
1137
|
+
if (this.sessionId !== void 0) headers.set("mcp-session-id", this.sessionId);
|
|
1138
|
+
const body = responses.length === 1 ? responses[0] : responses;
|
|
1139
|
+
response.resolveJson(new Response(JSON.stringify(body), { headers }));
|
|
1140
|
+
} else response.cleanup();
|
|
1141
|
+
for (const id of relatedIds) {
|
|
1142
|
+
this.requestResponseMap.delete(id);
|
|
1143
|
+
this.requestToStreamMapping.delete(id);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1149
|
+
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region src/mcp/auth-context.ts
|
|
1152
|
+
const authContextStorage = new AsyncLocalStorage();
|
|
1153
|
+
function getMcpAuthContext() {
|
|
1154
|
+
return authContextStorage.getStore();
|
|
1155
|
+
}
|
|
1156
|
+
function runWithAuthContext(context, fn) {
|
|
1157
|
+
return authContextStorage.run(context, fn);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
//#endregion
|
|
1161
|
+
//#region src/mcp/handler.ts
|
|
1162
|
+
function createMcpHandler(server, options = {}) {
|
|
1163
|
+
const route = options.route ?? "/mcp";
|
|
1164
|
+
return async (request, _env, ctx) => {
|
|
1165
|
+
const url = new URL(request.url);
|
|
1166
|
+
if (route && url.pathname !== route) return new Response("Not Found", { status: 404 });
|
|
1167
|
+
const transport = options.transport ?? new WorkerTransport({
|
|
1168
|
+
sessionIdGenerator: options.sessionIdGenerator,
|
|
1169
|
+
enableJsonResponse: options.enableJsonResponse,
|
|
1170
|
+
onsessioninitialized: options.onsessioninitialized,
|
|
1171
|
+
corsOptions: options.corsOptions,
|
|
1172
|
+
storage: options.storage
|
|
1173
|
+
});
|
|
1174
|
+
const buildAuthContext = () => {
|
|
1175
|
+
if (options.authContext) return options.authContext;
|
|
1176
|
+
if (ctx.props && Object.keys(ctx.props).length > 0) return { props: ctx.props };
|
|
1177
|
+
};
|
|
1178
|
+
const handleRequest = async () => {
|
|
1179
|
+
return await transport.handleRequest(request);
|
|
1180
|
+
};
|
|
1181
|
+
const authContext = buildAuthContext();
|
|
1182
|
+
if (!transport.started) await server.connect(transport);
|
|
1183
|
+
try {
|
|
1184
|
+
if (authContext) return await runWithAuthContext(authContext, handleRequest);
|
|
1185
|
+
else return await handleRequest();
|
|
1186
|
+
} catch (error) {
|
|
1187
|
+
console.error("MCP handler error:", error);
|
|
1188
|
+
return new Response(JSON.stringify({
|
|
1189
|
+
jsonrpc: "2.0",
|
|
1190
|
+
error: {
|
|
1191
|
+
code: -32603,
|
|
1192
|
+
message: error instanceof Error ? error.message : "Internal server error"
|
|
1193
|
+
},
|
|
1194
|
+
id: null
|
|
1195
|
+
}), {
|
|
1196
|
+
status: 500,
|
|
1197
|
+
headers: { "Content-Type": "application/json" }
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
let didWarnAboutExperimentalCreateMcpHandler = false;
|
|
1203
|
+
/**
|
|
1204
|
+
* @deprecated This has been renamed to createMcpHandler, and experimental_createMcpHandler will be removed in the next major version
|
|
1205
|
+
*/
|
|
1206
|
+
function experimental_createMcpHandler(server, options = {}) {
|
|
1207
|
+
if (!didWarnAboutExperimentalCreateMcpHandler) {
|
|
1208
|
+
didWarnAboutExperimentalCreateMcpHandler = true;
|
|
1209
|
+
console.warn("experimental_createMcpHandler is deprecated, use createMcpHandler instead. experimental_createMcpHandler will be removed in the next major version.");
|
|
1210
|
+
}
|
|
1211
|
+
return createMcpHandler(server, options);
|
|
1212
|
+
}
|
|
1213
|
+
|
|
627
1214
|
//#endregion
|
|
628
1215
|
//#region src/mcp/index.ts
|
|
629
1216
|
var McpAgent = class McpAgent extends Agent {
|
|
@@ -813,7 +1400,7 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
813
1400
|
/** Return a handler for the given path for this MCP.
|
|
814
1401
|
* Defaults to Streamable HTTP transport.
|
|
815
1402
|
*/
|
|
816
|
-
static serve(path, { binding = "MCP_OBJECT", corsOptions, transport = "streamable-http" } = {}) {
|
|
1403
|
+
static serve(path, { binding = "MCP_OBJECT", corsOptions, transport = "streamable-http", jurisdiction } = {}) {
|
|
817
1404
|
return { async fetch(request, env, ctx) {
|
|
818
1405
|
const corsResponse = handleCORS(request, corsOptions);
|
|
819
1406
|
if (corsResponse) return corsResponse;
|
|
@@ -822,8 +1409,14 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
822
1409
|
if (!isDurableObjectNamespace(bindingValue)) throw new Error(`Invalid McpAgent binding for ${binding}. Make sure it's a Durable Object binding.`);
|
|
823
1410
|
const namespace = bindingValue;
|
|
824
1411
|
switch (transport) {
|
|
825
|
-
case "streamable-http": return createStreamingHttpHandler(path, namespace,
|
|
826
|
-
|
|
1412
|
+
case "streamable-http": return createStreamingHttpHandler(path, namespace, {
|
|
1413
|
+
corsOptions,
|
|
1414
|
+
jurisdiction
|
|
1415
|
+
})(request, ctx);
|
|
1416
|
+
case "sse": return createLegacySseHandler(path, namespace, {
|
|
1417
|
+
corsOptions,
|
|
1418
|
+
jurisdiction
|
|
1419
|
+
})(request, ctx);
|
|
827
1420
|
default: return new Response("Invalid MCP transport mode. Only `streamable-http` or `sse` are allowed.", { status: 500 });
|
|
828
1421
|
}
|
|
829
1422
|
} };
|
|
@@ -843,5 +1436,5 @@ var McpAgent = class McpAgent extends Agent {
|
|
|
843
1436
|
};
|
|
844
1437
|
|
|
845
1438
|
//#endregion
|
|
846
|
-
export { ElicitRequestSchema, McpAgent, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport };
|
|
1439
|
+
export { ElicitRequestSchema, McpAgent, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, WorkerTransport, createMcpHandler, experimental_createMcpHandler, getMcpAuthContext };
|
|
847
1440
|
//# sourceMappingURL=index.js.map
|