agents 0.0.0-881f11e → 0.0.0-885b3db

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.
Files changed (47) hide show
  1. package/README.md +127 -22
  2. package/dist/ai-chat-agent.d.ts +33 -5
  3. package/dist/ai-chat-agent.js +149 -115
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-react.d.ts +18 -5
  6. package/dist/ai-react.js +27 -29
  7. package/dist/ai-react.js.map +1 -1
  8. package/dist/chunk-KUH345EY.js +116 -0
  9. package/dist/chunk-KUH345EY.js.map +1 -0
  10. package/dist/chunk-PVQZBKN7.js +106 -0
  11. package/dist/chunk-PVQZBKN7.js.map +1 -0
  12. package/dist/{chunk-7VFQNJFK.js → chunk-UNG3FXYX.js} +99 -36
  13. package/dist/chunk-UNG3FXYX.js.map +1 -0
  14. package/dist/chunk-Z2OUUKK4.js +1270 -0
  15. package/dist/chunk-Z2OUUKK4.js.map +1 -0
  16. package/dist/client.d.ts +16 -2
  17. package/dist/client.js +6 -126
  18. package/dist/client.js.map +1 -1
  19. package/dist/index-BIJvkfYt.d.ts +614 -0
  20. package/dist/index.d.ts +34 -312
  21. package/dist/index.js +10 -3
  22. package/dist/mcp/client.d.ts +302 -33
  23. package/dist/mcp/client.js +1 -2
  24. package/dist/mcp/do-oauth-client-provider.d.ts +3 -3
  25. package/dist/mcp/do-oauth-client-provider.js +3 -103
  26. package/dist/mcp/do-oauth-client-provider.js.map +1 -1
  27. package/dist/mcp/index.d.ts +44 -12
  28. package/dist/mcp/index.js +141 -169
  29. package/dist/mcp/index.js.map +1 -1
  30. package/dist/observability/index.d.ts +13 -0
  31. package/dist/observability/index.js +10 -0
  32. package/dist/react.d.ts +86 -5
  33. package/dist/react.js +20 -8
  34. package/dist/react.js.map +1 -1
  35. package/dist/schedule.d.ts +6 -6
  36. package/dist/schedule.js +4 -6
  37. package/dist/schedule.js.map +1 -1
  38. package/dist/serializable.d.ts +32 -0
  39. package/dist/serializable.js +1 -0
  40. package/dist/serializable.js.map +1 -0
  41. package/package.json +76 -71
  42. package/src/index.ts +1073 -135
  43. package/dist/chunk-7VFQNJFK.js.map +0 -1
  44. package/dist/chunk-HMLY7DHA.js +0 -16
  45. package/dist/chunk-JR3NW4A7.js +0 -621
  46. package/dist/chunk-JR3NW4A7.js.map +0 -1
  47. /package/dist/{chunk-HMLY7DHA.js.map → observability/index.js.map} +0 -0
package/dist/mcp/index.js CHANGED
@@ -1,59 +1,59 @@
1
1
  import {
2
2
  Agent
3
- } from "../chunk-JR3NW4A7.js";
4
- import "../chunk-7VFQNJFK.js";
3
+ } from "../chunk-Z2OUUKK4.js";
5
4
  import {
6
- __privateAdd,
7
- __privateGet,
8
- __privateMethod,
9
- __privateSet
10
- } from "../chunk-HMLY7DHA.js";
5
+ SSEEdgeClientTransport,
6
+ StreamableHTTPEdgeClientTransport
7
+ } from "../chunk-UNG3FXYX.js";
8
+ import "../chunk-PVQZBKN7.js";
9
+ import "../chunk-KUH345EY.js";
11
10
 
12
11
  // src/mcp/index.ts
13
12
  import { DurableObject } from "cloudflare:workers";
14
13
  import {
15
14
  InitializeRequestSchema,
15
+ JSONRPCMessageSchema,
16
16
  isJSONRPCError,
17
17
  isJSONRPCNotification,
18
18
  isJSONRPCRequest,
19
- isJSONRPCResponse,
20
- JSONRPCMessageSchema
19
+ isJSONRPCResponse
21
20
  } from "@modelcontextprotocol/sdk/types.js";
22
21
  var MAXIMUM_MESSAGE_SIZE_BYTES = 4 * 1024 * 1024;
23
- function corsHeaders(request, corsOptions = {}) {
22
+ function corsHeaders(_request, corsOptions = {}) {
24
23
  const origin = "*";
25
24
  return {
26
- "Access-Control-Allow-Origin": corsOptions.origin || origin,
25
+ "Access-Control-Allow-Headers": corsOptions.headers || "Content-Type, mcp-session-id, mcp-protocol-version",
27
26
  "Access-Control-Allow-Methods": corsOptions.methods || "GET, POST, OPTIONS",
28
- "Access-Control-Allow-Headers": corsOptions.headers || "Content-Type, mcp-session-id",
29
- "Access-Control-Max-Age": (corsOptions.maxAge || 86400).toString(),
30
- "Access-Control-Expose-Headers": corsOptions.exposeHeaders || "mcp-session-id"
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()
31
30
  };
32
31
  }
32
+ function isDurableObjectNamespace(namespace) {
33
+ return typeof namespace === "object" && namespace !== null && "newUniqueId" in namespace && typeof namespace.newUniqueId === "function" && "idFromName" in namespace && typeof namespace.idFromName === "function";
34
+ }
33
35
  function handleCORS(request, corsOptions) {
34
36
  if (request.method === "OPTIONS") {
35
37
  return new Response(null, { headers: corsHeaders(request, corsOptions) });
36
38
  }
37
39
  return null;
38
40
  }
39
- var _getWebSocket, _started;
40
41
  var McpSSETransport = class {
41
42
  constructor(getWebSocket) {
42
- __privateAdd(this, _getWebSocket);
43
- __privateAdd(this, _started, false);
44
- __privateSet(this, _getWebSocket, getWebSocket);
43
+ this._started = false;
44
+ this._getWebSocket = getWebSocket;
45
45
  }
46
46
  async start() {
47
- if (__privateGet(this, _started)) {
47
+ if (this._started) {
48
48
  throw new Error("Transport already started");
49
49
  }
50
- __privateSet(this, _started, true);
50
+ this._started = true;
51
51
  }
52
52
  async send(message) {
53
- if (!__privateGet(this, _started)) {
53
+ if (!this._started) {
54
54
  throw new Error("Transport not started");
55
55
  }
56
- const websocket = __privateGet(this, _getWebSocket).call(this);
56
+ const websocket = this._getWebSocket();
57
57
  if (!websocket) {
58
58
  throw new Error("WebSocket not connected");
59
59
  }
@@ -68,52 +68,40 @@ var McpSSETransport = class {
68
68
  this.onclose?.();
69
69
  }
70
70
  };
71
- _getWebSocket = new WeakMap();
72
- _started = new WeakMap();
73
- var _getWebSocketForGetRequest, _getWebSocketForMessageID, _notifyResponseIdSent, _started2;
74
71
  var McpStreamableHttpTransport = class {
75
72
  constructor(getWebSocketForMessageID, notifyResponseIdSent) {
76
- // TODO: If there is an open connection to send server-initiated messages
77
- // back, we should use that connection
78
- __privateAdd(this, _getWebSocketForGetRequest);
79
- // Get the appropriate websocket connection for a given message id
80
- __privateAdd(this, _getWebSocketForMessageID);
81
- // Notify the server that a response has been sent for a given message id
82
- // so that it may clean up it's mapping of message ids to connections
83
- // once they are no longer needed
84
- __privateAdd(this, _notifyResponseIdSent);
85
- __privateAdd(this, _started2, false);
86
- __privateSet(this, _getWebSocketForMessageID, getWebSocketForMessageID);
87
- __privateSet(this, _notifyResponseIdSent, notifyResponseIdSent);
88
- __privateSet(this, _getWebSocketForGetRequest, () => null);
73
+ this._started = false;
74
+ this._getWebSocketForMessageID = getWebSocketForMessageID;
75
+ this._notifyResponseIdSent = notifyResponseIdSent;
76
+ this._getWebSocketForGetRequest = () => null;
89
77
  }
90
78
  async start() {
91
- if (__privateGet(this, _started2)) {
79
+ if (this._started) {
92
80
  throw new Error("Transport already started");
93
81
  }
94
- __privateSet(this, _started2, true);
82
+ this._started = true;
95
83
  }
96
84
  async send(message) {
97
- if (!__privateGet(this, _started2)) {
85
+ if (!this._started) {
98
86
  throw new Error("Transport not started");
99
87
  }
100
88
  let websocket = null;
101
89
  if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
102
- websocket = __privateGet(this, _getWebSocketForMessageID).call(this, message.id.toString());
90
+ websocket = this._getWebSocketForMessageID(message.id.toString());
103
91
  if (!websocket) {
104
92
  throw new Error(
105
93
  `Could not find WebSocket for message id: ${message.id}`
106
94
  );
107
95
  }
108
96
  } else if (isJSONRPCRequest(message)) {
109
- websocket = __privateGet(this, _getWebSocketForGetRequest).call(this);
97
+ websocket = this._getWebSocketForGetRequest();
110
98
  } else if (isJSONRPCNotification(message)) {
111
99
  websocket = null;
112
100
  }
113
101
  try {
114
102
  websocket?.send(JSON.stringify(message));
115
103
  if (isJSONRPCResponse(message)) {
116
- __privateGet(this, _notifyResponseIdSent).call(this, message.id.toString());
104
+ this._notifyResponseIdSent(message.id.toString());
117
105
  }
118
106
  } catch (error) {
119
107
  this.onerror?.(error);
@@ -124,28 +112,16 @@ var McpStreamableHttpTransport = class {
124
112
  this.onclose?.();
125
113
  }
126
114
  };
127
- _getWebSocketForGetRequest = new WeakMap();
128
- _getWebSocketForMessageID = new WeakMap();
129
- _notifyResponseIdSent = new WeakMap();
130
- _started2 = new WeakMap();
131
- var _status, _transport, _transportType, _requestIdToConnectionId, _agent, _McpAgent_instances, initialize_fn;
132
- var _McpAgent = class _McpAgent extends DurableObject {
115
+ var McpAgent = class _McpAgent extends DurableObject {
133
116
  constructor(ctx, env) {
134
117
  var _a;
135
118
  super(ctx, env);
136
- __privateAdd(this, _McpAgent_instances);
137
- __privateAdd(this, _status, "zero");
138
- __privateAdd(this, _transport);
139
- __privateAdd(this, _transportType, "unset");
140
- __privateAdd(this, _requestIdToConnectionId, /* @__PURE__ */ new Map());
141
- /**
142
- * Since McpAgent's _aren't_ yet real "Agents", let's only expose a couple of the methods
143
- * to the outer class: initialState/state/setState/onStateUpdate/sql
144
- */
145
- __privateAdd(this, _agent);
119
+ this._status = "zero";
120
+ this._transportType = "unset";
121
+ this._requestIdToConnectionId = /* @__PURE__ */ new Map();
146
122
  this.initRun = false;
147
123
  const self = this;
148
- __privateSet(this, _agent, new (_a = class extends Agent {
124
+ this._agent = new (_a = class extends Agent {
149
125
  onStateUpdate(state, source) {
150
126
  return self.onStateUpdate(state, source);
151
127
  }
@@ -154,26 +130,27 @@ var _McpAgent = class _McpAgent extends DurableObject {
154
130
  }
155
131
  }, _a.options = {
156
132
  hibernate: true
157
- }, _a)(ctx, env));
133
+ }, _a)(ctx, env);
158
134
  }
159
135
  get mcp() {
160
- return __privateGet(this, _agent).mcp;
136
+ return this._agent.mcp;
161
137
  }
162
138
  get state() {
163
- return __privateGet(this, _agent).state;
139
+ return this._agent.state;
164
140
  }
165
141
  sql(strings, ...values) {
166
- return __privateGet(this, _agent).sql(strings, ...values);
142
+ return this._agent.sql(strings, ...values);
167
143
  }
168
144
  setState(state) {
169
- return __privateGet(this, _agent).setState(state);
145
+ return this._agent.setState(state);
170
146
  }
147
+ // biome-ignore lint/correctness/noUnusedFunctionParameters: overriden later
171
148
  onStateUpdate(state, source) {
172
149
  }
173
150
  async onStart() {
174
151
  var _a;
175
152
  const self = this;
176
- __privateSet(this, _agent, new (_a = class extends Agent {
153
+ this._agent = new (_a = class extends Agent {
177
154
  constructor() {
178
155
  super(...arguments);
179
156
  this.initialState = self.initialState;
@@ -186,22 +163,22 @@ var _McpAgent = class _McpAgent extends DurableObject {
186
163
  }
187
164
  }, _a.options = {
188
165
  hibernate: true
189
- }, _a)(this.ctx, this.env));
166
+ }, _a)(this.ctx, this.env);
190
167
  this.props = await this.ctx.storage.get("props");
191
- __privateSet(this, _transportType, await this.ctx.storage.get(
168
+ this._transportType = await this.ctx.storage.get(
192
169
  "transportType"
193
- ));
170
+ );
194
171
  await this._init(this.props);
195
172
  const server = await this.server;
196
- if (__privateGet(this, _transportType) === "sse") {
197
- __privateSet(this, _transport, new McpSSETransport(() => this.getWebSocket()));
198
- await server.connect(__privateGet(this, _transport));
199
- } else if (__privateGet(this, _transportType) === "streamable-http") {
200
- __privateSet(this, _transport, new McpStreamableHttpTransport(
173
+ if (this._transportType === "sse") {
174
+ this._transport = new McpSSETransport(() => this.getWebSocket());
175
+ await server.connect(this._transport);
176
+ } else if (this._transportType === "streamable-http") {
177
+ this._transport = new McpStreamableHttpTransport(
201
178
  (id) => this.getWebSocketForResponseID(id),
202
- (id) => __privateGet(this, _requestIdToConnectionId).delete(id)
203
- ));
204
- await server.connect(__privateGet(this, _transport));
179
+ (id) => this._requestIdToConnectionId.delete(id)
180
+ );
181
+ await server.connect(this._transport);
205
182
  }
206
183
  }
207
184
  async _init(props) {
@@ -221,10 +198,17 @@ var _McpAgent = class _McpAgent extends DurableObject {
221
198
  async isInitialized() {
222
199
  return await this.ctx.storage.get("initialized") === true;
223
200
  }
201
+ async _initialize() {
202
+ await this.ctx.blockConcurrencyWhile(async () => {
203
+ this._status = "starting";
204
+ await this.onStart();
205
+ this._status = "started";
206
+ });
207
+ }
224
208
  // Allow the worker to fetch a websocket connection to the agent
225
209
  async fetch(request) {
226
- if (__privateGet(this, _status) !== "started") {
227
- await __privateMethod(this, _McpAgent_instances, initialize_fn).call(this);
210
+ if (this._status !== "started") {
211
+ await this._initialize();
228
212
  }
229
213
  if (request.headers.get("Upgrade") !== "websocket") {
230
214
  return new Response("Expected WebSocket Upgrade request", {
@@ -241,24 +225,24 @@ var _McpAgent = class _McpAgent extends DurableObject {
241
225
  return new Response("Websocket already connected", { status: 400 });
242
226
  }
243
227
  await this.ctx.storage.put("transportType", "sse");
244
- __privateSet(this, _transportType, "sse");
245
- if (!__privateGet(this, _transport)) {
246
- __privateSet(this, _transport, new McpSSETransport(() => this.getWebSocket()));
247
- await server.connect(__privateGet(this, _transport));
228
+ this._transportType = "sse";
229
+ if (!this._transport) {
230
+ this._transport = new McpSSETransport(() => this.getWebSocket());
231
+ await server.connect(this._transport);
248
232
  }
249
- return __privateGet(this, _agent).fetch(request);
233
+ return this._agent.fetch(request);
250
234
  }
251
235
  case "/streamable-http": {
252
- if (!__privateGet(this, _transport)) {
253
- __privateSet(this, _transport, new McpStreamableHttpTransport(
236
+ if (!this._transport) {
237
+ this._transport = new McpStreamableHttpTransport(
254
238
  (id) => this.getWebSocketForResponseID(id),
255
- (id) => __privateGet(this, _requestIdToConnectionId).delete(id)
256
- ));
257
- await server.connect(__privateGet(this, _transport));
239
+ (id) => this._requestIdToConnectionId.delete(id)
240
+ );
241
+ await server.connect(this._transport);
258
242
  }
259
243
  await this.ctx.storage.put("transportType", "streamable-http");
260
- __privateSet(this, _transportType, "streamable-http");
261
- return __privateGet(this, _agent).fetch(request);
244
+ this._transportType = "streamable-http";
245
+ return this._agent.fetch(request);
262
246
  }
263
247
  default:
264
248
  return new Response(
@@ -277,19 +261,19 @@ var _McpAgent = class _McpAgent extends DurableObject {
277
261
  return websockets[0];
278
262
  }
279
263
  getWebSocketForResponseID(id) {
280
- const connectionId = __privateGet(this, _requestIdToConnectionId).get(id);
264
+ const connectionId = this._requestIdToConnectionId.get(id);
281
265
  if (connectionId === void 0) {
282
266
  return null;
283
267
  }
284
- return __privateGet(this, _agent).getConnection(connectionId) ?? null;
268
+ return this._agent.getConnection(connectionId) ?? null;
285
269
  }
286
270
  // All messages received here. This is currently never called
287
271
  async onMessage(connection, event) {
288
- if (__privateGet(this, _transportType) !== "streamable-http") {
272
+ if (this._transportType !== "streamable-http") {
289
273
  const err = new Error(
290
274
  "Internal Server Error: Expected streamable-http protocol"
291
275
  );
292
- __privateGet(this, _transport)?.onerror?.(err);
276
+ this._transport?.onerror?.(err);
293
277
  return;
294
278
  }
295
279
  let message;
@@ -297,21 +281,21 @@ var _McpAgent = class _McpAgent extends DurableObject {
297
281
  const data = typeof event === "string" ? event : new TextDecoder().decode(event);
298
282
  message = JSONRPCMessageSchema.parse(JSON.parse(data));
299
283
  } catch (error) {
300
- __privateGet(this, _transport)?.onerror?.(error);
284
+ this._transport?.onerror?.(error);
301
285
  return;
302
286
  }
303
287
  if (isJSONRPCRequest(message)) {
304
- __privateGet(this, _requestIdToConnectionId).set(message.id.toString(), connection.id);
288
+ this._requestIdToConnectionId.set(message.id.toString(), connection.id);
305
289
  }
306
- __privateGet(this, _transport)?.onmessage?.(message);
290
+ this._transport?.onmessage?.(message);
307
291
  }
308
292
  // All messages received over SSE after the initial connection has been established
309
293
  // will be passed here
310
- async onSSEMcpMessage(sessionId, request) {
311
- if (__privateGet(this, _status) !== "started") {
312
- await __privateMethod(this, _McpAgent_instances, initialize_fn).call(this);
294
+ async onSSEMcpMessage(_sessionId, request) {
295
+ if (this._status !== "started") {
296
+ await this._initialize();
313
297
  }
314
- if (__privateGet(this, _transportType) !== "sse") {
298
+ if (this._transportType !== "sse") {
315
299
  return new Error("Internal Server Error: Expected SSE protocol");
316
300
  }
317
301
  try {
@@ -320,36 +304,36 @@ var _McpAgent = class _McpAgent extends DurableObject {
320
304
  try {
321
305
  parsedMessage = JSONRPCMessageSchema.parse(message);
322
306
  } catch (error) {
323
- __privateGet(this, _transport)?.onerror?.(error);
307
+ this._transport?.onerror?.(error);
324
308
  throw error;
325
309
  }
326
- __privateGet(this, _transport)?.onmessage?.(parsedMessage);
310
+ this._transport?.onmessage?.(parsedMessage);
327
311
  return null;
328
312
  } catch (error) {
329
313
  console.error("Error forwarding message to SSE:", error);
330
- __privateGet(this, _transport)?.onerror?.(error);
314
+ this._transport?.onerror?.(error);
331
315
  return error;
332
316
  }
333
317
  }
334
318
  // Delegate all websocket events to the underlying agent
335
319
  async webSocketMessage(ws, event) {
336
- if (__privateGet(this, _status) !== "started") {
337
- await __privateMethod(this, _McpAgent_instances, initialize_fn).call(this);
320
+ if (this._status !== "started") {
321
+ await this._initialize();
338
322
  }
339
- return await __privateGet(this, _agent).webSocketMessage(ws, event);
323
+ return await this._agent.webSocketMessage(ws, event);
340
324
  }
341
325
  // WebSocket event handlers for hibernation support
342
326
  async webSocketError(ws, error) {
343
- if (__privateGet(this, _status) !== "started") {
344
- await __privateMethod(this, _McpAgent_instances, initialize_fn).call(this);
327
+ if (this._status !== "started") {
328
+ await this._initialize();
345
329
  }
346
- return await __privateGet(this, _agent).webSocketError(ws, error);
330
+ return await this._agent.webSocketError(ws, error);
347
331
  }
348
332
  async webSocketClose(ws, code, reason, wasClean) {
349
- if (__privateGet(this, _status) !== "started") {
350
- await __privateMethod(this, _McpAgent_instances, initialize_fn).call(this);
333
+ if (this._status !== "started") {
334
+ await this._initialize();
351
335
  }
352
- return await __privateGet(this, _agent).webSocketClose(ws, code, reason, wasClean);
336
+ return await this._agent.webSocketClose(ws, code, reason, wasClean);
353
337
  }
354
338
  static mount(path, {
355
339
  binding = "MCP_OBJECT",
@@ -379,7 +363,7 @@ var _McpAgent = class _McpAgent extends DurableObject {
379
363
  );
380
364
  return new Response("Invalid binding", { status: 500 });
381
365
  }
382
- if (bindingValue.toString() !== "[object DurableObjectNamespace]") {
366
+ if (!isDurableObjectNamespace(bindingValue)) {
383
367
  return new Response("Invalid binding", { status: 500 });
384
368
  }
385
369
  const namespace = bindingValue;
@@ -440,10 +424,10 @@ data: ${JSON.stringify(result.data)}
440
424
  onMessage(event).catch(console.error);
441
425
  });
442
426
  ws.addEventListener("error", (error) => {
443
- async function onError(error2) {
427
+ async function onError(_error) {
444
428
  try {
445
429
  await writer.close();
446
- } catch (e) {
430
+ } catch (_e) {
447
431
  }
448
432
  }
449
433
  onError(error).catch(console.error);
@@ -460,9 +444,9 @@ data: ${JSON.stringify(result.data)}
460
444
  });
461
445
  return new Response(readable, {
462
446
  headers: {
463
- "Content-Type": "text/event-stream",
464
447
  "Cache-Control": "no-cache",
465
448
  Connection: "keep-alive",
449
+ "Content-Type": "text/event-stream",
466
450
  ...corsHeaders(request, corsOptions)
467
451
  }
468
452
  });
@@ -498,23 +482,23 @@ data: ${JSON.stringify(result.data)}
498
482
  const error = await doStub.onSSEMcpMessage(sessionId, request);
499
483
  if (error) {
500
484
  return new Response(error.message, {
501
- status: 400,
502
485
  headers: {
503
- "Content-Type": "text/event-stream",
504
486
  "Cache-Control": "no-cache",
505
487
  Connection: "keep-alive",
488
+ "Content-Type": "text/event-stream",
506
489
  ...corsHeaders(request, corsOptions)
507
- }
490
+ },
491
+ status: 400
508
492
  });
509
493
  }
510
494
  return new Response("Accepted", {
511
- status: 202,
512
495
  headers: {
513
- "Content-Type": "text/event-stream",
514
496
  "Cache-Control": "no-cache",
515
497
  Connection: "keep-alive",
498
+ "Content-Type": "text/event-stream",
516
499
  ...corsHeaders(request, corsOptions)
517
- }
500
+ },
501
+ status: 202
518
502
  });
519
503
  }
520
504
  return new Response("Not Found", { status: 404 });
@@ -544,7 +528,7 @@ data: ${JSON.stringify(result.data)}
544
528
  );
545
529
  return new Response("Invalid binding", { status: 500 });
546
530
  }
547
- if (bindingValue.toString() !== "[object DurableObjectNamespace]") {
531
+ if (!isDurableObjectNamespace(bindingValue)) {
548
532
  return new Response("Invalid binding", { status: 500 });
549
533
  }
550
534
  const namespace = bindingValue;
@@ -552,24 +536,24 @@ data: ${JSON.stringify(result.data)}
552
536
  const acceptHeader = request.headers.get("accept");
553
537
  if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
554
538
  const body2 = JSON.stringify({
555
- jsonrpc: "2.0",
556
539
  error: {
557
540
  code: -32e3,
558
541
  message: "Not Acceptable: Client must accept both application/json and text/event-stream"
559
542
  },
560
- id: null
543
+ id: null,
544
+ jsonrpc: "2.0"
561
545
  });
562
546
  return new Response(body2, { status: 406 });
563
547
  }
564
548
  const ct = request.headers.get("content-type");
565
549
  if (!ct || !ct.includes("application/json")) {
566
550
  const body2 = JSON.stringify({
567
- jsonrpc: "2.0",
568
551
  error: {
569
552
  code: -32e3,
570
553
  message: "Unsupported Media Type: Content-Type must be application/json"
571
554
  },
572
- id: null
555
+ id: null,
556
+ jsonrpc: "2.0"
573
557
  });
574
558
  return new Response(body2, { status: 415 });
575
559
  }
@@ -579,12 +563,12 @@ data: ${JSON.stringify(result.data)}
579
563
  );
580
564
  if (contentLength > MAXIMUM_MESSAGE_SIZE_BYTES) {
581
565
  const body2 = JSON.stringify({
582
- jsonrpc: "2.0",
583
566
  error: {
584
567
  code: -32e3,
585
568
  message: `Request body too large. Maximum size is ${MAXIMUM_MESSAGE_SIZE_BYTES} bytes`
586
569
  },
587
- id: null
570
+ id: null,
571
+ jsonrpc: "2.0"
588
572
  });
589
573
  return new Response(body2, { status: 413 });
590
574
  }
@@ -592,14 +576,14 @@ data: ${JSON.stringify(result.data)}
592
576
  let rawMessage;
593
577
  try {
594
578
  rawMessage = await request.json();
595
- } catch (error) {
579
+ } catch (_error) {
596
580
  const body2 = JSON.stringify({
597
- jsonrpc: "2.0",
598
581
  error: {
599
582
  code: -32700,
600
583
  message: "Parse error: Invalid JSON"
601
584
  },
602
- id: null
585
+ id: null,
586
+ jsonrpc: "2.0"
603
587
  });
604
588
  return new Response(body2, { status: 400 });
605
589
  }
@@ -613,12 +597,12 @@ data: ${JSON.stringify(result.data)}
613
597
  for (const msg of arrayMessage) {
614
598
  if (!JSONRPCMessageSchema.safeParse(msg).success) {
615
599
  const body2 = JSON.stringify({
616
- jsonrpc: "2.0",
617
600
  error: {
618
601
  code: -32700,
619
602
  message: "Parse error: Invalid JSON-RPC message"
620
603
  },
621
- id: null
604
+ id: null,
605
+ jsonrpc: "2.0"
622
606
  });
623
607
  return new Response(body2, { status: 400 });
624
608
  }
@@ -629,34 +613,34 @@ data: ${JSON.stringify(result.data)}
629
613
  );
630
614
  if (isInitializationRequest && sessionId) {
631
615
  const body2 = JSON.stringify({
632
- jsonrpc: "2.0",
633
616
  error: {
634
617
  code: -32600,
635
618
  message: "Invalid Request: Initialization requests must not include a sessionId"
636
619
  },
637
- id: null
620
+ id: null,
621
+ jsonrpc: "2.0"
638
622
  });
639
623
  return new Response(body2, { status: 400 });
640
624
  }
641
625
  if (isInitializationRequest && messages.length > 1) {
642
626
  const body2 = JSON.stringify({
643
- jsonrpc: "2.0",
644
627
  error: {
645
628
  code: -32600,
646
629
  message: "Invalid Request: Only one initialization request is allowed"
647
630
  },
648
- id: null
631
+ id: null,
632
+ jsonrpc: "2.0"
649
633
  });
650
634
  return new Response(body2, { status: 400 });
651
635
  }
652
636
  if (!isInitializationRequest && !sessionId) {
653
637
  const body2 = JSON.stringify({
654
- jsonrpc: "2.0",
655
638
  error: {
656
639
  code: -32e3,
657
640
  message: "Bad Request: Mcp-Session-Id header is required"
658
641
  },
659
- id: null
642
+ id: null,
643
+ jsonrpc: "2.0"
660
644
  });
661
645
  return new Response(body2, { status: 400 });
662
646
  }
@@ -669,12 +653,12 @@ data: ${JSON.stringify(result.data)}
669
653
  await doStub.setInitialized();
670
654
  } else if (!isInitialized) {
671
655
  const body2 = JSON.stringify({
672
- jsonrpc: "2.0",
673
656
  error: {
674
657
  code: -32001,
675
658
  message: "Session not found"
676
659
  },
677
- id: null
660
+ id: null,
661
+ jsonrpc: "2.0"
678
662
  });
679
663
  return new Response(body2, { status: 404 });
680
664
  }
@@ -697,12 +681,12 @@ data: ${JSON.stringify(result.data)}
697
681
  console.error("Failed to establish WebSocket connection");
698
682
  await writer.close();
699
683
  const body2 = JSON.stringify({
700
- jsonrpc: "2.0",
701
684
  error: {
702
685
  code: -32001,
703
686
  message: "Failed to establish WebSocket connection"
704
687
  },
705
- id: null
688
+ id: null,
689
+ jsonrpc: "2.0"
706
690
  });
707
691
  return new Response(body2, { status: 500 });
708
692
  }
@@ -735,10 +719,10 @@ data: ${JSON.stringify(result.data)}
735
719
  onMessage(event).catch(console.error);
736
720
  });
737
721
  ws.addEventListener("error", (error) => {
738
- async function onError(error2) {
722
+ async function onError(_error) {
739
723
  try {
740
724
  await writer.close();
741
- } catch (e) {
725
+ } catch (_e) {
742
726
  }
743
727
  }
744
728
  onError(error).catch(console.error);
@@ -762,8 +746,8 @@ data: ${JSON.stringify(result.data)}
762
746
  }
763
747
  ws.close();
764
748
  return new Response(null, {
765
- status: 202,
766
- headers: corsHeaders(request, corsOptions)
749
+ headers: corsHeaders(request, corsOptions),
750
+ status: 202
767
751
  });
768
752
  }
769
753
  for (const message of messages) {
@@ -774,9 +758,9 @@ data: ${JSON.stringify(result.data)}
774
758
  }
775
759
  return new Response(readable, {
776
760
  headers: {
777
- "Content-Type": "text/event-stream",
778
761
  "Cache-Control": "no-cache",
779
762
  Connection: "keep-alive",
763
+ "Content-Type": "text/event-stream",
780
764
  "mcp-session-id": sessionId,
781
765
  ...corsHeaders(request, corsOptions)
782
766
  },
@@ -784,33 +768,21 @@ data: ${JSON.stringify(result.data)}
784
768
  });
785
769
  }
786
770
  const body = JSON.stringify({
787
- jsonrpc: "2.0",
788
771
  error: {
789
772
  code: -32e3,
790
773
  message: "Method not allowed"
791
774
  },
792
- id: null
775
+ id: null,
776
+ jsonrpc: "2.0"
793
777
  });
794
778
  return new Response(body, { status: 405 });
795
779
  }
796
780
  };
797
781
  }
798
782
  };
799
- _status = new WeakMap();
800
- _transport = new WeakMap();
801
- _transportType = new WeakMap();
802
- _requestIdToConnectionId = new WeakMap();
803
- _agent = new WeakMap();
804
- _McpAgent_instances = new WeakSet();
805
- initialize_fn = async function() {
806
- await this.ctx.blockConcurrencyWhile(async () => {
807
- __privateSet(this, _status, "starting");
808
- await this.onStart();
809
- __privateSet(this, _status, "started");
810
- });
811
- };
812
- var McpAgent = _McpAgent;
813
783
  export {
814
- McpAgent
784
+ McpAgent,
785
+ SSEEdgeClientTransport,
786
+ StreamableHTTPEdgeClientTransport
815
787
  };
816
788
  //# sourceMappingURL=index.js.map