agents 0.0.0-5908188 → 0.0.0-59ac254

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 (68) hide show
  1. package/README.md +5 -3
  2. package/dist/ai-chat-agent.d.ts +95 -13
  3. package/dist/ai-chat-agent.js +354 -74
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/{ai-chat-v5-migration-DBHGW4Hv.js → ai-chat-v5-migration-DguhuLKF.js} +1 -1
  6. package/dist/{ai-chat-v5-migration-DBHGW4Hv.js.map → ai-chat-v5-migration-DguhuLKF.js.map} +1 -1
  7. package/dist/ai-chat-v5-migration.js +1 -1
  8. package/dist/ai-react.d.ts +15 -9
  9. package/dist/ai-react.js +179 -29
  10. package/dist/ai-react.js.map +1 -1
  11. package/dist/{ai-types-B3aQaFv3.js → ai-types-CwgHzwUb.js} +5 -1
  12. package/dist/ai-types-CwgHzwUb.js.map +1 -0
  13. package/dist/{ai-types-D5YoPrBZ.d.ts → ai-types-D_hTbf25.d.ts} +15 -7
  14. package/dist/ai-types.d.ts +1 -1
  15. package/dist/ai-types.js +1 -1
  16. package/dist/cli/index.d.ts +1 -0
  17. package/dist/cli/index.js +28 -0
  18. package/dist/cli/index.js.map +1 -0
  19. package/dist/client-C_M5uPrn.d.ts +834 -0
  20. package/dist/{client-BfiZ3HQd.js → client-CcyhkGfN.js} +2 -2
  21. package/dist/{client-BfiZ3HQd.js.map → client-CcyhkGfN.js.map} +1 -1
  22. package/dist/{client-CbWe9FBd.d.ts → client-ClORm6f0.d.ts} +2 -2
  23. package/dist/client-QZa2Rq0l.js +1105 -0
  24. package/dist/client-QZa2Rq0l.js.map +1 -0
  25. package/dist/client.d.ts +2 -2
  26. package/dist/client.js +2 -2
  27. package/dist/codemode/ai.js +6 -5
  28. package/dist/codemode/ai.js.map +1 -1
  29. package/dist/context-BkKbAa1R.js +8 -0
  30. package/dist/context-BkKbAa1R.js.map +1 -0
  31. package/dist/context-_sPQqJWv.d.ts +24 -0
  32. package/dist/context.d.ts +6 -0
  33. package/dist/context.js +3 -0
  34. package/dist/{do-oauth-client-provider-DGc5pP0l.d.ts → do-oauth-client-provider-B-ryFIPr.d.ts} +20 -5
  35. package/dist/{do-oauth-client-provider-CswoD5Lu.js → do-oauth-client-provider-B1fVIshX.js} +70 -8
  36. package/dist/do-oauth-client-provider-B1fVIshX.js.map +1 -0
  37. package/dist/{index-DhJCaDWd.d.ts → index-CyDpAVHZ.d.ts} +2 -2
  38. package/dist/{index-BJOkI2Mo.d.ts → index-DUnsVDnf.d.ts} +83 -74
  39. package/dist/index.d.ts +34 -34
  40. package/dist/index.js +6 -5
  41. package/dist/mcp/client.d.ts +4 -4
  42. package/dist/mcp/client.js +2 -1
  43. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  44. package/dist/mcp/do-oauth-client-provider.js +1 -1
  45. package/dist/mcp/index.d.ts +98 -24
  46. package/dist/mcp/index.js +298 -91
  47. package/dist/mcp/index.js.map +1 -1
  48. package/dist/mcp/x402.js +10 -6
  49. package/dist/mcp/x402.js.map +1 -1
  50. package/dist/{mcp-Dw5vDrY8.d.ts → mcp-CzbSsLfc.d.ts} +1 -1
  51. package/dist/observability/index.d.ts +2 -2
  52. package/dist/observability/index.js +6 -5
  53. package/dist/react-DbzUBop3.d.ts +131 -0
  54. package/dist/react.d.ts +15 -10
  55. package/dist/react.js +57 -57
  56. package/dist/react.js.map +1 -1
  57. package/dist/{serializable-CymX8ovI.d.ts → serializable-C4GLimgv.d.ts} +1 -1
  58. package/dist/serializable.d.ts +1 -1
  59. package/dist/{src-CTtjSFyX.js → src-BmbDclOA.js} +129 -179
  60. package/dist/src-BmbDclOA.js.map +1 -0
  61. package/package.json +53 -38
  62. package/dist/ai-types-B3aQaFv3.js.map +0 -1
  63. package/dist/client-BmMRlvlM.d.ts +0 -5313
  64. package/dist/client-CIvp_OWw.js +0 -786
  65. package/dist/client-CIvp_OWw.js.map +0 -1
  66. package/dist/do-oauth-client-provider-CswoD5Lu.js.map +0 -1
  67. package/dist/react-7YOau7tS.d.ts +0 -115
  68. package/dist/src-CTtjSFyX.js.map +0 -1
@@ -1,10 +1,11 @@
1
+ import { n as AgentEmail } from "./context-_sPQqJWv.js";
1
2
  import {
2
- a as MCPConnectionState,
3
- l as TransportType,
4
- t as MCPClientManager
5
- } from "./client-BmMRlvlM.js";
6
- import { t as Observability } from "./index-DhJCaDWd.js";
7
- import { n as MessageType } from "./ai-types-D5YoPrBZ.js";
3
+ h as TransportType,
4
+ t as MCPClientManager,
5
+ u as MCPConnectionState
6
+ } from "./client-C_M5uPrn.js";
7
+ import { t as Observability } from "./index-CyDpAVHZ.js";
8
+ import { n as MessageType } from "./ai-types-D_hTbf25.js";
8
9
  import {
9
10
  Connection,
10
11
  Connection as Connection$1,
@@ -87,9 +88,9 @@ declare function callable(
87
88
  * @param metadata Optional metadata about the callable method
88
89
  */
89
90
  declare const unstable_callable: (metadata?: CallableMetadata) => void;
90
- type QueueItem<T$1 = string> = {
91
+ type QueueItem<T = string> = {
91
92
  id: string;
92
- payload: T$1;
93
+ payload: T;
93
94
  callback: keyof Agent<unknown>;
94
95
  created_at: number;
95
96
  };
@@ -97,13 +98,13 @@ type QueueItem<T$1 = string> = {
97
98
  * Represents a scheduled task within an Agent
98
99
  * @template T Type of the payload data
99
100
  */
100
- type Schedule<T$1 = string> = {
101
+ type Schedule<T = string> = {
101
102
  /** Unique identifier for the schedule */
102
103
  id: string;
103
104
  /** Name of the method to be called */
104
105
  callback: string;
105
106
  /** Data to be passed to the callback */
106
- payload: T$1;
107
+ payload: T;
107
108
  } & (
108
109
  | {
109
110
  /** Type of schedule for one-time execution at a specific time */
@@ -139,9 +140,15 @@ type MCPServersState = {
139
140
  servers: {
140
141
  [id: string]: MCPServer;
141
142
  };
142
- tools: Tool[];
143
- prompts: Prompt[];
144
- resources: Resource[];
143
+ tools: (Tool & {
144
+ serverId: string;
145
+ })[];
146
+ prompts: (Prompt & {
147
+ serverId: string;
148
+ })[];
149
+ resources: (Resource & {
150
+ serverId: string;
151
+ })[];
145
152
  };
146
153
  type MCPServer = {
147
154
  name: string;
@@ -152,9 +159,9 @@ type MCPServer = {
152
159
  capabilities: ServerCapabilities | null;
153
160
  };
154
161
  declare function getCurrentAgent<
155
- T$1 extends Agent<unknown, unknown> = Agent<unknown, unknown>
162
+ T extends Agent<unknown, unknown> = Agent<unknown, unknown>
156
163
  >(): {
157
- agent: T$1 | undefined;
164
+ agent: T | undefined;
158
165
  connection: Connection | undefined;
159
166
  request: Request | undefined;
160
167
  email: AgentEmail | undefined;
@@ -171,6 +178,7 @@ declare class Agent<
171
178
  > extends Server<Env, Props> {
172
179
  private _state;
173
180
  private _disposables;
181
+ private _destroyed;
174
182
  private _ParentClass;
175
183
  readonly mcp: MCPClientManager;
176
184
  /**
@@ -324,7 +332,7 @@ declare class Agent<
324
332
  /**
325
333
  * Cancel a scheduled task
326
334
  * @param id ID of the task to cancel
327
- * @returns true if the task was cancelled, false otherwise
335
+ * @returns true if the task was cancelled, false if the task was not found
328
336
  */
329
337
  cancelSchedule(id: string): Promise<boolean>;
330
338
  private _scheduleNextAlarm;
@@ -354,7 +362,8 @@ declare class Agent<
354
362
  * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
355
363
  * @param agentsPrefix agents routing prefix if not using `agents`
356
364
  * @param options MCP client and transport options
357
- * @returns authUrl
365
+ * @returns Server id and state - either "authenticating" with authUrl, or "ready"
366
+ * @throws If connection or discovery fails
358
367
  */
359
368
  addMcpServer(
360
369
  serverName: string,
@@ -368,24 +377,35 @@ declare class Agent<
368
377
  type?: TransportType;
369
378
  };
370
379
  }
371
- ): Promise<{
372
- id: string;
373
- authUrl: string | undefined;
374
- }>;
375
- /**
376
- * Handle potential OAuth callback requests after DO hibernation.
377
- * Detects OAuth callbacks, restores state from database, and processes the callback.
378
- * Returns a Response if this was an OAuth callback, otherwise returns undefined.
379
- */
380
- private _handlePotentialOAuthCallback;
381
- /**
382
- * Process an OAuth callback request (assumes state is already restored)
383
- */
384
- private _processOAuthCallback;
385
- private _connectToMcpServerInternal;
380
+ ): Promise<
381
+ | {
382
+ id: string;
383
+ state: typeof MCPConnectionState.AUTHENTICATING;
384
+ authUrl: string;
385
+ }
386
+ | {
387
+ id: string;
388
+ state: typeof MCPConnectionState.READY;
389
+ authUrl?: undefined;
390
+ }
391
+ >;
386
392
  removeMcpServer(id: string): Promise<void>;
387
393
  getMcpServers(): MCPServersState;
388
394
  private broadcastMcpServers;
395
+ /**
396
+ * Handle MCP OAuth callback request if it's an OAuth callback.
397
+ *
398
+ * This method encapsulates the entire OAuth callback flow:
399
+ * 1. Checks if the request is an MCP OAuth callback
400
+ * 2. Processes the OAuth code exchange
401
+ * 3. Establishes the connection if successful
402
+ * 4. Broadcasts MCP server state updates
403
+ * 5. Returns the appropriate HTTP response
404
+ *
405
+ * @param request The incoming HTTP request
406
+ * @returns Response if this was an OAuth callback, null otherwise
407
+ */
408
+ private handleMcpOAuthCallback;
389
409
  /**
390
410
  * Handle OAuth callback response using MCPClientManager configuration
391
411
  * @param result OAuth callback result
@@ -470,16 +490,6 @@ declare function routeAgentEmail<Env>(
470
490
  env: Env,
471
491
  options: EmailRoutingOptions<Env>
472
492
  ): Promise<void>;
473
- type AgentEmail = {
474
- from: string;
475
- to: string;
476
- getRaw: () => Promise<Uint8Array>;
477
- headers: Headers;
478
- rawSize: number;
479
- setReject: (reason: string) => void;
480
- forward: (rcptTo: string, headers?: Headers) => Promise<void>;
481
- reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
482
- };
483
493
  type EmailSendOptions = {
484
494
  to: string;
485
495
  subject: string;
@@ -502,17 +512,17 @@ type EmailSendOptions = {
502
512
  */
503
513
  declare function getAgentByName<
504
514
  Env,
505
- T$1 extends Agent<Env>,
515
+ T extends Agent<Env>,
506
516
  Props extends Record<string, unknown> = Record<string, unknown>
507
517
  >(
508
- namespace: AgentNamespace<T$1>,
518
+ namespace: AgentNamespace<T>,
509
519
  name: string,
510
520
  options?: {
511
521
  jurisdiction?: DurableObjectJurisdiction;
512
522
  locationHint?: DurableObjectLocationHint;
513
523
  props?: Props;
514
524
  }
515
- ): Promise<DurableObjectStub<T$1>>;
525
+ ): Promise<DurableObjectStub<T>>;
516
526
  /**
517
527
  * A wrapper for streaming responses in callable methods
518
528
  */
@@ -534,35 +544,34 @@ declare class StreamingResponse {
534
544
  }
535
545
  //#endregion
536
546
  export {
537
- unstable_callable as A,
538
- createAddressBasedEmailResolver as C,
539
- getCurrentAgent as D,
540
- getAgentByName as E,
541
- routeAgentEmail as O,
542
- callable as S,
543
- createHeaderBasedEmailResolver as T,
544
- RPCResponse as _,
545
- AgentOptions as a,
546
- StreamingResponse as b,
547
- ConnectionContext as c,
548
- EmailSendOptions as d,
549
- MCPServer as f,
550
- RPCRequest as g,
551
- QueueItem as h,
552
- AgentNamespace as i,
553
- routeAgentRequest as k,
554
- EmailResolver as l,
555
- MCPServersState as m,
547
+ createCatchAllEmailResolver as C,
548
+ routeAgentEmail as D,
549
+ getCurrentAgent as E,
550
+ routeAgentRequest as O,
551
+ createAddressBasedEmailResolver as S,
552
+ getAgentByName as T,
553
+ Schedule as _,
554
+ CallableMetadata as a,
555
+ WSMessage as b,
556
+ EmailResolver as c,
557
+ MCPServer as d,
558
+ MCPServerMessage as f,
559
+ RPCResponse as g,
560
+ RPCRequest as h,
561
+ AgentOptions as i,
562
+ unstable_callable as k,
563
+ EmailRoutingOptions as l,
564
+ QueueItem as m,
556
565
  AgentContext as n,
557
- CallableMetadata as o,
558
- MCPServerMessage as p,
559
- AgentEmail as r,
560
- Connection$1 as s,
566
+ Connection$1 as o,
567
+ MCPServersState as p,
568
+ AgentNamespace as r,
569
+ ConnectionContext as s,
561
570
  Agent as t,
562
- EmailRoutingOptions as u,
563
- Schedule as v,
564
- createCatchAllEmailResolver as w,
565
- WSMessage as x,
566
- StateUpdateMessage as y
571
+ EmailSendOptions as u,
572
+ StateUpdateMessage as v,
573
+ createHeaderBasedEmailResolver as w,
574
+ callable as x,
575
+ StreamingResponse as y
567
576
  };
568
- //# sourceMappingURL=index-BJOkI2Mo.d.ts.map
577
+ //# sourceMappingURL=index-DUnsVDnf.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,40 +1,40 @@
1
- import { l as TransportType } from "./client-BmMRlvlM.js";
2
- import "./mcp-Dw5vDrY8.js";
3
- import "./do-oauth-client-provider-DGc5pP0l.js";
4
- import "./index-DhJCaDWd.js";
5
- import "./ai-types-D5YoPrBZ.js";
1
+ import { n as AgentEmail } from "./context-_sPQqJWv.js";
2
+ import { h as TransportType } from "./client-C_M5uPrn.js";
3
+ import "./mcp-CzbSsLfc.js";
4
+ import "./do-oauth-client-provider-B-ryFIPr.js";
5
+ import "./index-CyDpAVHZ.js";
6
+ import "./ai-types-D_hTbf25.js";
6
7
  import {
7
- A as unstable_callable,
8
- C as createAddressBasedEmailResolver,
9
- D as getCurrentAgent,
10
- E as getAgentByName,
11
- O as routeAgentEmail,
12
- S as callable,
13
- T as createHeaderBasedEmailResolver,
14
- _ as RPCResponse,
15
- a as AgentOptions,
16
- b as StreamingResponse,
17
- c as ConnectionContext,
18
- d as EmailSendOptions,
19
- f as MCPServer,
20
- g as RPCRequest,
21
- h as QueueItem,
22
- i as AgentNamespace,
23
- k as routeAgentRequest,
24
- l as EmailResolver,
25
- m as MCPServersState,
8
+ C as createCatchAllEmailResolver,
9
+ D as routeAgentEmail,
10
+ E as getCurrentAgent,
11
+ O as routeAgentRequest,
12
+ S as createAddressBasedEmailResolver,
13
+ T as getAgentByName,
14
+ _ as Schedule,
15
+ a as CallableMetadata,
16
+ b as WSMessage,
17
+ c as EmailResolver,
18
+ d as MCPServer,
19
+ f as MCPServerMessage,
20
+ g as RPCResponse,
21
+ h as RPCRequest,
22
+ i as AgentOptions,
23
+ k as unstable_callable,
24
+ l as EmailRoutingOptions,
25
+ m as QueueItem,
26
26
  n as AgentContext,
27
- o as CallableMetadata,
28
- p as MCPServerMessage,
29
- r as AgentEmail,
30
- s as Connection,
27
+ o as Connection,
28
+ p as MCPServersState,
29
+ r as AgentNamespace,
30
+ s as ConnectionContext,
31
31
  t as Agent,
32
- u as EmailRoutingOptions,
33
- v as Schedule,
34
- w as createCatchAllEmailResolver,
35
- x as WSMessage,
36
- y as StateUpdateMessage
37
- } from "./index-BJOkI2Mo.js";
32
+ u as EmailSendOptions,
33
+ v as StateUpdateMessage,
34
+ w as createHeaderBasedEmailResolver,
35
+ x as callable,
36
+ y as StreamingResponse
37
+ } from "./index-DUnsVDnf.js";
38
38
  export {
39
39
  Agent,
40
40
  AgentContext,
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import "./ai-types-B3aQaFv3.js";
2
- import "./client-BfiZ3HQd.js";
3
- import "./client-CIvp_OWw.js";
4
- import "./do-oauth-client-provider-CswoD5Lu.js";
5
- import { a as createCatchAllEmailResolver, c as getCurrentAgent, d as unstable_callable, i as createAddressBasedEmailResolver, l as routeAgentEmail, n as StreamingResponse, o as createHeaderBasedEmailResolver, r as callable, s as getAgentByName, t as Agent, u as routeAgentRequest } from "./src-CTtjSFyX.js";
1
+ import "./context-BkKbAa1R.js";
2
+ import "./ai-types-CwgHzwUb.js";
3
+ import "./client-CcyhkGfN.js";
4
+ import "./client-QZa2Rq0l.js";
5
+ import "./do-oauth-client-provider-B1fVIshX.js";
6
+ import { a as createCatchAllEmailResolver, c as getCurrentAgent, d as unstable_callable, i as createAddressBasedEmailResolver, l as routeAgentEmail, n as StreamingResponse, o as createHeaderBasedEmailResolver, r as callable, s as getAgentByName, t as Agent, u as routeAgentRequest } from "./src-BmbDclOA.js";
6
7
 
7
8
  export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };
@@ -1,4 +1,4 @@
1
- import { i as getNamespacedData, n as MCPClientOAuthCallbackConfig, r as MCPClientOAuthResult, t as MCPClientManager } from "../client-BmMRlvlM.js";
2
- import "../mcp-Dw5vDrY8.js";
3
- import "../do-oauth-client-provider-DGc5pP0l.js";
4
- export { MCPClientManager, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, getNamespacedData };
1
+ import { a as MCPConnectionResult, c as RegisterServerOptions, i as MCPClientOAuthResult, l as getNamespacedData, n as MCPClientManagerOptions, o as MCPDiscoverResult, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions, t as MCPClientManager } from "../client-C_M5uPrn.js";
2
+ import "../mcp-CzbSsLfc.js";
3
+ import "../do-oauth-client-provider-B-ryFIPr.js";
4
+ export { MCPClientManager, MCPClientManagerOptions, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MCPConnectionResult, MCPDiscoverResult, MCPServerOptions, RegisterServerOptions, getNamespacedData };
@@ -1,3 +1,4 @@
1
- import { n as getNamespacedData, t as MCPClientManager } from "../client-CIvp_OWw.js";
1
+ import { n as getNamespacedData, t as MCPClientManager } from "../client-QZa2Rq0l.js";
2
+ import "../do-oauth-client-provider-B1fVIshX.js";
2
3
 
3
4
  export { MCPClientManager, getNamespacedData };
@@ -1,2 +1,2 @@
1
- import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider-DGc5pP0l.js";
1
+ import { n as DurableObjectOAuthClientProvider, t as AgentsOAuthProvider } from "../do-oauth-client-provider-B-ryFIPr.js";
2
2
  export { AgentsOAuthProvider, DurableObjectOAuthClientProvider };
@@ -1,3 +1,3 @@
1
- import { t as DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-CswoD5Lu.js";
1
+ import { t as DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-B1fVIshX.js";
2
2
 
3
3
  export { DurableObjectOAuthClientProvider };
@@ -1,22 +1,57 @@
1
- import { c as ServeOptions, d as SSEEdgeClientTransport, n as MCPClientOAuthCallbackConfig, o as BaseTransportType, r as MCPClientOAuthResult, s as MaybePromise, u as StreamableHTTPEdgeClientTransport } from "../client-BmMRlvlM.js";
2
- import "../mcp-Dw5vDrY8.js";
3
- import "../do-oauth-client-provider-DGc5pP0l.js";
4
- import "../index-DhJCaDWd.js";
5
- import "../ai-types-D5YoPrBZ.js";
6
- import { c as ConnectionContext, s as Connection, t as Agent } from "../index-BJOkI2Mo.js";
7
- import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js";
1
+ import "../context-_sPQqJWv.js";
2
+ import { a as MCPConnectionResult, d as BaseTransportType, f as CORSOptions, i as MCPClientOAuthResult, m as ServeOptions, o as MCPDiscoverResult, p as MaybePromise, r as MCPClientOAuthCallbackConfig, s as MCPServerOptions } from "../client-C_M5uPrn.js";
3
+ import "../mcp-CzbSsLfc.js";
4
+ import "../do-oauth-client-provider-B-ryFIPr.js";
5
+ import "../index-CyDpAVHZ.js";
6
+ import "../ai-types-D_hTbf25.js";
7
+ import { o as Connection, s as ConnectionContext, t as Agent } from "../index-DUnsVDnf.js";
8
+ import { SSEClientTransport, SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
9
+ import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
10
+ import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
8
11
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
9
12
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
10
- import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
13
+ import { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
11
14
 
15
+ //#region src/mcp/client-transports.d.ts
16
+ /**
17
+ * @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
18
+ */
19
+ declare class SSEEdgeClientTransport extends SSEClientTransport {
20
+ constructor(url: URL, options: SSEClientTransportOptions);
21
+ }
22
+ /**
23
+ * @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
24
+ */
25
+ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
26
+ constructor(url: URL, options: StreamableHTTPClientTransportOptions);
27
+ }
28
+ //#endregion
12
29
  //#region src/mcp/worker-transport.d.ts
30
+ interface MCPStorageApi {
31
+ get(): Promise<TransportState | undefined> | TransportState | undefined;
32
+ set(state: TransportState): Promise<void> | void;
33
+ }
34
+ interface TransportState {
35
+ sessionId?: string;
36
+ initialized: boolean;
37
+ }
13
38
  interface WorkerTransportOptions {
14
39
  sessionIdGenerator?: () => string;
40
+ /**
41
+ * Enable traditional Request/Response mode, this will disable streaming.
42
+ */
15
43
  enableJsonResponse?: boolean;
16
44
  onsessioninitialized?: (sessionId: string) => void;
45
+ corsOptions?: CORSOptions;
46
+ /**
47
+ * Optional storage api for persisting transport state.
48
+ * Use this to store session state in Durable Object/Agent storage
49
+ * so it survives hibernation/restart.
50
+ */
51
+ storage?: MCPStorageApi;
17
52
  }
18
53
  declare class WorkerTransport implements Transport {
19
- private started;
54
+ started: boolean;
20
55
  private initialized;
21
56
  private sessionIdGenerator?;
22
57
  private enableJsonResponse;
@@ -25,12 +60,39 @@ declare class WorkerTransport implements Transport {
25
60
  private streamMapping;
26
61
  private requestToStreamMapping;
27
62
  private requestResponseMap;
63
+ private corsOptions?;
64
+ private storage?;
65
+ private stateRestored;
28
66
  sessionId?: string;
29
67
  onclose?: () => void;
30
68
  onerror?: (error: Error) => void;
31
- onmessage?: (message: JSONRPCMessage) => void;
69
+ onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
32
70
  constructor(options?: WorkerTransportOptions);
71
+ /**
72
+ * Restore transport state from persistent storage.
73
+ * This is automatically called on start.
74
+ */
75
+ private restoreState;
76
+ /**
77
+ * Persist current transport state to storage.
78
+ */
79
+ private saveState;
33
80
  start(): Promise<void>;
81
+ /**
82
+ * Validates the MCP-Protocol-Version header on incoming requests.
83
+ *
84
+ * This performs a simple check: if a version header is present, it must be
85
+ * in the SUPPORTED_PROTOCOL_VERSIONS list. We do not track the negotiated
86
+ * version or enforce version consistency across requests - the SDK handles
87
+ * version negotiation during initialization, and we simply reject any
88
+ * explicitly unsupported versions.
89
+ *
90
+ * - Header present and supported: Accept
91
+ * - Header present and unsupported: 400 Bad Request
92
+ * - Header missing: Accept (version validation is optional)
93
+ */
94
+ private validateProtocolVersion;
95
+ private getHeaders;
34
96
  handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
35
97
  private handleGetRequest;
36
98
  private handlePostRequest;
@@ -39,9 +101,15 @@ declare class WorkerTransport implements Transport {
39
101
  private handleUnsupportedRequest;
40
102
  private validateSession;
41
103
  close(): Promise<void>;
42
- send(message: JSONRPCMessage): Promise<void>;
104
+ send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
43
105
  }
44
106
  //#endregion
107
+ //#region src/mcp/auth-context.d.ts
108
+ interface McpAuthContext {
109
+ props: Record<string, unknown>;
110
+ }
111
+ declare function getMcpAuthContext(): McpAuthContext | undefined;
112
+ //#endregion
45
113
  //#region src/mcp/handler.d.ts
46
114
  interface CreateMcpHandlerOptions extends WorkerTransportOptions {
47
115
  /**
@@ -50,18 +118,23 @@ interface CreateMcpHandlerOptions extends WorkerTransportOptions {
50
118
  * @default "/mcp"
51
119
  */
52
120
  route?: string;
121
+ /**
122
+ * An optional auth context to use for handling MCP requests.
123
+ * If not provided, the handler will look for props in the execution context.
124
+ */
125
+ authContext?: McpAuthContext;
126
+ /**
127
+ * An optional transport to use for handling MCP requests.
128
+ * If not provided, a WorkerTransport will be created with the provided WorkerTransportOptions.
129
+ */
130
+ transport?: WorkerTransport;
53
131
  }
54
- type OAuthExecutionContext = ExecutionContext & {
55
- props?: Record<string, unknown>;
56
- };
132
+ declare function createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
133
+ /**
134
+ * @deprecated This has been renamed to createMcpHandler, and experimental_createMcpHandler will be removed in the next major version
135
+ */
57
136
  declare function experimental_createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
58
137
  //#endregion
59
- //#region src/mcp/auth-context.d.ts
60
- interface McpAuthContext {
61
- props: Record<string, unknown>;
62
- }
63
- declare function getMcpAuthContext(): McpAuthContext | undefined;
64
- //#endregion
65
138
  //#region src/mcp/index.d.ts
66
139
  declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
67
140
  private _transport?;
@@ -81,7 +154,7 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
81
154
  */
82
155
  getSessionId(): string;
83
156
  /** Get the unique WebSocket. SSE transport only. */
84
- private getWebSocket;
157
+ getWebSocket(): Connection<unknown> | null;
85
158
  /** Returns a new transport matching the type of the Agent. */
86
159
  private initTransport;
87
160
  /** Update and store the props */
@@ -94,7 +167,7 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
94
167
  request: req
95
168
  }: ConnectionContext): Promise<void>;
96
169
  /** Handles MCP Messages for the legacy SSE transport. */
97
- onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
170
+ onSSEMcpMessage(_sessionId: string, messageBody: unknown, extraInfo?: MessageExtraInfo): Promise<Error | null>;
98
171
  /** Elicit user input with a message and schema */
99
172
  elicitInput(params: {
100
173
  message: string;
@@ -110,7 +183,8 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
110
183
  static serve(path: string, {
111
184
  binding,
112
185
  corsOptions,
113
- transport
186
+ transport,
187
+ jurisdiction
114
188
  }?: ServeOptions): {
115
189
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
116
190
  };
@@ -125,5 +199,5 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
125
199
  };
126
200
  }
127
201
  //#endregion
128
- export { type CreateMcpHandlerOptions, type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, McpAgent, type McpAuthContext, type OAuthExecutionContext, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, WorkerTransport, type WorkerTransportOptions, experimental_createMcpHandler, getMcpAuthContext };
202
+ export { type CreateMcpHandlerOptions, type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, type MCPConnectionResult, type MCPDiscoverResult, type MCPServerOptions, McpAgent, type McpAuthContext, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, type TransportState, WorkerTransport, type WorkerTransportOptions, createMcpHandler, experimental_createMcpHandler, getMcpAuthContext };
129
203
  //# sourceMappingURL=index.d.ts.map