agents 0.0.0-d7a460e → 0.0.0-da2bb57

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 (61) hide show
  1. package/README.md +5 -3
  2. package/dist/ai-chat-agent.d.ts +86 -13
  3. package/dist/ai-chat-agent.js +340 -74
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/{ai-chat-v5-migration-DBHGW4Hv.js → ai-chat-v5-migration-BSiGZmYU.js} +1 -1
  6. package/dist/{ai-chat-v5-migration-DBHGW4Hv.js.map → ai-chat-v5-migration-BSiGZmYU.js.map} +1 -1
  7. package/dist/ai-chat-v5-migration.js +1 -1
  8. package/dist/ai-react.d.ts +14 -9
  9. package/dist/ai-react.js +164 -29
  10. package/dist/ai-react.js.map +1 -1
  11. package/dist/{ai-types-D5YoPrBZ.d.ts → ai-types-81H_-Uxh.d.ts} +15 -7
  12. package/dist/{ai-types-B3aQaFv3.js → ai-types-CrMqkwc_.js} +5 -1
  13. package/dist/ai-types-CrMqkwc_.js.map +1 -0
  14. package/dist/ai-types.d.ts +1 -1
  15. package/dist/ai-types.js +1 -1
  16. package/dist/cli.d.ts +8 -0
  17. package/dist/cli.js +27 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/{client-BfiZ3HQd.js → client-B3SR12TQ.js} +2 -2
  20. package/dist/{client-BfiZ3HQd.js.map → client-B3SR12TQ.js.map} +1 -1
  21. package/dist/{client-CbWe9FBd.d.ts → client-BAQA84dr.d.ts} +2 -2
  22. package/dist/client-BZq9qau2.js +1093 -0
  23. package/dist/client-BZq9qau2.js.map +1 -0
  24. package/dist/client-DJhQNTez.d.ts +1528 -0
  25. package/dist/client.d.ts +2 -2
  26. package/dist/client.js +2 -2
  27. package/dist/codemode/ai.js +5 -5
  28. package/dist/{do-oauth-client-provider-DGc5pP0l.d.ts → do-oauth-client-provider-C2CHH5x-.d.ts} +1 -1
  29. package/dist/{do-oauth-client-provider-CswoD5Lu.js → do-oauth-client-provider-CwqK5SXm.js} +2 -1
  30. package/dist/do-oauth-client-provider-CwqK5SXm.js.map +1 -0
  31. package/dist/{index-DhJCaDWd.d.ts → index-BUle9RiP.d.ts} +2 -2
  32. package/dist/{index-DFqsR7mb.d.ts → index-BvEldExU.d.ts} +53 -26
  33. package/dist/index.d.ts +6 -6
  34. package/dist/index.js +5 -5
  35. package/dist/mcp/client.d.ts +4 -4
  36. package/dist/mcp/client.js +2 -1
  37. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  38. package/dist/mcp/do-oauth-client-provider.js +1 -1
  39. package/dist/mcp/index.d.ts +75 -36
  40. package/dist/mcp/index.js +99 -21
  41. package/dist/mcp/index.js.map +1 -1
  42. package/dist/mcp/x402.js +10 -6
  43. package/dist/mcp/x402.js.map +1 -1
  44. package/dist/{mcp-Dw5vDrY8.d.ts → mcp-BwPscEiF.d.ts} +1 -1
  45. package/dist/observability/index.d.ts +2 -2
  46. package/dist/observability/index.js +5 -5
  47. package/dist/{react-NCPvtyCY.d.ts → react-Ccc1FohP.d.ts} +33 -35
  48. package/dist/react.d.ts +9 -9
  49. package/dist/react.js +2 -2
  50. package/dist/react.js.map +1 -1
  51. package/dist/{serializable-CymX8ovI.d.ts → serializable-faDkMCai.d.ts} +1 -1
  52. package/dist/serializable.d.ts +1 -1
  53. package/dist/{src-Dz0H9hSU.js → src-D_KKH_4c.js} +123 -139
  54. package/dist/src-D_KKH_4c.js.map +1 -0
  55. package/package.json +53 -38
  56. package/dist/ai-types-B3aQaFv3.js.map +0 -1
  57. package/dist/client-9Ld2_lnt.js +0 -786
  58. package/dist/client-9Ld2_lnt.js.map +0 -1
  59. package/dist/client-Csp_m13H.d.ts +0 -5315
  60. package/dist/do-oauth-client-provider-CswoD5Lu.js.map +0 -1
  61. package/dist/src-Dz0H9hSU.js.map +0 -1
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "./serializable-CymX8ovI.js";
1
+ import "./serializable-faDkMCai.js";
2
2
  import {
3
3
  a as agentFetch,
4
4
  i as StreamOptions,
@@ -6,7 +6,7 @@ import {
6
6
  o as camelCaseToKebabCase,
7
7
  r as AgentClientOptions,
8
8
  t as AgentClient
9
- } from "./client-CbWe9FBd.js";
9
+ } from "./client-BAQA84dr.js";
10
10
  export {
11
11
  AgentClient,
12
12
  AgentClientFetchOptions,
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./ai-types-B3aQaFv3.js";
2
- import { n as agentFetch, r as camelCaseToKebabCase, t as AgentClient } from "./client-BfiZ3HQd.js";
1
+ import "./ai-types-CrMqkwc_.js";
2
+ import { n as agentFetch, r as camelCaseToKebabCase, t as AgentClient } from "./client-B3SR12TQ.js";
3
3
 
4
4
  export { AgentClient, agentFetch, camelCaseToKebabCase };
@@ -1,8 +1,8 @@
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 { s as getAgentByName } from "../src-Dz0H9hSU.js";
1
+ import "../ai-types-CrMqkwc_.js";
2
+ import "../client-B3SR12TQ.js";
3
+ import "../client-BZq9qau2.js";
4
+ import "../do-oauth-client-provider-CwqK5SXm.js";
5
+ import { s as getAgentByName } from "../src-D_KKH_4c.js";
6
6
  import { generateObject, tool } from "ai";
7
7
  import { openai } from "@ai-sdk/openai";
8
8
  import { z } from "zod/v3";
@@ -52,4 +52,4 @@ declare class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {
52
52
  }
53
53
  //#endregion
54
54
  export { DurableObjectOAuthClientProvider as n, AgentsOAuthProvider as t };
55
- //# sourceMappingURL=do-oauth-client-provider-DGc5pP0l.d.ts.map
55
+ //# sourceMappingURL=do-oauth-client-provider-C2CHH5x-.d.ts.map
@@ -6,6 +6,7 @@ var DurableObjectOAuthClientProvider = class {
6
6
  this.storage = storage;
7
7
  this.clientName = clientName;
8
8
  this.baseRedirectUrl = baseRedirectUrl;
9
+ if (!storage) throw new Error("DurableObjectOAuthClientProvider requires a valid DurableObjectStorage instance");
9
10
  }
10
11
  get clientMetadata() {
11
12
  return {
@@ -90,4 +91,4 @@ var DurableObjectOAuthClientProvider = class {
90
91
 
91
92
  //#endregion
92
93
  export { DurableObjectOAuthClientProvider as t };
93
- //# sourceMappingURL=do-oauth-client-provider-CswoD5Lu.js.map
94
+ //# sourceMappingURL=do-oauth-client-provider-CwqK5SXm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"do-oauth-client-provider-CwqK5SXm.js","names":["storage: DurableObjectStorage","clientName: string","baseRedirectUrl: string"],"sources":["../src/mcp/do-oauth-client-provider.ts"],"sourcesContent":["import type { OAuthClientProvider } from \"@modelcontextprotocol/sdk/client/auth.js\";\nimport type {\n OAuthClientInformation,\n OAuthClientInformationFull,\n OAuthClientMetadata,\n OAuthTokens\n} from \"@modelcontextprotocol/sdk/shared/auth.js\";\nimport { nanoid } from \"nanoid\";\n\n// A slight extension to the standard OAuthClientProvider interface because `redirectToAuthorization` doesn't give us the interface we need\n// This allows us to track authentication for a specific server and associated dynamic client registration\nexport interface AgentsOAuthProvider extends OAuthClientProvider {\n authUrl: string | undefined;\n clientId: string | undefined;\n serverId: string | undefined;\n}\n\nexport class DurableObjectOAuthClientProvider implements AgentsOAuthProvider {\n private _authUrl_: string | undefined;\n private _serverId_: string | undefined;\n private _clientId_: string | undefined;\n\n constructor(\n public storage: DurableObjectStorage,\n public clientName: string,\n public baseRedirectUrl: string\n ) {\n if (!storage) {\n throw new Error(\n \"DurableObjectOAuthClientProvider requires a valid DurableObjectStorage instance\"\n );\n }\n }\n\n get clientMetadata(): OAuthClientMetadata {\n return {\n client_name: this.clientName,\n client_uri: this.clientUri,\n grant_types: [\"authorization_code\", \"refresh_token\"],\n redirect_uris: [this.redirectUrl],\n response_types: [\"code\"],\n token_endpoint_auth_method: \"none\"\n };\n }\n\n get clientUri() {\n return new URL(this.redirectUrl).origin;\n }\n\n get redirectUrl() {\n return `${this.baseRedirectUrl}/${this.serverId}`;\n }\n\n get clientId() {\n if (!this._clientId_) {\n throw new Error(\"Trying to access clientId before it was set\");\n }\n return this._clientId_;\n }\n\n set clientId(clientId_: string) {\n this._clientId_ = clientId_;\n }\n\n get serverId() {\n if (!this._serverId_) {\n throw new Error(\"Trying to access serverId before it was set\");\n }\n return this._serverId_;\n }\n\n set serverId(serverId_: string) {\n this._serverId_ = serverId_;\n }\n\n keyPrefix(clientId: string) {\n return `/${this.clientName}/${this.serverId}/${clientId}`;\n }\n\n clientInfoKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/client_info/`;\n }\n\n async clientInformation(): Promise<OAuthClientInformation | undefined> {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthClientInformation>(\n this.clientInfoKey(this.clientId)\n )) ?? undefined\n );\n }\n\n async saveClientInformation(\n clientInformation: OAuthClientInformationFull\n ): Promise<void> {\n await this.storage.put(\n this.clientInfoKey(clientInformation.client_id),\n clientInformation\n );\n this.clientId = clientInformation.client_id;\n }\n\n tokenKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/token`;\n }\n\n async tokens(): Promise<OAuthTokens | undefined> {\n if (!this._clientId_) {\n return undefined;\n }\n return (\n (await this.storage.get<OAuthTokens>(this.tokenKey(this.clientId))) ??\n undefined\n );\n }\n\n async saveTokens(tokens: OAuthTokens): Promise<void> {\n await this.storage.put(this.tokenKey(this.clientId), tokens);\n }\n\n get authUrl() {\n return this._authUrl_;\n }\n\n /**\n * Because this operates on the server side (but we need browser auth), we send this url back to the user\n * and require user interact to initiate the redirect flow\n */\n async redirectToAuthorization(authUrl: URL): Promise<void> {\n // Generate secure random token for state parameter\n const stateToken = nanoid();\n authUrl.searchParams.set(\"state\", stateToken);\n this._authUrl_ = authUrl.toString();\n }\n\n codeVerifierKey(clientId: string) {\n return `${this.keyPrefix(clientId)}/code_verifier`;\n }\n\n async saveCodeVerifier(verifier: string): Promise<void> {\n const key = this.codeVerifierKey(this.clientId);\n\n // Don't overwrite existing verifier to preserve first PKCE verifier\n const existing = await this.storage.get<string>(key);\n if (existing) {\n return;\n }\n\n await this.storage.put(key, verifier);\n }\n\n async codeVerifier(): Promise<string> {\n const codeVerifier = await this.storage.get<string>(\n this.codeVerifierKey(this.clientId)\n );\n if (!codeVerifier) {\n throw new Error(\"No code verifier found\");\n }\n return codeVerifier;\n }\n}\n"],"mappings":";;;AAiBA,IAAa,mCAAb,MAA6E;CAK3E,YACE,AAAOA,SACP,AAAOC,YACP,AAAOC,iBACP;EAHO;EACA;EACA;AAEP,MAAI,CAAC,QACH,OAAM,IAAI,MACR,kFACD;;CAIL,IAAI,iBAAsC;AACxC,SAAO;GACL,aAAa,KAAK;GAClB,YAAY,KAAK;GACjB,aAAa,CAAC,sBAAsB,gBAAgB;GACpD,eAAe,CAAC,KAAK,YAAY;GACjC,gBAAgB,CAAC,OAAO;GACxB,4BAA4B;GAC7B;;CAGH,IAAI,YAAY;AACd,SAAO,IAAI,IAAI,KAAK,YAAY,CAAC;;CAGnC,IAAI,cAAc;AAChB,SAAO,GAAG,KAAK,gBAAgB,GAAG,KAAK;;CAGzC,IAAI,WAAW;AACb,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MAAM,8CAA8C;AAEhE,SAAO,KAAK;;CAGd,IAAI,SAAS,WAAmB;AAC9B,OAAK,aAAa;;CAGpB,IAAI,WAAW;AACb,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MAAM,8CAA8C;AAEhE,SAAO,KAAK;;CAGd,IAAI,SAAS,WAAmB;AAC9B,OAAK,aAAa;;CAGpB,UAAU,UAAkB;AAC1B,SAAO,IAAI,KAAK,WAAW,GAAG,KAAK,SAAS,GAAG;;CAGjD,cAAc,UAAkB;AAC9B,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,oBAAiE;AACrE,MAAI,CAAC,KAAK,WACR;AAEF,SACG,MAAM,KAAK,QAAQ,IAClB,KAAK,cAAc,KAAK,SAAS,CAClC,IAAK;;CAIV,MAAM,sBACJ,mBACe;AACf,QAAM,KAAK,QAAQ,IACjB,KAAK,cAAc,kBAAkB,UAAU,EAC/C,kBACD;AACD,OAAK,WAAW,kBAAkB;;CAGpC,SAAS,UAAkB;AACzB,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,SAA2C;AAC/C,MAAI,CAAC,KAAK,WACR;AAEF,SACG,MAAM,KAAK,QAAQ,IAAiB,KAAK,SAAS,KAAK,SAAS,CAAC,IAClE;;CAIJ,MAAM,WAAW,QAAoC;AACnD,QAAM,KAAK,QAAQ,IAAI,KAAK,SAAS,KAAK,SAAS,EAAE,OAAO;;CAG9D,IAAI,UAAU;AACZ,SAAO,KAAK;;;;;;CAOd,MAAM,wBAAwB,SAA6B;EAEzD,MAAM,aAAa,QAAQ;AAC3B,UAAQ,aAAa,IAAI,SAAS,WAAW;AAC7C,OAAK,YAAY,QAAQ,UAAU;;CAGrC,gBAAgB,UAAkB;AAChC,SAAO,GAAG,KAAK,UAAU,SAAS,CAAC;;CAGrC,MAAM,iBAAiB,UAAiC;EACtD,MAAM,MAAM,KAAK,gBAAgB,KAAK,SAAS;AAI/C,MADiB,MAAM,KAAK,QAAQ,IAAY,IAAI,CAElD;AAGF,QAAM,KAAK,QAAQ,IAAI,KAAK,SAAS;;CAGvC,MAAM,eAAgC;EACpC,MAAM,eAAe,MAAM,KAAK,QAAQ,IACtC,KAAK,gBAAgB,KAAK,SAAS,CACpC;AACD,MAAI,CAAC,aACH,OAAM,IAAI,MAAM,yBAAyB;AAE3C,SAAO"}
@@ -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-BwPscEiF.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-BUle9RiP.d.ts.map
@@ -1,10 +1,10 @@
1
1
  import {
2
- a as MCPConnectionState,
2
+ h as TransportType,
3
3
  t as MCPClientManager,
4
- u as TransportType
5
- } from "./client-Csp_m13H.js";
6
- import { t as Observability } from "./index-DhJCaDWd.js";
7
- import { n as MessageType } from "./ai-types-D5YoPrBZ.js";
4
+ u as MCPConnectionState
5
+ } from "./client-DJhQNTez.js";
6
+ import { t as Observability } from "./index-BUle9RiP.js";
7
+ import { n as MessageType } from "./ai-types-81H_-Uxh.js";
8
8
  import {
9
9
  Connection,
10
10
  Connection as Connection$1,
@@ -87,9 +87,9 @@ 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;
92
+ payload: T;
93
93
  callback: keyof Agent<unknown>;
94
94
  created_at: number;
95
95
  };
@@ -97,13 +97,13 @@ type QueueItem<T$1 = string> = {
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<unknown, unknown> = Agent<unknown, unknown>
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;
@@ -171,7 +177,7 @@ declare class Agent<
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
  /**
@@ -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
@@ -494,17 +521,17 @@ type EmailSendOptions = {
494
521
  */
495
522
  declare function getAgentByName<
496
523
  Env,
497
- T$1 extends Agent<Env>,
524
+ T extends Agent<Env>,
498
525
  Props extends Record<string, unknown> = Record<string, unknown>
499
526
  >(
500
- namespace: AgentNamespace<T$1>,
527
+ namespace: AgentNamespace<T>,
501
528
  name: string,
502
529
  options?: {
503
530
  jurisdiction?: DurableObjectJurisdiction;
504
531
  locationHint?: DurableObjectLocationHint;
505
532
  props?: Props;
506
533
  }
507
- ): Promise<DurableObjectStub<T$1>>;
534
+ ): Promise<DurableObjectStub<T>>;
508
535
  /**
509
536
  * A wrapper for streaming responses in callable methods
510
537
  */
@@ -557,4 +584,4 @@ export {
557
584
  WSMessage as x,
558
585
  StateUpdateMessage as y
559
586
  };
560
- //# sourceMappingURL=index-DFqsR7mb.d.ts.map
587
+ //# sourceMappingURL=index-BvEldExU.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { u as TransportType } from "./client-Csp_m13H.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 { h as TransportType } from "./client-DJhQNTez.js";
2
+ import "./mcp-BwPscEiF.js";
3
+ import "./do-oauth-client-provider-C2CHH5x-.js";
4
+ import "./index-BUle9RiP.js";
5
+ import "./ai-types-81H_-Uxh.js";
6
6
  import {
7
7
  A as unstable_callable,
8
8
  C as createAddressBasedEmailResolver,
@@ -34,7 +34,7 @@ import {
34
34
  w as createCatchAllEmailResolver,
35
35
  x as WSMessage,
36
36
  y as StateUpdateMessage
37
- } from "./index-DFqsR7mb.js";
37
+ } from "./index-BvEldExU.js";
38
38
  export {
39
39
  Agent,
40
40
  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 "./ai-types-CrMqkwc_.js";
2
+ import "./client-B3SR12TQ.js";
3
+ import "./client-BZq9qau2.js";
4
+ import "./do-oauth-client-provider-CwqK5SXm.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-D_KKH_4c.js";
6
6
 
7
7
  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-Csp_m13H.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-DJhQNTez.js";
2
+ import "../mcp-BwPscEiF.js";
3
+ import "../do-oauth-client-provider-C2CHH5x-.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-9Ld2_lnt.js";
1
+ import { n as getNamespacedData, t as MCPClientManager } from "../client-BZq9qau2.js";
2
+ import "../do-oauth-client-provider-CwqK5SXm.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-C2CHH5x-.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-CwqK5SXm.js";
2
2
 
3
3
  export { DurableObjectOAuthClientProvider };
@@ -1,23 +1,59 @@
1
- import { c as MaybePromise, d as StreamableHTTPEdgeClientTransport, f as SSEEdgeClientTransport, l as ServeOptions, n as MCPClientOAuthCallbackConfig, o as BaseTransportType, r as MCPClientOAuthResult, s as CORSOptions } from "../client-Csp_m13H.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-DFqsR7mb.js";
7
- import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js";
1
+ 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-DJhQNTez.js";
2
+ import "../mcp-BwPscEiF.js";
3
+ import "../do-oauth-client-provider-C2CHH5x-.js";
4
+ import "../index-BUle9RiP.js";
5
+ import "../ai-types-81H_-Uxh.js";
6
+ import { c as ConnectionContext, s as Connection, t as Agent } from "../index-BvEldExU.js";
7
+ import { SSEClientTransport, SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
8
+ import { StreamableHTTPClientTransport, StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
9
+ import { ElicitRequest, ElicitRequestSchema, ElicitResult, ElicitResult as ElicitResult$1, JSONRPCMessage, MessageExtraInfo } from "@modelcontextprotocol/sdk/types.js";
8
10
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
9
11
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
10
- import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
12
+ import { Transport, TransportSendOptions } from "@modelcontextprotocol/sdk/shared/transport.js";
11
13
 
14
+ //#region src/mcp/client-transports.d.ts
15
+ /**
16
+ * @deprecated Use SSEClientTransport from @modelcontextprotocol/sdk/client/sse.js instead. This alias will be removed in the next major version.
17
+ */
18
+ declare class SSEEdgeClientTransport extends SSEClientTransport {
19
+ constructor(url: URL, options: SSEClientTransportOptions);
20
+ }
21
+ /**
22
+ * @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/sdk/client/streamableHttp.js instead. This alias will be removed in the next major version.
23
+ */
24
+ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
25
+ constructor(url: URL, options: StreamableHTTPClientTransportOptions);
26
+ }
27
+ //#endregion
12
28
  //#region src/mcp/worker-transport.d.ts
29
+ declare const SUPPORTED_PROTOCOL_VERSIONS: readonly ["2025-03-26", "2025-06-18"];
30
+ type ProtocolVersion = (typeof SUPPORTED_PROTOCOL_VERSIONS)[number];
31
+ interface MCPStorageApi {
32
+ get(): Promise<TransportState | undefined> | TransportState | undefined;
33
+ set(state: TransportState): Promise<void> | void;
34
+ }
35
+ interface TransportState {
36
+ sessionId?: string;
37
+ initialized: boolean;
38
+ protocolVersion?: ProtocolVersion;
39
+ }
13
40
  interface WorkerTransportOptions {
14
41
  sessionIdGenerator?: () => string;
42
+ /**
43
+ * Enable traditional Request/Response mode, this will disable streaming.
44
+ */
15
45
  enableJsonResponse?: boolean;
16
46
  onsessioninitialized?: (sessionId: string) => void;
17
47
  corsOptions?: CORSOptions;
48
+ /**
49
+ * Optional storage api for persisting transport state.
50
+ * Use this to store session state in Durable Object/Agent storage
51
+ * so it survives hibernation/restart.
52
+ */
53
+ storage?: MCPStorageApi;
18
54
  }
19
55
  declare class WorkerTransport implements Transport {
20
- private started;
56
+ started: boolean;
21
57
  private initialized;
22
58
  private sessionIdGenerator?;
23
59
  private enableJsonResponse;
@@ -28,11 +64,22 @@ declare class WorkerTransport implements Transport {
28
64
  private requestResponseMap;
29
65
  private corsOptions?;
30
66
  private protocolVersion?;
67
+ private storage?;
68
+ private stateRestored;
31
69
  sessionId?: string;
32
70
  onclose?: () => void;
33
71
  onerror?: (error: Error) => void;
34
- onmessage?: (message: JSONRPCMessage) => void;
72
+ onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
35
73
  constructor(options?: WorkerTransportOptions);
74
+ /**
75
+ * Restore transport state from persistent storage.
76
+ * This is automatically called on start.
77
+ */
78
+ private restoreState;
79
+ /**
80
+ * Persist current transport state to storage.
81
+ */
82
+ private saveState;
36
83
  start(): Promise<void>;
37
84
  private validateProtocolVersion;
38
85
  private getHeaders;
@@ -44,8 +91,14 @@ declare class WorkerTransport implements Transport {
44
91
  private handleUnsupportedRequest;
45
92
  private validateSession;
46
93
  close(): Promise<void>;
47
- send(message: JSONRPCMessage): Promise<void>;
94
+ send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void>;
95
+ }
96
+ //#endregion
97
+ //#region src/mcp/auth-context.d.ts
98
+ interface McpAuthContext {
99
+ props: Record<string, unknown>;
48
100
  }
101
+ declare function getMcpAuthContext(): McpAuthContext | undefined;
49
102
  //#endregion
50
103
  //#region src/mcp/handler.d.ts
51
104
  interface CreateMcpHandlerOptions extends WorkerTransportOptions {
@@ -56,36 +109,22 @@ interface CreateMcpHandlerOptions extends WorkerTransportOptions {
56
109
  */
57
110
  route?: string;
58
111
  /**
59
- * CORS configuration options for handling cross-origin requests.
60
- * These options are passed to the WorkerTransport which handles adding
61
- * CORS headers to all responses.
62
- *
63
- * Default values are:
64
- * - origin: "*"
65
- * - headers: "Content-Type, Accept, Authorization, mcp-session-id, MCP-Protocol-Version"
66
- * - methods: "GET, POST, DELETE, OPTIONS"
67
- * - exposeHeaders: "mcp-session-id"
68
- * - maxAge: 86400
69
- *
70
- * Provided options will overwrite the defaults.
112
+ * An optional auth context to use for handling MCP requests.
113
+ * If not provided, the handler will look for props in the execution context.
71
114
  */
72
- corsOptions?: CORSOptions;
115
+ authContext?: McpAuthContext;
116
+ /**
117
+ * An optional transport to use for handling MCP requests.
118
+ * If not provided, a WorkerTransport will be created with the provided WorkerTransportOptions.
119
+ */
120
+ transport?: WorkerTransport;
73
121
  }
74
- type OAuthExecutionContext = ExecutionContext & {
75
- props?: Record<string, unknown>;
76
- };
77
122
  declare function createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
78
123
  /**
79
124
  * @deprecated This has been renamed to createMcpHandler, and experimental_createMcpHandler will be removed in the next major version
80
125
  */
81
126
  declare function experimental_createMcpHandler(server: McpServer | Server, options?: CreateMcpHandlerOptions): (request: Request, env: unknown, ctx: ExecutionContext) => Promise<Response>;
82
127
  //#endregion
83
- //#region src/mcp/auth-context.d.ts
84
- interface McpAuthContext {
85
- props: Record<string, unknown>;
86
- }
87
- declare function getMcpAuthContext(): McpAuthContext | undefined;
88
- //#endregion
89
128
  //#region src/mcp/index.d.ts
90
129
  declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
91
130
  private _transport?;
@@ -105,7 +144,7 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
105
144
  */
106
145
  getSessionId(): string;
107
146
  /** Get the unique WebSocket. SSE transport only. */
108
- private getWebSocket;
147
+ getWebSocket(): Connection<unknown> | null;
109
148
  /** Returns a new transport matching the type of the Agent. */
110
149
  private initTransport;
111
150
  /** Update and store the props */
@@ -118,7 +157,7 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
118
157
  request: req
119
158
  }: ConnectionContext): Promise<void>;
120
159
  /** Handles MCP Messages for the legacy SSE transport. */
121
- onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
160
+ onSSEMcpMessage(_sessionId: string, messageBody: unknown, extraInfo?: MessageExtraInfo): Promise<Error | null>;
122
161
  /** Elicit user input with a message and schema */
123
162
  elicitInput(params: {
124
163
  message: string;
@@ -150,5 +189,5 @@ declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Re
150
189
  };
151
190
  }
152
191
  //#endregion
153
- export { type CreateMcpHandlerOptions, type ElicitRequest, ElicitRequestSchema, type ElicitResult, type MCPClientOAuthCallbackConfig, type MCPClientOAuthResult, McpAgent, type McpAuthContext, type OAuthExecutionContext, SSEEdgeClientTransport, StreamableHTTPEdgeClientTransport, WorkerTransport, type WorkerTransportOptions, createMcpHandler, experimental_createMcpHandler, getMcpAuthContext };
192
+ 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 };
154
193
  //# sourceMappingURL=index.d.ts.map