agents 0.0.94 → 0.0.96

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.
@@ -1,10 +1,10 @@
1
1
  import * as zod from 'zod';
2
- import { Tool, Prompt, Resource, ResourceTemplate, ServerCapabilities, CallToolRequest, CallToolResultSchema, CompatibilityCallToolResultSchema, ReadResourceRequest, GetPromptRequest } from '@modelcontextprotocol/sdk/types.js';
3
2
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
4
3
  import { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
5
- import { AgentsOAuthProvider } from './do-oauth-client-provider.js';
6
4
  import { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
5
+ import { Tool, Prompt, Resource, ResourceTemplate, ServerCapabilities, CallToolRequest, CallToolResultSchema, CompatibilityCallToolResultSchema, ReadResourceRequest, GetPromptRequest } from '@modelcontextprotocol/sdk/types.js';
7
6
  import { ToolSet } from 'ai';
7
+ import { AgentsOAuthProvider } from './do-oauth-client-provider.js';
8
8
  import '@modelcontextprotocol/sdk/client/auth.js';
9
9
  import '@modelcontextprotocol/sdk/shared/auth.js';
10
10
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MCPClientManager,
3
3
  getNamespacedData
4
- } from "../chunk-OYJXQRRH.js";
4
+ } from "../chunk-E3LCYPCB.js";
5
5
  export {
6
6
  MCPClientManager,
7
7
  getNamespacedData
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DurableObjectOAuthClientProvider
3
- } from "../chunk-BZXOAZUX.js";
3
+ } from "../chunk-767EASBA.js";
4
4
  export {
5
5
  DurableObjectOAuthClientProvider
6
6
  };
@@ -1,17 +1,17 @@
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
6
  import 'zod';
7
- import '@modelcontextprotocol/sdk/types.js';
8
7
  import '@modelcontextprotocol/sdk/client/index.js';
9
8
  import '@modelcontextprotocol/sdk/client/sse.js';
9
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
10
+ import '@modelcontextprotocol/sdk/types.js';
11
+ import 'ai';
10
12
  import './do-oauth-client-provider.js';
11
13
  import '@modelcontextprotocol/sdk/client/auth.js';
12
14
  import '@modelcontextprotocol/sdk/shared/auth.js';
13
- import '@modelcontextprotocol/sdk/shared/protocol.js';
14
- import 'ai';
15
15
 
16
16
  interface CORSOptions {
17
17
  origin?: string;
@@ -57,7 +57,7 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
57
57
  getWebSocket(): WebSocket | null;
58
58
  getWebSocketForResponseID(id: string): WebSocket | null;
59
59
  onMessage(connection: Connection, event: WSMessage): Promise<void>;
60
- onSSEMcpMessage(sessionId: string, request: Request): Promise<Error | null>;
60
+ onSSEMcpMessage(_sessionId: string, request: Request): Promise<Error | null>;
61
61
  webSocketMessage(ws: WebSocket, event: ArrayBuffer | string): Promise<void>;
62
62
  webSocketError(ws: WebSocket, error: unknown): Promise<void>;
63
63
  webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean): Promise<void>;
package/dist/mcp/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Agent
3
- } from "../chunk-6RPGDIE2.js";
4
- import "../chunk-OYJXQRRH.js";
5
- import "../chunk-BZXOAZUX.js";
6
- import "../chunk-VCSB47AK.js";
3
+ } from "../chunk-ZRRXJUAA.js";
4
+ import "../chunk-E3LCYPCB.js";
5
+ import "../chunk-767EASBA.js";
6
+ import "../chunk-NKZZ66QY.js";
7
7
 
8
8
  // src/mcp/index.ts
9
9
  import { DurableObject } from "cloudflare:workers";
@@ -16,14 +16,14 @@ import {
16
16
  JSONRPCMessageSchema
17
17
  } from "@modelcontextprotocol/sdk/types.js";
18
18
  var MAXIMUM_MESSAGE_SIZE_BYTES = 4 * 1024 * 1024;
19
- function corsHeaders(request, corsOptions = {}) {
19
+ function corsHeaders(_request, corsOptions = {}) {
20
20
  const origin = "*";
21
21
  return {
22
- "Access-Control-Allow-Origin": corsOptions.origin || origin,
23
- "Access-Control-Allow-Methods": corsOptions.methods || "GET, POST, OPTIONS",
24
22
  "Access-Control-Allow-Headers": corsOptions.headers || "Content-Type, mcp-session-id",
25
- "Access-Control-Max-Age": (corsOptions.maxAge || 86400).toString(),
26
- "Access-Control-Expose-Headers": corsOptions.exposeHeaders || "mcp-session-id"
23
+ "Access-Control-Allow-Methods": corsOptions.methods || "GET, POST, OPTIONS",
24
+ "Access-Control-Allow-Origin": corsOptions.origin || origin,
25
+ "Access-Control-Expose-Headers": corsOptions.exposeHeaders || "mcp-session-id",
26
+ "Access-Control-Max-Age": (corsOptions.maxAge || 86400).toString()
27
27
  };
28
28
  }
29
29
  function isDurableObjectNamespace(namespace) {
@@ -141,6 +141,7 @@ var McpAgent = class _McpAgent extends DurableObject {
141
141
  setState(state) {
142
142
  return this._agent.setState(state);
143
143
  }
144
+ // biome-ignore lint/correctness/noUnusedFunctionParameters: overriden later
144
145
  onStateUpdate(state, source) {
145
146
  }
146
147
  async onStart() {
@@ -287,7 +288,7 @@ var McpAgent = class _McpAgent extends DurableObject {
287
288
  }
288
289
  // All messages received over SSE after the initial connection has been established
289
290
  // will be passed here
290
- async onSSEMcpMessage(sessionId, request) {
291
+ async onSSEMcpMessage(_sessionId, request) {
291
292
  if (this._status !== "started") {
292
293
  await this._initialize();
293
294
  }
@@ -420,10 +421,10 @@ data: ${JSON.stringify(result.data)}
420
421
  onMessage(event).catch(console.error);
421
422
  });
422
423
  ws.addEventListener("error", (error) => {
423
- async function onError(error2) {
424
+ async function onError(_error) {
424
425
  try {
425
426
  await writer.close();
426
- } catch (e) {
427
+ } catch (_e) {
427
428
  }
428
429
  }
429
430
  onError(error).catch(console.error);
@@ -440,9 +441,9 @@ data: ${JSON.stringify(result.data)}
440
441
  });
441
442
  return new Response(readable, {
442
443
  headers: {
443
- "Content-Type": "text/event-stream",
444
444
  "Cache-Control": "no-cache",
445
445
  Connection: "keep-alive",
446
+ "Content-Type": "text/event-stream",
446
447
  ...corsHeaders(request, corsOptions)
447
448
  }
448
449
  });
@@ -478,23 +479,23 @@ data: ${JSON.stringify(result.data)}
478
479
  const error = await doStub.onSSEMcpMessage(sessionId, request);
479
480
  if (error) {
480
481
  return new Response(error.message, {
481
- status: 400,
482
482
  headers: {
483
- "Content-Type": "text/event-stream",
484
483
  "Cache-Control": "no-cache",
485
484
  Connection: "keep-alive",
485
+ "Content-Type": "text/event-stream",
486
486
  ...corsHeaders(request, corsOptions)
487
- }
487
+ },
488
+ status: 400
488
489
  });
489
490
  }
490
491
  return new Response("Accepted", {
491
- status: 202,
492
492
  headers: {
493
- "Content-Type": "text/event-stream",
494
493
  "Cache-Control": "no-cache",
495
494
  Connection: "keep-alive",
495
+ "Content-Type": "text/event-stream",
496
496
  ...corsHeaders(request, corsOptions)
497
- }
497
+ },
498
+ status: 202
498
499
  });
499
500
  }
500
501
  return new Response("Not Found", { status: 404 });
@@ -532,24 +533,24 @@ data: ${JSON.stringify(result.data)}
532
533
  const acceptHeader = request.headers.get("accept");
533
534
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
534
535
  const body2 = JSON.stringify({
535
- jsonrpc: "2.0",
536
536
  error: {
537
537
  code: -32e3,
538
538
  message: "Not Acceptable: Client must accept both application/json and text/event-stream"
539
539
  },
540
- id: null
540
+ id: null,
541
+ jsonrpc: "2.0"
541
542
  });
542
543
  return new Response(body2, { status: 406 });
543
544
  }
544
545
  const ct = request.headers.get("content-type");
545
546
  if (!ct || !ct.includes("application/json")) {
546
547
  const body2 = JSON.stringify({
547
- jsonrpc: "2.0",
548
548
  error: {
549
549
  code: -32e3,
550
550
  message: "Unsupported Media Type: Content-Type must be application/json"
551
551
  },
552
- id: null
552
+ id: null,
553
+ jsonrpc: "2.0"
553
554
  });
554
555
  return new Response(body2, { status: 415 });
555
556
  }
@@ -559,12 +560,12 @@ data: ${JSON.stringify(result.data)}
559
560
  );
560
561
  if (contentLength > MAXIMUM_MESSAGE_SIZE_BYTES) {
561
562
  const body2 = JSON.stringify({
562
- jsonrpc: "2.0",
563
563
  error: {
564
564
  code: -32e3,
565
565
  message: `Request body too large. Maximum size is ${MAXIMUM_MESSAGE_SIZE_BYTES} bytes`
566
566
  },
567
- id: null
567
+ id: null,
568
+ jsonrpc: "2.0"
568
569
  });
569
570
  return new Response(body2, { status: 413 });
570
571
  }
@@ -572,14 +573,14 @@ data: ${JSON.stringify(result.data)}
572
573
  let rawMessage;
573
574
  try {
574
575
  rawMessage = await request.json();
575
- } catch (error) {
576
+ } catch (_error) {
576
577
  const body2 = JSON.stringify({
577
- jsonrpc: "2.0",
578
578
  error: {
579
579
  code: -32700,
580
580
  message: "Parse error: Invalid JSON"
581
581
  },
582
- id: null
582
+ id: null,
583
+ jsonrpc: "2.0"
583
584
  });
584
585
  return new Response(body2, { status: 400 });
585
586
  }
@@ -593,12 +594,12 @@ data: ${JSON.stringify(result.data)}
593
594
  for (const msg of arrayMessage) {
594
595
  if (!JSONRPCMessageSchema.safeParse(msg).success) {
595
596
  const body2 = JSON.stringify({
596
- jsonrpc: "2.0",
597
597
  error: {
598
598
  code: -32700,
599
599
  message: "Parse error: Invalid JSON-RPC message"
600
600
  },
601
- id: null
601
+ id: null,
602
+ jsonrpc: "2.0"
602
603
  });
603
604
  return new Response(body2, { status: 400 });
604
605
  }
@@ -609,34 +610,34 @@ data: ${JSON.stringify(result.data)}
609
610
  );
610
611
  if (isInitializationRequest && sessionId) {
611
612
  const body2 = JSON.stringify({
612
- jsonrpc: "2.0",
613
613
  error: {
614
614
  code: -32600,
615
615
  message: "Invalid Request: Initialization requests must not include a sessionId"
616
616
  },
617
- id: null
617
+ id: null,
618
+ jsonrpc: "2.0"
618
619
  });
619
620
  return new Response(body2, { status: 400 });
620
621
  }
621
622
  if (isInitializationRequest && messages.length > 1) {
622
623
  const body2 = JSON.stringify({
623
- jsonrpc: "2.0",
624
624
  error: {
625
625
  code: -32600,
626
626
  message: "Invalid Request: Only one initialization request is allowed"
627
627
  },
628
- id: null
628
+ id: null,
629
+ jsonrpc: "2.0"
629
630
  });
630
631
  return new Response(body2, { status: 400 });
631
632
  }
632
633
  if (!isInitializationRequest && !sessionId) {
633
634
  const body2 = JSON.stringify({
634
- jsonrpc: "2.0",
635
635
  error: {
636
636
  code: -32e3,
637
637
  message: "Bad Request: Mcp-Session-Id header is required"
638
638
  },
639
- id: null
639
+ id: null,
640
+ jsonrpc: "2.0"
640
641
  });
641
642
  return new Response(body2, { status: 400 });
642
643
  }
@@ -649,12 +650,12 @@ data: ${JSON.stringify(result.data)}
649
650
  await doStub.setInitialized();
650
651
  } else if (!isInitialized) {
651
652
  const body2 = JSON.stringify({
652
- jsonrpc: "2.0",
653
653
  error: {
654
654
  code: -32001,
655
655
  message: "Session not found"
656
656
  },
657
- id: null
657
+ id: null,
658
+ jsonrpc: "2.0"
658
659
  });
659
660
  return new Response(body2, { status: 404 });
660
661
  }
@@ -677,12 +678,12 @@ data: ${JSON.stringify(result.data)}
677
678
  console.error("Failed to establish WebSocket connection");
678
679
  await writer.close();
679
680
  const body2 = JSON.stringify({
680
- jsonrpc: "2.0",
681
681
  error: {
682
682
  code: -32001,
683
683
  message: "Failed to establish WebSocket connection"
684
684
  },
685
- id: null
685
+ id: null,
686
+ jsonrpc: "2.0"
686
687
  });
687
688
  return new Response(body2, { status: 500 });
688
689
  }
@@ -715,10 +716,10 @@ data: ${JSON.stringify(result.data)}
715
716
  onMessage(event).catch(console.error);
716
717
  });
717
718
  ws.addEventListener("error", (error) => {
718
- async function onError(error2) {
719
+ async function onError(_error) {
719
720
  try {
720
721
  await writer.close();
721
- } catch (e) {
722
+ } catch (_e) {
722
723
  }
723
724
  }
724
725
  onError(error).catch(console.error);
@@ -742,8 +743,8 @@ data: ${JSON.stringify(result.data)}
742
743
  }
743
744
  ws.close();
744
745
  return new Response(null, {
745
- status: 202,
746
- headers: corsHeaders(request, corsOptions)
746
+ headers: corsHeaders(request, corsOptions),
747
+ status: 202
747
748
  });
748
749
  }
749
750
  for (const message of messages) {
@@ -754,9 +755,9 @@ data: ${JSON.stringify(result.data)}
754
755
  }
755
756
  return new Response(readable, {
756
757
  headers: {
757
- "Content-Type": "text/event-stream",
758
758
  "Cache-Control": "no-cache",
759
759
  Connection: "keep-alive",
760
+ "Content-Type": "text/event-stream",
760
761
  "mcp-session-id": sessionId,
761
762
  ...corsHeaders(request, corsOptions)
762
763
  },
@@ -764,12 +765,12 @@ data: ${JSON.stringify(result.data)}
764
765
  });
765
766
  }
766
767
  const body = JSON.stringify({
767
- jsonrpc: "2.0",
768
768
  error: {
769
769
  code: -32e3,
770
770
  message: "Method not allowed"
771
771
  },
772
- id: null
772
+ id: null,
773
+ jsonrpc: "2.0"
773
774
  });
774
775
  return new Response(body, { status: 405 });
775
776
  }