agents 0.0.0-8671aae → 0.0.0-86abae8
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 +92 -22
- package/dist/ai-chat-agent.d.ts +5 -3
- package/dist/ai-chat-agent.js +64 -26
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-react.d.ts +10 -9
- package/dist/ai-react.js +27 -27
- package/dist/ai-react.js.map +1 -1
- package/dist/{chunk-VCSB47AK.js → chunk-KUH345EY.js} +8 -8
- package/dist/chunk-KUH345EY.js.map +1 -0
- package/dist/{chunk-BZXOAZUX.js → chunk-PVQZBKN7.js} +5 -5
- package/dist/chunk-PVQZBKN7.js.map +1 -0
- package/dist/{chunk-OYJXQRRH.js → chunk-UNG3FXYX.js} +79 -19
- package/dist/chunk-UNG3FXYX.js.map +1 -0
- package/dist/{chunk-P3RZJ72N.js → chunk-Z2OUUKK4.js} +614 -127
- package/dist/chunk-Z2OUUKK4.js.map +1 -0
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/index-BIJvkfYt.d.ts +614 -0
- package/dist/index.d.ts +34 -405
- package/dist/index.js +10 -4
- package/dist/mcp/client.d.ts +290 -19
- package/dist/mcp/client.js +1 -1
- package/dist/mcp/do-oauth-client-provider.js +1 -1
- package/dist/mcp/index.d.ts +34 -11
- package/dist/mcp/index.js +56 -50
- package/dist/mcp/index.js.map +1 -1
- package/dist/observability/index.d.ts +13 -0
- package/dist/observability/index.js +10 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/react.d.ts +9 -8
- package/dist/react.js +7 -7
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +6 -6
- package/dist/schedule.js +4 -4
- package/dist/schedule.js.map +1 -1
- package/package.json +76 -71
- package/src/index.ts +799 -157
- package/dist/chunk-BZXOAZUX.js.map +0 -1
- package/dist/chunk-OYJXQRRH.js.map +0 -1
- package/dist/chunk-P3RZJ72N.js.map +0 -1
- package/dist/chunk-VCSB47AK.js.map +0 -1
package/dist/mcp/client.js
CHANGED
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
import { MCPClientManager } from './client.js';
|
|
2
2
|
import { DurableObject } from 'cloudflare:workers';
|
|
3
|
-
import { Connection, WSMessage } from 'partyserver';
|
|
4
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
3
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
import { Connection, WSMessage } from 'partyserver';
|
|
6
|
+
import { SSEClientTransport, SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
7
|
+
import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
6
8
|
import 'zod';
|
|
7
|
-
import '@modelcontextprotocol/sdk/types.js';
|
|
8
9
|
import '@modelcontextprotocol/sdk/client/index.js';
|
|
9
|
-
import '@modelcontextprotocol/sdk/
|
|
10
|
+
import '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
11
|
+
import '@modelcontextprotocol/sdk/types.js';
|
|
12
|
+
import 'ai';
|
|
10
13
|
import './do-oauth-client-provider.js';
|
|
11
14
|
import '@modelcontextprotocol/sdk/client/auth.js';
|
|
12
15
|
import '@modelcontextprotocol/sdk/shared/auth.js';
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
declare class SSEEdgeClientTransport extends SSEClientTransport {
|
|
18
|
+
private authProvider;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new EdgeSSEClientTransport, which overrides fetch to be compatible with the CF workers environment
|
|
21
|
+
*/
|
|
22
|
+
constructor(url: URL, options: SSEClientTransportOptions);
|
|
23
|
+
authHeaders(): Promise<{
|
|
24
|
+
Authorization: string;
|
|
25
|
+
} | undefined>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
|
|
29
|
+
private authProvider;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new StreamableHTTPEdgeClientTransport, which overrides fetch to be compatible with the CF workers environment
|
|
32
|
+
*/
|
|
33
|
+
constructor(url: URL, options: StreamableHTTPClientTransportOptions);
|
|
34
|
+
authHeaders(): Promise<{
|
|
35
|
+
Authorization: string;
|
|
36
|
+
} | undefined>;
|
|
37
|
+
}
|
|
15
38
|
|
|
16
39
|
interface CORSOptions {
|
|
17
40
|
origin?: string;
|
|
@@ -57,23 +80,23 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
|
|
|
57
80
|
getWebSocket(): WebSocket | null;
|
|
58
81
|
getWebSocketForResponseID(id: string): WebSocket | null;
|
|
59
82
|
onMessage(connection: Connection, event: WSMessage): Promise<void>;
|
|
60
|
-
onSSEMcpMessage(
|
|
83
|
+
onSSEMcpMessage(_sessionId: string, request: Request): Promise<Error | null>;
|
|
61
84
|
webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
|
|
62
85
|
webSocketError(ws: WebSocket, error: unknown): Promise<void>;
|
|
63
86
|
webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
|
|
64
|
-
static mount(path: string, { binding, corsOptions
|
|
87
|
+
static mount(path: string, { binding, corsOptions }?: {
|
|
65
88
|
binding?: string;
|
|
66
89
|
corsOptions?: CORSOptions;
|
|
67
90
|
}): {
|
|
68
91
|
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
69
92
|
};
|
|
70
|
-
static serveSSE(path: string, { binding, corsOptions
|
|
93
|
+
static serveSSE(path: string, { binding, corsOptions }?: {
|
|
71
94
|
binding?: string;
|
|
72
95
|
corsOptions?: CORSOptions;
|
|
73
96
|
}): {
|
|
74
97
|
fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
75
98
|
};
|
|
76
|
-
static serve(path: string, { binding, corsOptions
|
|
99
|
+
static serve(path: string, { binding, corsOptions }?: {
|
|
77
100
|
binding?: string;
|
|
78
101
|
corsOptions?: CORSOptions;
|
|
79
102
|
}): {
|
|
@@ -81,4 +104,4 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
|
|
|
81
104
|
};
|
|
82
105
|
}
|
|
83
106
|
|
|
84
|
-
export { McpAgent };
|
|
107
|
+
export { McpAgent, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport };
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Agent
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
} from "../chunk-Z2OUUKK4.js";
|
|
4
|
+
import {
|
|
5
|
+
SSEEdgeClientTransport,
|
|
6
|
+
StreamableHTTPEdgeClientTransport
|
|
7
|
+
} from "../chunk-UNG3FXYX.js";
|
|
8
|
+
import "../chunk-PVQZBKN7.js";
|
|
9
|
+
import "../chunk-KUH345EY.js";
|
|
7
10
|
|
|
8
11
|
// src/mcp/index.ts
|
|
9
12
|
import { DurableObject } from "cloudflare:workers";
|
|
10
13
|
import {
|
|
11
14
|
InitializeRequestSchema,
|
|
15
|
+
JSONRPCMessageSchema,
|
|
12
16
|
isJSONRPCError,
|
|
13
17
|
isJSONRPCNotification,
|
|
14
18
|
isJSONRPCRequest,
|
|
15
|
-
isJSONRPCResponse
|
|
16
|
-
JSONRPCMessageSchema
|
|
19
|
+
isJSONRPCResponse
|
|
17
20
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
18
21
|
var MAXIMUM_MESSAGE_SIZE_BYTES = 4 * 1024 * 1024;
|
|
19
|
-
function corsHeaders(
|
|
22
|
+
function corsHeaders(_request, corsOptions = {}) {
|
|
20
23
|
const origin = "*";
|
|
21
24
|
return {
|
|
22
|
-
"Access-Control-Allow-
|
|
25
|
+
"Access-Control-Allow-Headers": corsOptions.headers || "Content-Type, mcp-session-id, mcp-protocol-version",
|
|
23
26
|
"Access-Control-Allow-Methods": corsOptions.methods || "GET, POST, OPTIONS",
|
|
24
|
-
"Access-Control-Allow-
|
|
25
|
-
"Access-Control-
|
|
26
|
-
"Access-Control-
|
|
27
|
+
"Access-Control-Allow-Origin": corsOptions.origin || origin,
|
|
28
|
+
"Access-Control-Expose-Headers": corsOptions.exposeHeaders || "mcp-session-id",
|
|
29
|
+
"Access-Control-Max-Age": (corsOptions.maxAge || 86400).toString()
|
|
27
30
|
};
|
|
28
31
|
}
|
|
29
32
|
function isDurableObjectNamespace(namespace) {
|
|
@@ -141,6 +144,7 @@ var McpAgent = class _McpAgent extends DurableObject {
|
|
|
141
144
|
setState(state) {
|
|
142
145
|
return this._agent.setState(state);
|
|
143
146
|
}
|
|
147
|
+
// biome-ignore lint/correctness/noUnusedFunctionParameters: overriden later
|
|
144
148
|
onStateUpdate(state, source) {
|
|
145
149
|
}
|
|
146
150
|
async onStart() {
|
|
@@ -287,7 +291,7 @@ var McpAgent = class _McpAgent extends DurableObject {
|
|
|
287
291
|
}
|
|
288
292
|
// All messages received over SSE after the initial connection has been established
|
|
289
293
|
// will be passed here
|
|
290
|
-
async onSSEMcpMessage(
|
|
294
|
+
async onSSEMcpMessage(_sessionId, request) {
|
|
291
295
|
if (this._status !== "started") {
|
|
292
296
|
await this._initialize();
|
|
293
297
|
}
|
|
@@ -420,10 +424,10 @@ data: ${JSON.stringify(result.data)}
|
|
|
420
424
|
onMessage(event).catch(console.error);
|
|
421
425
|
});
|
|
422
426
|
ws.addEventListener("error", (error) => {
|
|
423
|
-
async function onError(
|
|
427
|
+
async function onError(_error) {
|
|
424
428
|
try {
|
|
425
429
|
await writer.close();
|
|
426
|
-
} catch (
|
|
430
|
+
} catch (_e) {
|
|
427
431
|
}
|
|
428
432
|
}
|
|
429
433
|
onError(error).catch(console.error);
|
|
@@ -440,9 +444,9 @@ data: ${JSON.stringify(result.data)}
|
|
|
440
444
|
});
|
|
441
445
|
return new Response(readable, {
|
|
442
446
|
headers: {
|
|
443
|
-
"Content-Type": "text/event-stream",
|
|
444
447
|
"Cache-Control": "no-cache",
|
|
445
448
|
Connection: "keep-alive",
|
|
449
|
+
"Content-Type": "text/event-stream",
|
|
446
450
|
...corsHeaders(request, corsOptions)
|
|
447
451
|
}
|
|
448
452
|
});
|
|
@@ -478,23 +482,23 @@ data: ${JSON.stringify(result.data)}
|
|
|
478
482
|
const error = await doStub.onSSEMcpMessage(sessionId, request);
|
|
479
483
|
if (error) {
|
|
480
484
|
return new Response(error.message, {
|
|
481
|
-
status: 400,
|
|
482
485
|
headers: {
|
|
483
|
-
"Content-Type": "text/event-stream",
|
|
484
486
|
"Cache-Control": "no-cache",
|
|
485
487
|
Connection: "keep-alive",
|
|
488
|
+
"Content-Type": "text/event-stream",
|
|
486
489
|
...corsHeaders(request, corsOptions)
|
|
487
|
-
}
|
|
490
|
+
},
|
|
491
|
+
status: 400
|
|
488
492
|
});
|
|
489
493
|
}
|
|
490
494
|
return new Response("Accepted", {
|
|
491
|
-
status: 202,
|
|
492
495
|
headers: {
|
|
493
|
-
"Content-Type": "text/event-stream",
|
|
494
496
|
"Cache-Control": "no-cache",
|
|
495
497
|
Connection: "keep-alive",
|
|
498
|
+
"Content-Type": "text/event-stream",
|
|
496
499
|
...corsHeaders(request, corsOptions)
|
|
497
|
-
}
|
|
500
|
+
},
|
|
501
|
+
status: 202
|
|
498
502
|
});
|
|
499
503
|
}
|
|
500
504
|
return new Response("Not Found", { status: 404 });
|
|
@@ -532,24 +536,24 @@ data: ${JSON.stringify(result.data)}
|
|
|
532
536
|
const acceptHeader = request.headers.get("accept");
|
|
533
537
|
if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
|
|
534
538
|
const body2 = JSON.stringify({
|
|
535
|
-
jsonrpc: "2.0",
|
|
536
539
|
error: {
|
|
537
540
|
code: -32e3,
|
|
538
541
|
message: "Not Acceptable: Client must accept both application/json and text/event-stream"
|
|
539
542
|
},
|
|
540
|
-
id: null
|
|
543
|
+
id: null,
|
|
544
|
+
jsonrpc: "2.0"
|
|
541
545
|
});
|
|
542
546
|
return new Response(body2, { status: 406 });
|
|
543
547
|
}
|
|
544
548
|
const ct = request.headers.get("content-type");
|
|
545
549
|
if (!ct || !ct.includes("application/json")) {
|
|
546
550
|
const body2 = JSON.stringify({
|
|
547
|
-
jsonrpc: "2.0",
|
|
548
551
|
error: {
|
|
549
552
|
code: -32e3,
|
|
550
553
|
message: "Unsupported Media Type: Content-Type must be application/json"
|
|
551
554
|
},
|
|
552
|
-
id: null
|
|
555
|
+
id: null,
|
|
556
|
+
jsonrpc: "2.0"
|
|
553
557
|
});
|
|
554
558
|
return new Response(body2, { status: 415 });
|
|
555
559
|
}
|
|
@@ -559,12 +563,12 @@ data: ${JSON.stringify(result.data)}
|
|
|
559
563
|
);
|
|
560
564
|
if (contentLength > MAXIMUM_MESSAGE_SIZE_BYTES) {
|
|
561
565
|
const body2 = JSON.stringify({
|
|
562
|
-
jsonrpc: "2.0",
|
|
563
566
|
error: {
|
|
564
567
|
code: -32e3,
|
|
565
568
|
message: `Request body too large. Maximum size is ${MAXIMUM_MESSAGE_SIZE_BYTES} bytes`
|
|
566
569
|
},
|
|
567
|
-
id: null
|
|
570
|
+
id: null,
|
|
571
|
+
jsonrpc: "2.0"
|
|
568
572
|
});
|
|
569
573
|
return new Response(body2, { status: 413 });
|
|
570
574
|
}
|
|
@@ -572,14 +576,14 @@ data: ${JSON.stringify(result.data)}
|
|
|
572
576
|
let rawMessage;
|
|
573
577
|
try {
|
|
574
578
|
rawMessage = await request.json();
|
|
575
|
-
} catch (
|
|
579
|
+
} catch (_error) {
|
|
576
580
|
const body2 = JSON.stringify({
|
|
577
|
-
jsonrpc: "2.0",
|
|
578
581
|
error: {
|
|
579
582
|
code: -32700,
|
|
580
583
|
message: "Parse error: Invalid JSON"
|
|
581
584
|
},
|
|
582
|
-
id: null
|
|
585
|
+
id: null,
|
|
586
|
+
jsonrpc: "2.0"
|
|
583
587
|
});
|
|
584
588
|
return new Response(body2, { status: 400 });
|
|
585
589
|
}
|
|
@@ -593,12 +597,12 @@ data: ${JSON.stringify(result.data)}
|
|
|
593
597
|
for (const msg of arrayMessage) {
|
|
594
598
|
if (!JSONRPCMessageSchema.safeParse(msg).success) {
|
|
595
599
|
const body2 = JSON.stringify({
|
|
596
|
-
jsonrpc: "2.0",
|
|
597
600
|
error: {
|
|
598
601
|
code: -32700,
|
|
599
602
|
message: "Parse error: Invalid JSON-RPC message"
|
|
600
603
|
},
|
|
601
|
-
id: null
|
|
604
|
+
id: null,
|
|
605
|
+
jsonrpc: "2.0"
|
|
602
606
|
});
|
|
603
607
|
return new Response(body2, { status: 400 });
|
|
604
608
|
}
|
|
@@ -609,34 +613,34 @@ data: ${JSON.stringify(result.data)}
|
|
|
609
613
|
);
|
|
610
614
|
if (isInitializationRequest && sessionId) {
|
|
611
615
|
const body2 = JSON.stringify({
|
|
612
|
-
jsonrpc: "2.0",
|
|
613
616
|
error: {
|
|
614
617
|
code: -32600,
|
|
615
618
|
message: "Invalid Request: Initialization requests must not include a sessionId"
|
|
616
619
|
},
|
|
617
|
-
id: null
|
|
620
|
+
id: null,
|
|
621
|
+
jsonrpc: "2.0"
|
|
618
622
|
});
|
|
619
623
|
return new Response(body2, { status: 400 });
|
|
620
624
|
}
|
|
621
625
|
if (isInitializationRequest && messages.length > 1) {
|
|
622
626
|
const body2 = JSON.stringify({
|
|
623
|
-
jsonrpc: "2.0",
|
|
624
627
|
error: {
|
|
625
628
|
code: -32600,
|
|
626
629
|
message: "Invalid Request: Only one initialization request is allowed"
|
|
627
630
|
},
|
|
628
|
-
id: null
|
|
631
|
+
id: null,
|
|
632
|
+
jsonrpc: "2.0"
|
|
629
633
|
});
|
|
630
634
|
return new Response(body2, { status: 400 });
|
|
631
635
|
}
|
|
632
636
|
if (!isInitializationRequest && !sessionId) {
|
|
633
637
|
const body2 = JSON.stringify({
|
|
634
|
-
jsonrpc: "2.0",
|
|
635
638
|
error: {
|
|
636
639
|
code: -32e3,
|
|
637
640
|
message: "Bad Request: Mcp-Session-Id header is required"
|
|
638
641
|
},
|
|
639
|
-
id: null
|
|
642
|
+
id: null,
|
|
643
|
+
jsonrpc: "2.0"
|
|
640
644
|
});
|
|
641
645
|
return new Response(body2, { status: 400 });
|
|
642
646
|
}
|
|
@@ -649,12 +653,12 @@ data: ${JSON.stringify(result.data)}
|
|
|
649
653
|
await doStub.setInitialized();
|
|
650
654
|
} else if (!isInitialized) {
|
|
651
655
|
const body2 = JSON.stringify({
|
|
652
|
-
jsonrpc: "2.0",
|
|
653
656
|
error: {
|
|
654
657
|
code: -32001,
|
|
655
658
|
message: "Session not found"
|
|
656
659
|
},
|
|
657
|
-
id: null
|
|
660
|
+
id: null,
|
|
661
|
+
jsonrpc: "2.0"
|
|
658
662
|
});
|
|
659
663
|
return new Response(body2, { status: 404 });
|
|
660
664
|
}
|
|
@@ -677,12 +681,12 @@ data: ${JSON.stringify(result.data)}
|
|
|
677
681
|
console.error("Failed to establish WebSocket connection");
|
|
678
682
|
await writer.close();
|
|
679
683
|
const body2 = JSON.stringify({
|
|
680
|
-
jsonrpc: "2.0",
|
|
681
684
|
error: {
|
|
682
685
|
code: -32001,
|
|
683
686
|
message: "Failed to establish WebSocket connection"
|
|
684
687
|
},
|
|
685
|
-
id: null
|
|
688
|
+
id: null,
|
|
689
|
+
jsonrpc: "2.0"
|
|
686
690
|
});
|
|
687
691
|
return new Response(body2, { status: 500 });
|
|
688
692
|
}
|
|
@@ -715,10 +719,10 @@ data: ${JSON.stringify(result.data)}
|
|
|
715
719
|
onMessage(event).catch(console.error);
|
|
716
720
|
});
|
|
717
721
|
ws.addEventListener("error", (error) => {
|
|
718
|
-
async function onError(
|
|
722
|
+
async function onError(_error) {
|
|
719
723
|
try {
|
|
720
724
|
await writer.close();
|
|
721
|
-
} catch (
|
|
725
|
+
} catch (_e) {
|
|
722
726
|
}
|
|
723
727
|
}
|
|
724
728
|
onError(error).catch(console.error);
|
|
@@ -742,8 +746,8 @@ data: ${JSON.stringify(result.data)}
|
|
|
742
746
|
}
|
|
743
747
|
ws.close();
|
|
744
748
|
return new Response(null, {
|
|
745
|
-
|
|
746
|
-
|
|
749
|
+
headers: corsHeaders(request, corsOptions),
|
|
750
|
+
status: 202
|
|
747
751
|
});
|
|
748
752
|
}
|
|
749
753
|
for (const message of messages) {
|
|
@@ -754,9 +758,9 @@ data: ${JSON.stringify(result.data)}
|
|
|
754
758
|
}
|
|
755
759
|
return new Response(readable, {
|
|
756
760
|
headers: {
|
|
757
|
-
"Content-Type": "text/event-stream",
|
|
758
761
|
"Cache-Control": "no-cache",
|
|
759
762
|
Connection: "keep-alive",
|
|
763
|
+
"Content-Type": "text/event-stream",
|
|
760
764
|
"mcp-session-id": sessionId,
|
|
761
765
|
...corsHeaders(request, corsOptions)
|
|
762
766
|
},
|
|
@@ -764,12 +768,12 @@ data: ${JSON.stringify(result.data)}
|
|
|
764
768
|
});
|
|
765
769
|
}
|
|
766
770
|
const body = JSON.stringify({
|
|
767
|
-
jsonrpc: "2.0",
|
|
768
771
|
error: {
|
|
769
772
|
code: -32e3,
|
|
770
773
|
message: "Method not allowed"
|
|
771
774
|
},
|
|
772
|
-
id: null
|
|
775
|
+
id: null,
|
|
776
|
+
jsonrpc: "2.0"
|
|
773
777
|
});
|
|
774
778
|
return new Response(body, { status: 405 });
|
|
775
779
|
}
|
|
@@ -777,6 +781,8 @@ data: ${JSON.stringify(result.data)}
|
|
|
777
781
|
}
|
|
778
782
|
};
|
|
779
783
|
export {
|
|
780
|
-
McpAgent
|
|
784
|
+
McpAgent,
|
|
785
|
+
SSEEdgeClientTransport,
|
|
786
|
+
StreamableHTTPEdgeClientTransport
|
|
781
787
|
};
|
|
782
788
|
//# sourceMappingURL=index.js.map
|