agents 0.0.0-2cc0f02 → 0.0.0-2e73791

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 +231 -22
  3. package/dist/ai-chat-agent.js +691 -121
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/{ai-chat-v5-migration-gdyLiTd8.js → ai-chat-v5-migration-DguhuLKF.js} +2 -2
  6. package/dist/{ai-chat-v5-migration-gdyLiTd8.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 +145 -16
  9. package/dist/ai-react.js +389 -75
  10. package/dist/ai-react.js.map +1 -1
  11. package/dist/{ai-types-B0GBFDwi.js → ai-types-DEtF_8Km.js} +10 -2
  12. package/dist/ai-types-DEtF_8Km.js.map +1 -0
  13. package/dist/{ai-types-BWW4umHY.d.ts → ai-types-U8lYA0o8.d.ts} +41 -9
  14. package/dist/ai-types.d.ts +4 -4
  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-Cfw92Wb_.d.ts +834 -0
  20. package/dist/{client-CmMi85Sj.d.ts → client-ClORm6f0.d.ts} +10 -10
  21. package/dist/{client-zS-OCVJA.js → client-DjTPRM8-.js} +3 -3
  22. package/dist/{client-zS-OCVJA.js.map → client-DjTPRM8-.js.map} +1 -1
  23. package/dist/client-QZa2Rq0l.js +1105 -0
  24. package/dist/client-QZa2Rq0l.js.map +1 -0
  25. package/dist/client.d.ts +8 -8
  26. package/dist/client.js +2 -2
  27. package/dist/codemode/ai.js +7 -6
  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-CCwGwnrA.d.ts → do-oauth-client-provider-B-ryFIPr.d.ts} +21 -6
  35. package/dist/{do-oauth-client-provider-B2jr6UNq.js → do-oauth-client-provider-B1fVIshX.js} +71 -9
  36. package/dist/do-oauth-client-provider-B1fVIshX.js.map +1 -0
  37. package/dist/{index-W4JUkafc.d.ts → index-CyDpAVHZ.d.ts} +7 -3
  38. package/dist/{index-DWcUTPtX.d.ts → index-xIS9I1YX.d.ts} +83 -65
  39. package/dist/index.d.ts +36 -36
  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 +140 -12
  46. package/dist/mcp/index.js +636 -41
  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-BEwaCsxO.d.ts → mcp-CzbSsLfc.d.ts} +2 -2
  51. package/dist/observability/index.d.ts +2 -2
  52. package/dist/observability/index.js +6 -5
  53. package/dist/{react-B8BT6PYZ.d.ts → react-ElpIreHg.d.ts} +35 -17
  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-gtr9YMhp.d.ts → serializable-C4GLimgv.d.ts} +8 -3
  58. package/dist/serializable.d.ts +5 -5
  59. package/dist/{src-C9xZ0CrH.js → src-BZDh910Z.js} +130 -128
  60. package/dist/src-BZDh910Z.js.map +1 -0
  61. package/package.json +61 -44
  62. package/dist/ai-types-B0GBFDwi.js.map +0 -1
  63. package/dist/client-C-u-lCFT.d.ts +0 -5311
  64. package/dist/client-WbaRgKYN.js +0 -788
  65. package/dist/client-WbaRgKYN.js.map +0 -1
  66. package/dist/do-oauth-client-provider-B2jr6UNq.js.map +0 -1
  67. package/dist/src-C9xZ0CrH.js.map +0 -1
  68. package/src/index.ts +0 -2031
@@ -1,10 +1,11 @@
1
+ import { n as AgentEmail } from "./context-_sPQqJWv.js";
1
2
  import {
2
- MCPClientManager,
3
- MCPConnectionState,
4
- TransportType
5
- } from "./client-C-u-lCFT.js";
6
- import { Observability } from "./index-W4JUkafc.js";
7
- import { MessageType } from "./ai-types-BWW4umHY.js";
3
+ h as TransportType,
4
+ t as MCPClientManager,
5
+ u as MCPConnectionState
6
+ } from "./client-Cfw92Wb_.js";
7
+ import { t as Observability } from "./index-CyDpAVHZ.js";
8
+ import { n as MessageType } from "./ai-types-U8lYA0o8.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
 
@@ -90,7 +90,7 @@ declare const unstable_callable: (metadata?: CallableMetadata) => void;
90
90
  type QueueItem<T = string> = {
91
91
  id: string;
92
92
  payload: T;
93
- callback: keyof Agent<unknown>;
93
+ callback: keyof Agent<Cloudflare.Env>;
94
94
  created_at: number;
95
95
  };
96
96
  /**
@@ -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,7 +158,7 @@ type MCPServer = {
152
158
  capabilities: ServerCapabilities | null;
153
159
  };
154
160
  declare function getCurrentAgent<
155
- T extends Agent<unknown, unknown> = Agent<unknown, unknown>
161
+ T extends Agent<Cloudflare.Env> = Agent<Cloudflare.Env>
156
162
  >(): {
157
163
  agent: T | undefined;
158
164
  connection: Connection | undefined;
@@ -165,12 +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;
180
+ private _destroyed;
174
181
  private _ParentClass;
175
182
  readonly mcp: MCPClientManager;
176
183
  /**
@@ -324,7 +331,7 @@ declare class Agent<
324
331
  /**
325
332
  * Cancel a scheduled task
326
333
  * @param id ID of the task to cancel
327
- * @returns true if the task was cancelled, false otherwise
334
+ * @returns true if the task was cancelled, false if the task was not found
328
335
  */
329
336
  cancelSchedule(id: string): Promise<boolean>;
330
337
  private _scheduleNextAlarm;
@@ -354,7 +361,8 @@ declare class Agent<
354
361
  * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
355
362
  * @param agentsPrefix agents routing prefix if not using `agents`
356
363
  * @param options MCP client and transport options
357
- * @returns authUrl
364
+ * @returns Server id and state - either "authenticating" with authUrl, or "ready"
365
+ * @throws If connection or discovery fails
358
366
  */
359
367
  addMcpServer(
360
368
  serverName: string,
@@ -368,14 +376,35 @@ declare class Agent<
368
376
  type?: TransportType;
369
377
  };
370
378
  }
371
- ): Promise<{
372
- id: string;
373
- authUrl: string | undefined;
374
- }>;
375
- 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
+ >;
376
391
  removeMcpServer(id: string): Promise<void>;
377
392
  getMcpServers(): MCPServersState;
378
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;
379
408
  /**
380
409
  * Handle OAuth callback response using MCPClientManager configuration
381
410
  * @param result OAuth callback result
@@ -388,7 +417,7 @@ declare class Agent<
388
417
  * Namespace for creating Agent instances
389
418
  * @template Agentic Type of the Agent class
390
419
  */
391
- type AgentNamespace<Agentic extends Agent<unknown>> =
420
+ type AgentNamespace<Agentic extends Agent<Cloudflare.Env>> =
392
421
  DurableObjectNamespace<Agentic>;
393
422
  /**
394
423
  * Agent's durable context
@@ -455,21 +484,11 @@ type EmailRoutingOptions<Env> = AgentOptions<Env> & {
455
484
  * @param options The options for routing the email
456
485
  * @returns A promise that resolves when the email has been routed
457
486
  */
458
- declare function routeAgentEmail<Env>(
487
+ declare function routeAgentEmail<Env extends Cloudflare.Env = Cloudflare.Env>(
459
488
  email: ForwardableEmailMessage,
460
489
  env: Env,
461
490
  options: EmailRoutingOptions<Env>
462
491
  ): Promise<void>;
463
- type AgentEmail = {
464
- from: string;
465
- to: string;
466
- getRaw: () => Promise<Uint8Array>;
467
- headers: Headers;
468
- rawSize: number;
469
- setReject: (reason: string) => void;
470
- forward: (rcptTo: string, headers?: Headers) => Promise<void>;
471
- reply: (options: { from: string; to: string; raw: string }) => Promise<void>;
472
- };
473
492
  type EmailSendOptions = {
474
493
  to: string;
475
494
  subject: string;
@@ -491,8 +510,8 @@ type EmailSendOptions = {
491
510
  * @returns Promise resolving to an Agent instance stub
492
511
  */
493
512
  declare function getAgentByName<
494
- Env,
495
- T extends Agent<Env>,
513
+ Env extends Cloudflare.Env = Cloudflare.Env,
514
+ T extends Agent<Env> = Agent<Env>,
496
515
  Props extends Record<string, unknown> = Record<string, unknown>
497
516
  >(
498
517
  namespace: AgentNamespace<T>,
@@ -524,35 +543,34 @@ declare class StreamingResponse {
524
543
  }
525
544
  //#endregion
526
545
  export {
527
- Agent,
528
- AgentContext,
529
- AgentEmail,
530
- AgentNamespace,
531
- AgentOptions,
532
- CallableMetadata,
533
- type Connection$1 as Connection,
534
- type ConnectionContext,
535
- EmailResolver,
536
- EmailRoutingOptions,
537
- EmailSendOptions,
538
- MCPServer,
539
- MCPServerMessage,
540
- MCPServersState,
541
- QueueItem,
542
- RPCRequest,
543
- RPCResponse,
544
- Schedule,
545
- StateUpdateMessage,
546
- StreamingResponse,
547
- type WSMessage,
548
- callable,
549
- createAddressBasedEmailResolver,
550
- createCatchAllEmailResolver,
551
- createHeaderBasedEmailResolver,
552
- getAgentByName,
553
- getCurrentAgent,
554
- routeAgentEmail,
555
- routeAgentRequest,
556
- unstable_callable
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,
564
+ AgentContext as n,
565
+ Connection$1 as o,
566
+ MCPServersState as p,
567
+ AgentNamespace as r,
568
+ ConnectionContext as s,
569
+ Agent as t,
570
+ EmailSendOptions as u,
571
+ StateUpdateMessage as v,
572
+ createHeaderBasedEmailResolver as w,
573
+ callable as x,
574
+ StreamingResponse as y
557
575
  };
558
- //# sourceMappingURL=index-DWcUTPtX.d.ts.map
576
+ //# sourceMappingURL=index-xIS9I1YX.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,40 +1,40 @@
1
- import { TransportType } from "./client-C-u-lCFT.js";
2
- import "./mcp-BEwaCsxO.js";
3
- import "./do-oauth-client-provider-CCwGwnrA.js";
4
- import "./index-W4JUkafc.js";
5
- import "./ai-types-BWW4umHY.js";
1
+ import { n as AgentEmail } from "./context-_sPQqJWv.js";
2
+ import { h as TransportType } from "./client-Cfw92Wb_.js";
3
+ import "./mcp-CzbSsLfc.js";
4
+ import "./do-oauth-client-provider-B-ryFIPr.js";
5
+ import "./index-CyDpAVHZ.js";
6
+ import "./ai-types-U8lYA0o8.js";
6
7
  import {
7
- Agent,
8
- AgentContext,
9
- AgentEmail,
10
- AgentNamespace,
11
- AgentOptions,
12
- CallableMetadata,
13
- Connection,
14
- ConnectionContext,
15
- EmailResolver,
16
- EmailRoutingOptions,
17
- EmailSendOptions,
18
- MCPServer,
19
- MCPServerMessage,
20
- MCPServersState,
21
- QueueItem,
22
- RPCRequest,
23
- RPCResponse,
24
- Schedule,
25
- StateUpdateMessage,
26
- StreamingResponse,
27
- WSMessage,
28
- callable,
29
- createAddressBasedEmailResolver,
30
- createCatchAllEmailResolver,
31
- createHeaderBasedEmailResolver,
32
- getAgentByName,
33
- getCurrentAgent,
34
- routeAgentEmail,
35
- routeAgentRequest,
36
- unstable_callable
37
- } from "./index-DWcUTPtX.js";
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
+ n as AgentContext,
27
+ o as Connection,
28
+ p as MCPServersState,
29
+ r as AgentNamespace,
30
+ s as ConnectionContext,
31
+ t as Agent,
32
+ u as EmailSendOptions,
33
+ v as StateUpdateMessage,
34
+ w as createHeaderBasedEmailResolver,
35
+ x as callable,
36
+ y as StreamingResponse
37
+ } from "./index-xIS9I1YX.js";
38
38
  export {
39
39
  Agent,
40
40
  AgentContext,
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import "./client-WbaRgKYN.js";
2
- import "./ai-types-B0GBFDwi.js";
3
- import "./client-zS-OCVJA.js";
4
- import "./do-oauth-client-provider-B2jr6UNq.js";
5
- import { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable } from "./src-C9xZ0CrH.js";
1
+ import "./context-BkKbAa1R.js";
2
+ import "./ai-types-DEtF_8Km.js";
3
+ import "./client-DjTPRM8-.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-BZDh910Z.js";
6
7
 
7
8
  export { Agent, StreamingResponse, callable, createAddressBasedEmailResolver, createCatchAllEmailResolver, createHeaderBasedEmailResolver, getAgentByName, getCurrentAgent, routeAgentEmail, routeAgentRequest, unstable_callable };
@@ -1,4 +1,4 @@
1
- import { MCPClientManager, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, getNamespacedData } from "../client-C-u-lCFT.js";
2
- import "../mcp-BEwaCsxO.js";
3
- import "../do-oauth-client-provider-CCwGwnrA.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-Cfw92Wb_.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 { MCPClientManager, getNamespacedData } from "../client-WbaRgKYN.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 { AgentsOAuthProvider, DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-CCwGwnrA.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 { DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-B2jr6UNq.js";
1
+ import { t as DurableObjectOAuthClientProvider } from "../do-oauth-client-provider-B1fVIshX.js";
2
2
 
3
3
  export { DurableObjectOAuthClientProvider };
@@ -1,15 +1,142 @@
1
- import { BaseTransportType, MCPClientOAuthCallbackConfig, MCPClientOAuthResult, MaybePromise, SSEEdgeClientTransport, ServeOptions, StreamableHTTPEdgeClientTransport } from "../client-C-u-lCFT.js";
2
- import "../mcp-BEwaCsxO.js";
3
- import "../do-oauth-client-provider-CCwGwnrA.js";
4
- import "../index-W4JUkafc.js";
5
- import "../ai-types-BWW4umHY.js";
6
- import { Agent, Connection, ConnectionContext } from "../index-DWcUTPtX.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-Cfw92Wb_.js";
3
+ import "../mcp-CzbSsLfc.js";
4
+ import "../do-oauth-client-provider-B-ryFIPr.js";
5
+ import "../index-CyDpAVHZ.js";
6
+ import "../ai-types-U8lYA0o8.js";
7
+ import { o as Connection, s as ConnectionContext, t as Agent } from "../index-xIS9I1YX.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";
13
+ import { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
10
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
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
+ }
38
+ interface WorkerTransportOptions {
39
+ sessionIdGenerator?: () => string;
40
+ /**
41
+ * Enable traditional Request/Response mode, this will disable streaming.
42
+ */
43
+ enableJsonResponse?: boolean;
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;
52
+ }
53
+ declare class WorkerTransport implements Transport {
54
+ started: boolean;
55
+ private initialized;
56
+ private sessionIdGenerator?;
57
+ private enableJsonResponse;
58
+ private onsessioninitialized?;
59
+ private standaloneSseStreamId;
60
+ private streamMapping;
61
+ private requestToStreamMapping;
62
+ private requestResponseMap;
63
+ private corsOptions?;
64
+ private storage?;
65
+ private stateRestored;
66
+ sessionId?: string;
67
+ onclose?: () => void;
68
+ onerror?: (error: Error) => void;
69
+ onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
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;
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;
96
+ handleRequest(request: Request, parsedBody?: unknown): Promise<Response>;
97
+ private handleGetRequest;
98
+ private handlePostRequest;
99
+ private handleDeleteRequest;
100
+ private handleOptionsRequest;
101
+ private handleUnsupportedRequest;
102
+ private validateSession;
103
+ close(): Promise<void>;
104
+ send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
105
+ }
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
113
+ //#region src/mcp/handler.d.ts
114
+ interface CreateMcpHandlerOptions extends WorkerTransportOptions {
115
+ /**
116
+ * The route path that this MCP handler should respond to.
117
+ * If specified, the handler will only process requests that match this route.
118
+ * @default "/mcp"
119
+ */
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;
131
+ }
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
+ */
136
+ declare function experimental_createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
137
+ //#endregion
11
138
  //#region src/mcp/index.d.ts
12
- declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
139
+ 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> {
13
140
  private _transport?;
14
141
  props?: Props;
15
142
  abstract server: MaybePromise<McpServer | Server>;
@@ -27,7 +154,7 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
27
154
  */
28
155
  getSessionId(): string;
29
156
  /** Get the unique WebSocket. SSE transport only. */
30
- private getWebSocket;
157
+ getWebSocket(): Connection<unknown> | null;
31
158
  /** Returns a new transport matching the type of the Agent. */
32
159
  private initTransport;
33
160
  /** Update and store the props */
@@ -40,7 +167,7 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
40
167
  request: req
41
168
  }: ConnectionContext): Promise<void>;
42
169
  /** Handles MCP Messages for the legacy SSE transport. */
43
- onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
170
+ onSSEMcpMessage(_sessionId: string, messageBody: unknown, extraInfo?: MessageExtraInfo): Promise<Error | null>;
44
171
  /** Elicit user input with a message and schema */
45
172
  elicitInput(params: {
46
173
  message: string;
@@ -56,7 +183,8 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
56
183
  static serve(path: string, {
57
184
  binding,
58
185
  corsOptions,
59
- transport
186
+ transport,
187
+ jurisdiction
60
188
  }?: ServeOptions): {
61
189
  fetch<Env>(this: void, request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
62
190
  };
@@ -71,5 +199,5 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
71
199
  };
72
200
  }
73
201
  //#endregion
74
- export { type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, McpAgent, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport };
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 };
75
203
  //# sourceMappingURL=index.d.ts.map