agents 0.0.0-e8f693b → 0.0.0-e9b6bb7

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