agents 0.30.1 → 0.32.0

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 (182) hide show
  1. package/README.md +2 -1
  2. package/dist/{agent-routing-CDbpVjYq.d.ts → agent-routing-vVMA7m8Y.d.ts} +69 -608
  3. package/dist/agent-routing.d.ts +1 -1
  4. package/dist/agent-tool-types.d.ts +1 -1
  5. package/dist/{agent-tools-C8DH8Yii.d.ts → agent-tools-gGXXkf1z.d.ts} +2 -2
  6. package/dist/agent-tools.d.ts +1 -1
  7. package/dist/agent-tools.js +0 -1
  8. package/dist/agent-tools.js.map +1 -1
  9. package/dist/{ai-iXw0uOGj.d.ts → ai-CDn3Abax.d.ts} +30 -4
  10. package/dist/{ai-sdk-DRPh2rRa.js → ai-sdk-Kon40i0q.js} +2 -36
  11. package/dist/ai-sdk-Kon40i0q.js.map +1 -0
  12. package/dist/browser/ai.d.ts +1 -1
  13. package/dist/browser/ai.js +16 -3
  14. package/dist/browser/ai.js.map +1 -1
  15. package/dist/browser/index.d.ts +64 -16
  16. package/dist/browser/index.js +4 -4
  17. package/dist/browser/tools/ai-sdk.d.ts +7 -5
  18. package/dist/browser/tools/ai-sdk.js +4 -4
  19. package/dist/browser/tools/ai-sdk.js.map +1 -1
  20. package/dist/browser/tools/pi.d.ts +9 -15
  21. package/dist/browser/tools/pi.js +6 -14
  22. package/dist/browser/tools/pi.js.map +1 -1
  23. package/dist/browser/tools/tanstack-ai.d.ts +48 -25
  24. package/dist/browser/tools/tanstack-ai.js +8 -4
  25. package/dist/browser/tools/tanstack-ai.js.map +1 -1
  26. package/dist/{browser-DccPw_wW.js → browser-1eUbPvC2.js} +413 -14
  27. package/dist/browser-1eUbPvC2.js.map +1 -0
  28. package/dist/{browser-DlXhSAdf.d.ts → browser-D9RNpJuT.d.ts} +254 -20
  29. package/dist/browser-tool-BhjCcNVE.d.ts +71 -0
  30. package/dist/browser-tool-DRan7Lk6.js +497 -0
  31. package/dist/browser-tool-DRan7Lk6.js.map +1 -0
  32. package/dist/capability-id-B3J8Nok_.js +13 -0
  33. package/dist/capability-id-B3J8Nok_.js.map +1 -0
  34. package/dist/catalog-BpOejOsE.js +239 -0
  35. package/dist/catalog-BpOejOsE.js.map +1 -0
  36. package/dist/catalog-BpiVV1OF.d.ts +173 -0
  37. package/dist/chat/index.d.ts +2 -2
  38. package/dist/chat-sdk/index.d.ts +3 -3
  39. package/dist/chat-sdk/index.js +1 -1
  40. package/dist/client-4OlMIJx-.js.map +1 -1
  41. package/dist/{client-BnYbNT3z.js → client-DMWujQJ1.js} +68 -244
  42. package/dist/client-DMWujQJ1.js.map +1 -0
  43. package/dist/{client-C27CtRZr.d.ts → client-eSfgYvd3.d.ts} +9 -7
  44. package/dist/client.d.ts +1 -1
  45. package/dist/{cloudflare-Dzvc7V2N.js → cloudflare-CUUm_9q9.js} +26 -4
  46. package/dist/cloudflare-CUUm_9q9.js.map +1 -0
  47. package/dist/{connector-DAXBOIIi.js → connector-CM-uuxKM.js} +96 -8
  48. package/dist/connector-CM-uuxKM.js.map +1 -0
  49. package/dist/{connector-20DJ6p4k.d.ts → connector-DZ71EjE-.d.ts} +109 -9
  50. package/dist/{do-oauth-client-provider-DfsUcpc3.d.ts → do-oauth-client-provider-DtNqv7oj.d.ts} +26 -2
  51. package/dist/{index-YSKgfgg9.d.ts → emitter-BJZtCVjQ.d.ts} +6 -140
  52. package/dist/emitter-DPOVcCln.js +15 -0
  53. package/dist/emitter-DPOVcCln.js.map +1 -0
  54. package/dist/experimental/channels/web/index.js +1 -1
  55. package/dist/experimental/webmcp.js +1 -1
  56. package/dist/{handler-stateless-Bly_nSH3.js → handler-stateless-B5hU3dxK.js} +35 -2
  57. package/dist/handler-stateless-B5hU3dxK.js.map +1 -0
  58. package/dist/{handler-stateless-DxYpJ_XF.d.ts → handler-stateless-C90kD5_R.d.ts} +3 -47
  59. package/dist/harness/container/index.d.ts +15 -15
  60. package/dist/harness/container/index.js +0 -1
  61. package/dist/harness/container/index.js.map +1 -1
  62. package/dist/harness/container/runtime/index.js +2 -2
  63. package/dist/harness/opencode/index.js +0 -1
  64. package/dist/harness/opencode/index.js.map +1 -1
  65. package/dist/harness/pi/index.d.ts +15 -7
  66. package/dist/harness/pi/index.js +74 -151
  67. package/dist/harness/pi/index.js.map +1 -1
  68. package/dist/harness/think/index.d.ts +2 -1
  69. package/dist/{images-xaDv2Fqe.js → images-CfuRCjwq.js} +1 -5
  70. package/dist/images-CfuRCjwq.js.map +1 -0
  71. package/dist/{index-DCxk3OSJ.d.ts → index-8k4qsX1T.d.ts} +2 -28
  72. package/dist/index.d.ts +15 -16
  73. package/dist/index.js +3 -3
  74. package/dist/internal-hosts-Kfp5A392.d.ts +230 -0
  75. package/dist/internal-kmw70xwR.js.map +1 -1
  76. package/dist/invoker-BC1SZ3q1.js +26 -0
  77. package/dist/invoker-BC1SZ3q1.js.map +1 -0
  78. package/dist/invoker-DoLFPJZV.d.ts +21 -0
  79. package/dist/markdown-BZ-VLtA1.js +86 -0
  80. package/dist/markdown-BZ-VLtA1.js.map +1 -0
  81. package/dist/mcp/client/do-oauth-client-provider.d.ts +4 -2
  82. package/dist/mcp/client/do-oauth-client-provider.js +15 -1
  83. package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
  84. package/dist/mcp/client/index.d.ts +15 -1
  85. package/dist/mcp/client/index.js +2 -2
  86. package/dist/mcp/client/x402.d.ts +7 -5
  87. package/dist/mcp/client/x402.js +34 -1
  88. package/dist/mcp/client/x402.js.map +1 -1
  89. package/dist/mcp/index.d.ts +561 -27
  90. package/dist/mcp/index.js +180 -3
  91. package/dist/mcp/index.js.map +1 -1
  92. package/dist/mcp/server/index.d.ts +1 -1
  93. package/dist/mcp/server/index.js +1 -1
  94. package/dist/models/ai-sdk/index.d.ts +2 -2
  95. package/dist/models/ai-sdk/index.js +1 -1
  96. package/dist/models/opencode/index.d.ts +2 -2
  97. package/dist/models/opencode/index.js +1 -1
  98. package/dist/models/pi-ai/index.d.ts +3 -28
  99. package/dist/models/pi-ai/index.js +160 -18
  100. package/dist/models/pi-ai/index.js.map +1 -1
  101. package/dist/observability/ai/index.js +1 -2
  102. package/dist/observability/ai/index.js.map +1 -1
  103. package/dist/observability/index.d.ts +170 -9
  104. package/dist/observability/index.js +386 -11
  105. package/dist/observability/index.js.map +1 -1
  106. package/dist/protocol-BEgrJYC5.d.ts +29 -29
  107. package/dist/react.d.ts +2 -2
  108. package/dist/resource-B59OV2a2.js +325 -0
  109. package/dist/resource-B59OV2a2.js.map +1 -0
  110. package/dist/routing/index.d.ts +1 -1
  111. package/dist/script-CFDLTk5b.d.ts +91 -0
  112. package/dist/script-workspace-BpdAYq1R.d.ts +41 -0
  113. package/dist/serializable.d.ts +1 -1
  114. package/dist/{session-store-yvwq1f9x.js → session-7CDgVE0z.js} +455 -33
  115. package/dist/session-7CDgVE0z.js.map +1 -0
  116. package/dist/{session-store-_IK6dV-w.d.ts → session-store-B7Ca-u1t.d.ts} +8 -1
  117. package/dist/settings-Dk2il2Hf.js.map +1 -1
  118. package/dist/skill-DRBcIBjC.d.ts +221 -0
  119. package/dist/skills/index.d.ts +275 -36
  120. package/dist/skills/index.js +265 -1534
  121. package/dist/skills/index.js.map +1 -1
  122. package/dist/skills/runner.d.ts +37 -0
  123. package/dist/skills/runner.js +912 -0
  124. package/dist/skills/runner.js.map +1 -0
  125. package/dist/skills/tools/ai-sdk.d.ts +36 -0
  126. package/dist/skills/tools/ai-sdk.js +94 -0
  127. package/dist/skills/tools/ai-sdk.js.map +1 -0
  128. package/dist/source-9RQzlEhM.d.ts +112 -0
  129. package/dist/{src-DfLzdwlK.js → src-DoGNJ4Ud.js} +21 -6
  130. package/dist/src-DoGNJ4Ud.js.map +1 -0
  131. package/dist/sub-routing.d.ts +12 -12
  132. package/dist/tool-CTp72Jb_.d.ts +10 -10
  133. package/dist/tool-CxKsvxjm.js.map +1 -1
  134. package/dist/tool-DkT_DJBm.js.map +1 -1
  135. package/dist/tool-DoVberpN.d.ts +22 -22
  136. package/dist/tool-helpers-BI7ifO2S.js +255 -0
  137. package/dist/tool-helpers-BI7ifO2S.js.map +1 -0
  138. package/dist/{transport-CPh7YGiw.d.ts → transport-5moD2pW5.d.ts} +1 -43
  139. package/dist/types-D2naO3rA.d.ts +49 -0
  140. package/dist/vite.d.ts +2 -2
  141. package/dist/vite.js +10 -258
  142. package/dist/vite.js.map +1 -1
  143. package/dist/voice/index.d.ts +1 -1
  144. package/dist/websockets/index.js +1 -1
  145. package/dist/{websockets-CyoeosdO.js → websockets-C6SJtWCJ.js} +1 -2
  146. package/dist/{websockets-CyoeosdO.js.map → websockets-C6SJtWCJ.js.map} +1 -1
  147. package/dist/workflow-types.d.ts +1 -1
  148. package/dist/workflows.d.ts +1 -1
  149. package/dist/workflows.js +0 -1
  150. package/dist/workflows.js.map +1 -1
  151. package/docs/browse-the-web.md +247 -413
  152. package/docs/harnesses/pi.md +36 -30
  153. package/docs/index.md +4 -4
  154. package/docs/mcp-client.md +25 -1
  155. package/docs/mcp-servers.md +26 -7
  156. package/docs/models-pi-ai.md +9 -11
  157. package/docs/models.md +1 -8
  158. package/docs/observability.md +5 -3
  159. package/docs/securing-mcp-servers.md +113 -302
  160. package/package.json +31 -17
  161. package/dist/ai-sdk-DRPh2rRa.js.map +0 -1
  162. package/dist/browser-DccPw_wW.js.map +0 -1
  163. package/dist/browser-tool-B1mhifin.js +0 -616
  164. package/dist/browser-tool-B1mhifin.js.map +0 -1
  165. package/dist/browser-tool-Cxjk5sgG.d.ts +0 -92
  166. package/dist/client-BnYbNT3z.js.map +0 -1
  167. package/dist/cloudflare-Dzvc7V2N.js.map +0 -1
  168. package/dist/connector-DAXBOIIi.js.map +0 -1
  169. package/dist/handler-stateless-Bly_nSH3.js.map +0 -1
  170. package/dist/images-xaDv2Fqe.js.map +0 -1
  171. package/dist/index-iv9FTXX9.d.ts +0 -311
  172. package/dist/invoker-CG0_p_Wq.d.ts +0 -20
  173. package/dist/invoker-CHMnoxIA.js +0 -57
  174. package/dist/invoker-CHMnoxIA.js.map +0 -1
  175. package/dist/session-store-yvwq1f9x.js.map +0 -1
  176. package/dist/skills/compile.d.ts +0 -40
  177. package/dist/skills/compile.js +0 -65
  178. package/dist/skills/compile.js.map +0 -1
  179. package/dist/src-DfLzdwlK.js.map +0 -1
  180. package/dist/tool-helpers-O5BDVEAY.js +0 -58
  181. package/dist/tool-helpers-O5BDVEAY.js.map +0 -1
  182. package/skills-module.d.ts +0 -22
@@ -28,6 +28,20 @@ interface AgentMcpOAuthProvider extends OAuthClientProvider {
28
28
  * @deprecated Use {@link AgentMcpOAuthProvider} instead.
29
29
  */
30
30
  type AgentsOAuthProvider = AgentMcpOAuthProvider;
31
+ interface DurableObjectOAuthClientProviderOptions {
32
+ /**
33
+ * HTTPS URL of this client's OAuth Client ID Metadata Document.
34
+ *
35
+ * When an authorization server advertises
36
+ * `client_id_metadata_document_supported`, the client uses this URL as its
37
+ * `client_id` instead of dynamic client registration. Other servers still
38
+ * use dynamic client registration. Serve
39
+ * {@link DurableObjectOAuthClientProvider.clientMetadataDocument} at this
40
+ * URL, and use a stable `callbackPath` so the document's `redirect_uris`
41
+ * match every authorization request.
42
+ */
43
+ clientMetadataUrl?: string;
44
+ }
31
45
  declare class DurableObjectOAuthClientProvider implements AgentMcpOAuthProvider {
32
46
  storage: DurableObjectStorage;
33
47
  clientName: string;
@@ -35,11 +49,20 @@ declare class DurableObjectOAuthClientProvider implements AgentMcpOAuthProvider
35
49
  private _authUrl_;
36
50
  private _serverId_;
37
51
  private _clientId_;
52
+ readonly clientMetadataUrl: string | undefined;
38
53
  constructor(
39
54
  storage: DurableObjectStorage,
40
55
  clientName: string,
41
- baseRedirectUrl: string
56
+ baseRedirectUrl: string,
57
+ options?: DurableObjectOAuthClientProviderOptions
42
58
  );
59
+ /**
60
+ * The Client ID Metadata Document to serve at `clientMetadataUrl`.
61
+ * Throws when the provider has no `clientMetadataUrl`.
62
+ */
63
+ get clientMetadataDocument(): OAuthClientMetadata & {
64
+ client_id: string;
65
+ };
43
66
  get clientMetadata(): OAuthClientMetadata;
44
67
  get clientUri(): string;
45
68
  get redirectUrl(): string;
@@ -109,8 +132,9 @@ declare class DurableObjectOAuthClientProvider implements AgentMcpOAuthProvider
109
132
  }
110
133
  //#endregion
111
134
  export {
135
+ DurableObjectOAuthClientProviderOptions as i,
112
136
  AgentsOAuthProvider as n,
113
137
  DurableObjectOAuthClientProvider as r,
114
138
  AgentMcpOAuthProvider as t
115
139
  };
116
- //# sourceMappingURL=do-oauth-client-provider-DfsUcpc3.d.ts.map
140
+ //# sourceMappingURL=do-oauth-client-provider-DtNqv7oj.d.ts.map
@@ -1,5 +1,3 @@
1
- import { Channel } from "node:diagnostics_channel";
2
-
3
1
  //#region src/observability/base.d.ts
4
2
  /**
5
3
  * Base event structure for all observability events
@@ -776,27 +774,7 @@ type AgentObservabilityEvent =
776
774
  }
777
775
  >;
778
776
  //#endregion
779
- //#region src/observability/diagnostics.d.ts
780
- /** Diagnostics channels for Agent and Lifecycle telemetry. */
781
- declare const channels: {
782
- readonly state: Channel<any, any>;
783
- readonly rpc: Channel<any, any>;
784
- readonly message: Channel<any, any>;
785
- readonly chat: Channel<any, any>;
786
- readonly transcript: Channel<any, any>;
787
- readonly fiber: Channel<any, any>;
788
- readonly task: Channel<any, any>;
789
- readonly stream: Channel<any, any>;
790
- readonly agentTool: Channel<any, any>;
791
- readonly schedule: Channel<any, any>;
792
- readonly lifecycle: Channel<any, any>;
793
- readonly workflow: Channel<any, any>;
794
- readonly mcp: Channel<any, any>;
795
- readonly email: Channel<any, any>;
796
- readonly channel: Channel<any, any>;
797
- };
798
- //#endregion
799
- //#region src/observability/index.d.ts
777
+ //#region src/observability/emitter.d.ts
800
778
  /**
801
779
  * Union of all observability event types from different domains
802
780
  */
@@ -815,123 +793,11 @@ interface Observability {
815
793
  * a subscriber is registered or a Tail Worker is attached.
816
794
  */
817
795
  declare const genericObservability: Observability;
818
- /**
819
- * Maps each channel key to the observability events it carries.
820
- */
821
- type ChannelEventMap = {
822
- state: Extract<
823
- ObservabilityEvent,
824
- {
825
- type: `state:${string}`;
826
- }
827
- >;
828
- rpc: Extract<
829
- ObservabilityEvent,
830
- {
831
- type: "rpc" | `rpc:${string}`;
832
- }
833
- >;
834
- message: Extract<
835
- ObservabilityEvent,
836
- {
837
- type:
838
- | `message:${string}`
839
- | `tool:${string}`
840
- | `submission:${string}`
841
- | `action:${string}`;
842
- }
843
- >;
844
- chat: Exclude<
845
- Extract<
846
- ObservabilityEvent,
847
- {
848
- type: `chat:${string}`;
849
- }
850
- >,
851
- {
852
- type: `chat:transcript:${string}`;
853
- }
854
- >;
855
- transcript: Extract<
856
- ObservabilityEvent,
857
- {
858
- type: `transcript:${string}` | `chat:transcript:${string}`;
859
- }
860
- >;
861
- fiber: Extract<
862
- ObservabilityEvent,
863
- {
864
- type: `fiber:${string}`;
865
- }
866
- >;
867
- agentTool: Extract<
868
- ObservabilityEvent,
869
- {
870
- type: `agent_tool:${string}`;
871
- }
872
- >;
873
- schedule: Extract<
874
- ObservabilityEvent,
875
- {
876
- type: `schedule:${string}` | `queue:${string}`;
877
- }
878
- >;
879
- lifecycle: Extract<
880
- ObservabilityEvent,
881
- {
882
- type: "connect" | "disconnect" | "destroy";
883
- }
884
- >;
885
- workflow: Extract<
886
- ObservabilityEvent,
887
- {
888
- type: `workflow:${string}`;
889
- }
890
- >;
891
- mcp: Extract<
892
- ObservabilityEvent,
893
- {
894
- type: `mcp:${string}`;
895
- }
896
- >;
897
- email: Extract<
898
- ObservabilityEvent,
899
- {
900
- type: `email:${string}`;
901
- }
902
- >;
903
- channel: Extract<
904
- ObservabilityEvent,
905
- {
906
- type: `channel:${string}` | `notice:${string}`;
907
- }
908
- >;
909
- };
910
- /**
911
- * Subscribe to a typed observability channel.
912
- *
913
- * ```ts
914
- * import { subscribe } from "agents/observability";
915
- *
916
- * const unsub = subscribe("rpc", (event) => {
917
- * console.log(event.payload.method); // fully typed
918
- * });
919
- * ```
920
- *
921
- * @returns A function that unsubscribes the callback.
922
- */
923
- declare function subscribe$1<K extends keyof ChannelEventMap>(
924
- channelKey: K,
925
- callback: (event: ChannelEventMap[K]) => void
926
- ): () => void;
927
796
  //#endregion
928
797
  export {
929
- subscribe$1 as a,
930
- genericObservability as i,
931
- Observability as n,
932
- channels as o,
933
- ObservabilityEvent as r,
934
- MCPObservabilityEvent as s,
935
- ChannelEventMap as t
798
+ MCPObservabilityEvent as i,
799
+ ObservabilityEvent as n,
800
+ genericObservability as r,
801
+ Observability as t
936
802
  };
937
- //# sourceMappingURL=index-YSKgfgg9.d.ts.map
803
+ //# sourceMappingURL=emitter-BJZtCVjQ.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { n as publishDiagnosticsEvent } from "./diagnostics-BzvaX2UT.js";
2
+ //#region src/observability/emitter.ts
3
+ /**
4
+ * The default observability implementation.
5
+ *
6
+ * Publishes events to diagnostics_channel. Events are silent unless
7
+ * a subscriber is registered or a Tail Worker is attached.
8
+ */
9
+ const genericObservability = { emit(event) {
10
+ publishDiagnosticsEvent(event);
11
+ } };
12
+ //#endregion
13
+ export { genericObservability as t };
14
+
15
+ //# sourceMappingURL=emitter-DPOVcCln.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter-DPOVcCln.js","names":[],"sources":["../src/observability/emitter.ts"],"sourcesContent":["import type { AgentObservabilityEvent } from \"./agent\";\nimport type { MCPObservabilityEvent } from \"./mcp\";\nimport { publishDiagnosticsEvent } from \"./diagnostics\";\n\n/**\n * Union of all observability event types from different domains\n */\nexport type ObservabilityEvent =\n | AgentObservabilityEvent\n | MCPObservabilityEvent;\n\nexport interface Observability {\n /**\n * Emit an event for the Agent's observability implementation to handle.\n * @param event - The event to emit\n */\n emit(event: ObservabilityEvent): void;\n}\n\n/**\n * The default observability implementation.\n *\n * Publishes events to diagnostics_channel. Events are silent unless\n * a subscriber is registered or a Tail Worker is attached.\n */\nexport const genericObservability: Observability = {\n emit(event) {\n publishDiagnosticsEvent(event);\n }\n};\n"],"mappings":";;;;;;;;AAyBA,MAAa,uBAAsC,EACjD,KAAK,OAAO;CACV,wBAAwB,KAAK;AAC/B,EACF"}
@@ -1,6 +1,6 @@
1
1
  import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "../../../classPrivateFieldGet2-DZBYAB34.js";
2
2
  import { t as _classPrivateMethodInitSpec } from "../../../classPrivateMethodInitSpec-qMjJ6sHQ.js";
3
- import { a as getConnectionFlag, l as registerInternalConnectionKeys, t as WebSockets, u as setConnectionFlag } from "../../../websockets-CyoeosdO.js";
3
+ import { a as getConnectionFlag, l as registerInternalConnectionKeys, t as WebSockets, u as setConnectionFlag } from "../../../websockets-C6SJtWCJ.js";
4
4
  import { i as participantRoute } from "../../../internal-kmw70xwR.js";
5
5
  import { n as parseClientFrame, t as WEB_IDENTITY_HEADER } from "../../../protocol-y2sSY584.js";
6
6
  //#region src/experimental/channels/web/channel.ts
@@ -1,6 +1,6 @@
1
- import { ToolListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js";
2
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
2
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
3
+ import { ToolListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js";
4
4
  //#region src/experimental/webmcp.ts
5
5
  /**
6
6
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -17,9 +17,42 @@ function isPlainRecord(value) {
17
17
  function invalidVerifiedContext() {
18
18
  throw new TypeError("Invalid verified OAuth request context");
19
19
  }
20
+ function isHttpUrl(value) {
21
+ try {
22
+ const url = new URL(value);
23
+ return url.protocol === "http:" || url.protocol === "https:" ? url : void 0;
24
+ } catch {
25
+ return;
26
+ }
27
+ }
28
+ /**
29
+ * Map `ctx.auth` from Workers OAuth Provider 1.x to SDK v2 `AuthInfo`.
30
+ * Returns `undefined` when `ctx.auth` is absent or not in the provider's
31
+ * shape, so the handler falls back to plain `ctx.props`.
32
+ */
33
+ function getResourceAuthInfo(ctx) {
34
+ const auth = ctx.auth;
35
+ if (!isPlainRecord(auth)) return void 0;
36
+ const { token, audience, expiresAt, scope, clientId } = auth;
37
+ if (typeof token !== "string" || token.length === 0 || typeof audience !== "string" || !Array.isArray(scope) || !scope.every((entry) => typeof entry === "string") || typeof clientId !== "string" || clientId.length === 0 || expiresAt !== void 0 && (typeof expiresAt !== "number" || !Number.isFinite(expiresAt) || expiresAt <= 0)) return;
38
+ const resource = isHttpUrl(audience);
39
+ const props = ctx.props;
40
+ if (!resource || !isPlainRecord(props)) return void 0;
41
+ return {
42
+ props,
43
+ authInfo: {
44
+ token,
45
+ clientId,
46
+ scopes: [...scope],
47
+ ...expiresAt !== void 0 && { expiresAt },
48
+ resource,
49
+ extra: { props }
50
+ }
51
+ };
52
+ }
20
53
  function getVerifiedOAuthAuthInfo(ctx) {
21
54
  const symbolContext = ctx;
22
- if (!(VERIFIED_OAUTH_CONTEXT in symbolContext)) return void 0;
55
+ if (!(VERIFIED_OAUTH_CONTEXT in symbolContext)) return getResourceAuthInfo(ctx);
23
56
  const value = symbolContext[VERIFIED_OAUTH_CONTEXT];
24
57
  if (!isPlainRecord(value) || value.version !== 1) invalidVerifiedContext();
25
58
  const { token, clientId, scopes, expiresAt, resource, props } = value;
@@ -324,4 +357,4 @@ function createStatelessMcpHandler(factory, options = {}) {
324
357
  //#endregion
325
358
  export { getMcpAuthContext as n, runWithAuthContext as r, createStatelessMcpHandler as t };
326
359
 
327
- //# sourceMappingURL=handler-stateless-Bly_nSH3.js.map
360
+ //# sourceMappingURL=handler-stateless-B5hU3dxK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler-stateless-B5hU3dxK.js","names":["candidate","createSdkMcpHandler"],"sources":["../src/mcp/server/auth-context.ts","../src/mcp/server/handler-errors.ts","../src/mcp/server/handler-legacy-compat.ts","../src/mcp/server/handler-stateless.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { AuthInfo } from \"@modelcontextprotocol/server\";\n\nconst VERIFIED_OAUTH_CONTEXT = Symbol.for(\n \"cloudflare.workers-oauth-provider.verified-context.v1\"\n);\n\ninterface VerifiedWorkersOAuthContext {\n version: 1;\n token: string;\n clientId: string;\n scopes: string[];\n expiresAt?: number;\n resource?: string;\n props: Record<string, unknown>;\n}\n\nexport interface McpAuthContext {\n props: Record<string, unknown>;\n}\n\nconst authContextStorage = new AsyncLocalStorage<McpAuthContext>();\n\nexport function getMcpAuthContext(): McpAuthContext | undefined {\n return authContextStorage.getStore();\n}\n\nexport function runWithAuthContext<T>(context: McpAuthContext, fn: () => T): T {\n return authContextStorage.run(context, fn);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction invalidVerifiedContext(): never {\n throw new TypeError(\"Invalid verified OAuth request context\");\n}\n\n/**\n * Token details that `@cloudflare/workers-oauth-provider` 1.x sets on the\n * execution context as `ctx.auth`, beside `ctx.props`, after it validates the\n * bearer token. Both `OAuthProvider` (for its `apiHandler`) and\n * `OAuthResourceServer` (for its `handler`) set it.\n */\ninterface WorkersOAuthResourceAuth {\n token: string;\n audience: string;\n expiresAt?: number;\n scope: string[];\n userId?: string;\n clientId?: string;\n}\n\nfunction isHttpUrl(value: string): URL | undefined {\n try {\n const url = new URL(value);\n return url.protocol === \"http:\" || url.protocol === \"https:\"\n ? url\n : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Map `ctx.auth` from Workers OAuth Provider 1.x to SDK v2 `AuthInfo`.\n * Returns `undefined` when `ctx.auth` is absent or not in the provider's\n * shape, so the handler falls back to plain `ctx.props`.\n */\nfunction getResourceAuthInfo(\n ctx: ExecutionContext\n): { authInfo: AuthInfo; props: Record<string, unknown> } | undefined {\n const auth = (ctx as ExecutionContext & { auth?: unknown }).auth;\n if (!isPlainRecord(auth)) return undefined;\n\n const candidate = auth as Partial<WorkersOAuthResourceAuth>;\n const { token, audience, expiresAt, scope, clientId } = candidate;\n if (\n typeof token !== \"string\" ||\n token.length === 0 ||\n typeof audience !== \"string\" ||\n !Array.isArray(scope) ||\n !scope.every((entry) => typeof entry === \"string\") ||\n // SDK v2 AuthInfo requires a client ID.\n typeof clientId !== \"string\" ||\n clientId.length === 0 ||\n (expiresAt !== undefined &&\n (typeof expiresAt !== \"number\" ||\n !Number.isFinite(expiresAt) ||\n expiresAt <= 0))\n ) {\n return undefined;\n }\n\n const resource = isHttpUrl(audience);\n const props = ctx.props;\n if (!resource || !isPlainRecord(props)) return undefined;\n\n return {\n props,\n authInfo: {\n token,\n clientId,\n scopes: [...scope],\n ...(expiresAt !== undefined && { expiresAt }),\n resource,\n extra: { props }\n }\n };\n}\n\nexport function getVerifiedOAuthAuthInfo(\n ctx: ExecutionContext\n): { authInfo: AuthInfo; props: Record<string, unknown> } | undefined {\n const symbolContext = ctx as ExecutionContext & Record<symbol, unknown>;\n if (!(VERIFIED_OAUTH_CONTEXT in symbolContext)) {\n return getResourceAuthInfo(ctx);\n }\n\n const value = symbolContext[VERIFIED_OAUTH_CONTEXT];\n if (!isPlainRecord(value) || value.version !== 1) invalidVerifiedContext();\n\n const candidate = value as Partial<VerifiedWorkersOAuthContext>;\n const { token, clientId, scopes, expiresAt, resource, props } = candidate;\n if (\n typeof token !== \"string\" ||\n token.length === 0 ||\n typeof clientId !== \"string\" ||\n clientId.length === 0 ||\n !Array.isArray(scopes) ||\n !scopes.every((scope) => typeof scope === \"string\") ||\n !isPlainRecord(props)\n ) {\n invalidVerifiedContext();\n }\n\n if (\n expiresAt !== undefined &&\n (typeof expiresAt !== \"number\" ||\n !Number.isFinite(expiresAt) ||\n expiresAt <= 0)\n ) {\n invalidVerifiedContext();\n }\n\n let resourceUrl: URL | undefined;\n if (resource !== undefined) {\n if (typeof resource !== \"string\") invalidVerifiedContext();\n try {\n resourceUrl = new URL(resource);\n } catch {\n invalidVerifiedContext();\n }\n if (resourceUrl.protocol !== \"http:\" && resourceUrl.protocol !== \"https:\") {\n invalidVerifiedContext();\n }\n }\n\n if (ctx.props !== props) invalidVerifiedContext();\n\n return {\n props,\n authInfo: {\n token,\n clientId,\n scopes: [...scopes],\n ...(expiresAt !== undefined && { expiresAt }),\n ...(resourceUrl !== undefined && { resource: resourceUrl }),\n extra: { props }\n }\n };\n}\n","export function internalErrorResponse(\n id: string | number | null = null\n): Response {\n return Response.json(\n {\n jsonrpc: \"2.0\",\n error: { code: -32603, message: \"Internal server error\" },\n id\n },\n { status: 500 }\n );\n}\n\nexport function requestIdFromParsedBody(body: unknown): string | number | null {\n if (\n typeof body !== \"object\" ||\n body === null ||\n Array.isArray(body) ||\n !(\"method\" in body) ||\n typeof body.method !== \"string\" ||\n !(\"id\" in body)\n ) {\n return null;\n }\n return typeof body.id === \"string\" || typeof body.id === \"number\"\n ? body.id\n : null;\n}\n\nexport function reportHandlerError(\n onerror: ((error: Error) => void) | undefined,\n error: unknown\n): void {\n try {\n onerror?.(error instanceof Error ? error : new Error(String(error)));\n } catch {\n // Error reporting must not change the response.\n }\n}\n","import {\n WebStandardStreamableHTTPServerTransport,\n isJSONRPCRequest,\n type CreateMcpHandlerOptions,\n type McpHandlerRequestOptions,\n McpServer,\n type McpServerFactory,\n type Server\n} from \"@modelcontextprotocol/server\";\nimport {\n internalErrorResponse,\n reportHandlerError,\n requestIdFromParsedBody\n} from \"./handler-errors\";\n/**\n * Temporary adapter for Legacy compatibility on the SDK v2 transport.\n *\n * Local deltas from the upstream stateless fallback:\n *\n * - impossible stateless server-to-client requests fail immediately rather\n * than leaving the tool handler waiting for a session response.\n * - a factory that returns an instance still serving another request is\n * rejected before this request takes ownership of it, so the error path\n * never closes the other request's instance (mirrors upstream's\n * `assertNotServing` on the modern path).\n *\n * Streaming and keepalive behavior remain delegated to the SDK transport.\n * Remove this adapter once the SDK exposes the reverse-request policy directly.\n */\nexport function createLegacyCompatibilityRequestHandler(\n factory: McpServerFactory,\n handlerOptions: Pick<CreateMcpHandlerOptions, \"keepAliveMs\" | \"onerror\"> = {}\n) {\n const { keepAliveMs, onerror } = handlerOptions;\n const fetch = async (\n request: Request,\n requestOptions: McpHandlerRequestOptions | undefined\n ): Promise<Response> => {\n // Match the upstream Legacy fallback: GET and DELETE are session operations\n // and cannot be served by a fresh per-request transport. Reject\n // them before running a factory with application-visible side effects.\n if (request.method.toUpperCase() !== \"POST\") {\n return Response.json(\n {\n jsonrpc: \"2.0\",\n error: { code: -32000, message: \"Method not allowed.\" },\n id: null\n },\n { status: 405 }\n );\n }\n\n if (request.signal.aborted) {\n return new Response(null, { status: 499 });\n }\n\n let product: McpServer | Server | undefined;\n let transport: WebStandardStreamableHTTPServerTransport | undefined;\n let teardownPromise: Promise<void> | undefined;\n const teardown = () =>\n (teardownPromise ??= (async () => {\n await Promise.all([\n transport?.close().catch(() => {}),\n product?.close().catch(() => {})\n ]);\n })());\n const onAbort = () => void teardown();\n\n try {\n const candidate = await factory({\n era: \"legacy\",\n ...(requestOptions?.authInfo !== undefined && {\n authInfo: requestOptions.authInfo\n }),\n requestInfo: request\n });\n assertNotServing(candidate);\n product = candidate;\n transport = new WebStandardStreamableHTTPServerTransport({\n keepAliveMs,\n sessionIdGenerator: undefined\n });\n\n const send = transport.send.bind(transport);\n transport.send = async (message, sendOptions) => {\n if (isJSONRPCRequest(message)) {\n transport?.onmessage?.({\n jsonrpc: \"2.0\",\n id: message.id,\n error: {\n code: -32603,\n message:\n \"Server-to-client requests are unavailable in the Legacy compatibility lane. \" +\n \"Use inputRequired(...) for Stateless clients, or route \" +\n \"Legacy traffic to a sessionful transport.\"\n }\n });\n return;\n }\n await send(message, sendOptions);\n };\n\n await product.connect(transport);\n if (request.signal.aborted) {\n await teardown();\n return new Response(null, { status: 499 });\n }\n request.signal.addEventListener(\"abort\", onAbort, { once: true });\n const response = await transport.handleRequest(request, {\n ...(requestOptions?.authInfo !== undefined && {\n authInfo: requestOptions.authInfo\n }),\n ...(requestOptions?.parsedBody !== undefined && {\n parsedBody: requestOptions.parsedBody\n })\n });\n\n if (\n response.body === null ||\n !response.headers.get(\"content-type\")?.includes(\"text/event-stream\")\n ) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n return response;\n }\n\n const reader = response.body.getReader();\n const body = new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const { done, value } = await reader.read();\n if (done) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n controller.close();\n } else if (value !== undefined) {\n controller.enqueue(value);\n }\n } catch (error) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n controller.error(error);\n }\n },\n async cancel(reason) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await reader.cancel(reason).catch(() => {});\n await teardown();\n }\n });\n return new Response(body, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers\n });\n } catch (error) {\n request.signal.removeEventListener(\"abort\", onAbort);\n await teardown();\n reportHandlerError(onerror, error);\n return internalErrorResponse(\n requestIdFromParsedBody(requestOptions?.parsedBody)\n );\n }\n };\n\n return { fetch };\n}\n\nfunction assertNotServing(product: McpServer | Server): void {\n const server = product instanceof McpServer ? product.server : product;\n if (server.transport !== undefined) {\n throw new Error(\n \"The factory returned an instance that is still serving another \" +\n \"request. Return a new instance for each request.\"\n );\n }\n}\n","import {\n createMcpHandler as createSdkMcpHandler,\n hostHeaderValidationResponse,\n isLegacyRequest,\n localhostAllowedHostnames,\n localhostAllowedOrigins,\n originValidationResponse,\n type AuthInfo,\n type CreateMcpHandlerOptions as SdkCreateMcpHandlerOptions,\n type McpHandlerRequestOptions,\n type McpServerFactory,\n type ServerNotifier\n} from \"@modelcontextprotocol/server\";\nimport {\n getVerifiedOAuthAuthInfo,\n runWithAuthContext,\n type McpAuthContext\n} from \"./auth-context\";\nimport { internalErrorResponse, reportHandlerError } from \"./handler-errors\";\nimport { createLegacyCompatibilityRequestHandler } from \"./handler-legacy-compat\";\nimport type { CORSOptions } from \"../types\";\n\nexport interface CreateStatelessMcpHandlerOptions extends Omit<\n SdkCreateMcpHandlerOptions,\n \"bus\"\n> {\n /** Exact pathname handled by this Worker wrapper. @default \"/mcp\" */\n route?: string;\n /** CORS headers applied by the Worker wrapper. Pass `false` to disable. */\n corsOptions?: CORSOptions | false;\n /**\n * Restrict `Host` headers to these hostnames. Localhost and `workers.dev`\n * endpoints receive matching defaults; custom domains rely on Cloudflare\n * routing unless this option is set.\n */\n allowedHostnames?: string[];\n /**\n * Restrict present browser `Origin` headers to these hostnames. Requests\n * without an Origin (including non-browser MCP clients) remain valid. The\n * default includes localhost-class Origins, the endpoint's `workers.dev`\n * hostname, and a concrete `corsOptions.origin` hostname. Pass `\"*\"` only\n * when equivalent Origin validation runs in trusted middleware upstream.\n */\n allowedOriginHostnames?: string[] | \"*\";\n /** Application props exposed through {@link getMcpAuthContext}. */\n authContext?: McpAuthContext;\n}\n\nexport type StatelessMcpHandler = {\n (request: Request, env: unknown, ctx: ExecutionContext): Promise<Response>;\n fetch(\n request: Request,\n options?: McpHandlerRequestOptions\n ): Promise<Response>;\n notify: ServerNotifier;\n};\n\nexport type StatelessMcpServerInput = McpServerFactory;\n\nconst DEFAULT_CORS_OPTIONS: Required<CORSOptions> = {\n origin: \"*\",\n headers:\n \"Content-Type, Accept, Authorization, mcp-session-id, MCP-Protocol-Version, Mcp-Method, Mcp-Name\",\n methods: \"GET, POST, DELETE, OPTIONS\",\n exposeHeaders: \"mcp-session-id\",\n maxAge: 86400\n};\n\nfunction corsHeaders(options: CORSOptions = {}): Headers {\n const merged = { ...DEFAULT_CORS_OPTIONS, ...options };\n return new Headers({\n \"Access-Control-Allow-Headers\": merged.headers,\n \"Access-Control-Allow-Methods\": merged.methods,\n \"Access-Control-Allow-Origin\": merged.origin,\n \"Access-Control-Expose-Headers\": merged.exposeHeaders,\n \"Access-Control-Max-Age\": String(merged.maxAge)\n });\n}\n\nfunction withCors(response: Response, options: CORSOptions | false): Response {\n const headers = new Headers(response.headers);\n if (options === false) {\n for (const name of Array.from(headers.keys())) {\n if (name.toLowerCase().startsWith(\"access-control-\")) {\n headers.delete(name);\n }\n }\n } else {\n for (const [name, value] of corsHeaders(options)) {\n headers.set(name, value);\n }\n }\n return new Response(response.body, {\n status: response.status,\n statusText: response.statusText,\n headers\n });\n}\n\nfunction wrapResponseBodyWithAuthContext(\n response: Response,\n authContext: McpAuthContext | undefined\n): Response {\n if (!authContext || !response.body) return response;\n\n const reader = response.body.getReader();\n const body = new ReadableStream<Uint8Array>({\n pull(controller) {\n return runWithAuthContext(authContext, async () => {\n try {\n const { done, value } = await reader.read();\n if (done) {\n controller.close();\n } else {\n controller.enqueue(value);\n }\n } catch (error) {\n controller.error(error);\n }\n });\n },\n cancel(reason) {\n return runWithAuthContext(authContext, () => reader.cancel(reason));\n }\n });\n\n return new Response(body, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers\n });\n}\n\nexport function createStatelessMcpHandler(\n factory: StatelessMcpServerInput,\n options: CreateStatelessMcpHandlerOptions = {}\n): StatelessMcpHandler {\n const optionRecord = options as Record<string, unknown>;\n if (optionRecord.bus !== undefined) {\n throw new TypeError(\n 'createMcpHandler option \"bus\" is not exposed by the Agents SDK.'\n );\n }\n const legacyOnlyOption = [\n \"transport\",\n \"storage\",\n \"sessionIdGenerator\",\n \"onsessioninitialized\",\n \"onsessionclosed\",\n \"enableJsonResponse\",\n \"eventStore\",\n \"allowedHosts\",\n \"allowedOrigins\",\n \"enableDnsRebindingProtection\",\n \"retryInterval\"\n ].find((key) => optionRecord[key] !== undefined);\n if (legacyOnlyOption) {\n throw new TypeError(\n `createMcpHandler option \"${legacyOnlyOption}\" is only supported with an MCP SDK v1 server. The managed SDK v2 handler is stateless; remove this option or keep the v1 server during migration.`\n );\n }\n\n const {\n route = \"/mcp\",\n corsOptions = {},\n allowedHostnames,\n allowedOriginHostnames,\n authContext,\n legacy = \"stateless\",\n ...sdkOptions\n } = options;\n\n const sdkHandler = createSdkMcpHandler(factory, {\n ...sdkOptions,\n legacy: \"reject\"\n });\n const legacyCompatibilityHandler =\n legacy === \"stateless\"\n ? createLegacyCompatibilityRequestHandler(factory, {\n keepAliveMs: sdkOptions.keepAliveMs,\n onerror: sdkOptions.onerror\n })\n : undefined;\n\n const serve = async (\n request: Request,\n requestOptions?: McpHandlerRequestOptions,\n workerCtx?: ExecutionContext\n ): Promise<Response> => {\n const requestUrl = new URL(request.url);\n if (requestUrl.pathname !== route) {\n return withCors(new Response(\"Not Found\", { status: 404 }), corsOptions);\n }\n\n // The SDK app factories can distinguish their bind address from an\n // attacker-controlled Host header. A bare Worker cannot. Use defaults we\n // can establish independently: localhost-class names, a standard\n // workers.dev route, and any concrete CORS Origin the application chose.\n // Custom-domain deployments can provide explicit Host and Origin lists.\n const localEndpoint = localhostAllowedHostnames().includes(\n requestUrl.hostname\n );\n const workersDevEndpoint = requestUrl.hostname.endsWith(\".workers.dev\");\n const acceptedHostnames =\n allowedHostnames ??\n (localEndpoint\n ? localhostAllowedHostnames()\n : workersDevEndpoint\n ? [requestUrl.hostname]\n : undefined);\n const hostRejection = acceptedHostnames\n ? hostHeaderValidationResponse(request, acceptedHostnames)\n : undefined;\n if (hostRejection) {\n return withCors(hostRejection, corsOptions);\n }\n if (allowedOriginHostnames !== \"*\") {\n let acceptedOriginHostnames = allowedOriginHostnames;\n if (acceptedOriginHostnames === undefined) {\n const defaults = new Set(localhostAllowedOrigins());\n if (workersDevEndpoint) defaults.add(requestUrl.hostname);\n if (corsOptions !== false && corsOptions.origin !== undefined) {\n try {\n const configuredOrigin = new URL(corsOptions.origin);\n if (\n (configuredOrigin.protocol === \"http:\" ||\n configuredOrigin.protocol === \"https:\") &&\n configuredOrigin.hostname\n ) {\n defaults.add(configuredOrigin.hostname);\n }\n } catch {\n // A wildcard or malformed CORS value does not expand the allowlist.\n }\n }\n acceptedOriginHostnames = [...defaults];\n }\n const originRejection = originValidationResponse(\n request,\n acceptedOriginHostnames ?? []\n );\n if (originRejection) {\n return withCors(originRejection, corsOptions);\n }\n }\n\n if (request.method === \"OPTIONS\" && corsOptions !== false) {\n return new Response(null, { headers: corsHeaders(corsOptions) });\n }\n\n const legacyRequest =\n legacyCompatibilityHandler !== undefined &&\n (await isLegacyRequest(request, requestOptions?.parsedBody));\n\n try {\n const verified = workerCtx\n ? getVerifiedOAuthAuthInfo(workerCtx)\n : undefined;\n const explicitAuthInfo = requestOptions?.authInfo;\n if (\n verified &&\n explicitAuthInfo &&\n explicitAuthInfo.clientId !== verified.authInfo.clientId\n ) {\n throw new TypeError(\"Conflicting verified OAuth client identity\");\n }\n\n const authInfo: AuthInfo | undefined =\n explicitAuthInfo ?? verified?.authInfo;\n const resolvedAuthContext =\n authContext ??\n (verified\n ? { props: verified.props }\n : workerCtx?.props && Object.keys(workerCtx.props).length > 0\n ? { props: workerCtx.props as Record<string, unknown> }\n : undefined);\n const upstreamOptions: McpHandlerRequestOptions | undefined =\n requestOptions || authInfo\n ? { ...requestOptions, ...(authInfo && { authInfo }) }\n : undefined;\n const invoke = async () => {\n if (legacyRequest && legacyCompatibilityHandler) {\n return legacyCompatibilityHandler.fetch(request, upstreamOptions);\n }\n return sdkHandler.fetch(request, upstreamOptions);\n };\n const response = resolvedAuthContext\n ? await runWithAuthContext(resolvedAuthContext, invoke)\n : await invoke();\n return withCors(\n wrapResponseBodyWithAuthContext(response, resolvedAuthContext),\n corsOptions\n );\n } catch (error) {\n reportHandlerError(sdkOptions.onerror, error);\n return withCors(internalErrorResponse(), corsOptions);\n }\n };\n\n const callable = (request: Request, _env: unknown, ctx: ExecutionContext) =>\n serve(request, undefined, ctx);\n const fetch = (request: Request, requestOptions?: McpHandlerRequestOptions) =>\n serve(request, requestOptions);\n\n return Object.assign(callable, {\n fetch,\n notify: sdkHandler.notify\n })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S,IAClC,KAAA;GACJ,MAAM,mBAAmB,gBAAgB;GACzC,IACE,YACA,oBACA,iBAAiB,aAAa,SAAS,SAAS,UAEhD,MAAM,IAAI,UAAU,4CAA4C;GAGlE,MAAM,WACJ,oBAAoB,UAAU;GAChC,MAAM,sBACJ,gBACC,WACG,EAAE,OAAO,SAAS,MAAM,IACxB,WAAW,SAAS,OAAO,KAAK,UAAU,KAAK,CAAC,CAAC,SAAS,IACxD,EAAE,OAAO,UAAU,MAAiC,IACpD,KAAA;GACR,MAAM,kBACJ,kBAAkB,WACd;IAAE,GAAG;IAAgB,GAAI,YAAY,EAAE,SAAS;GAAG,IACnD,KAAA;GACN,MAAM,SAAS,YAAY;IACzB,IAAI,iBAAiB,4BACnB,OAAO,2BAA2B,MAAM,SAAS,eAAe;IAElE,OAAO,WAAW,MAAM,SAAS,eAAe;GAClD;GAIA,OAAO,SACL,gCAJe,sBACb,MAAM,mBAAmB,qBAAqB,MAAM,IACpD,MAAM,OAAO,GAE2B,mBAAmB,GAC7D,WACF;EACF,SAAS,OAAO;GACd,mBAAmB,WAAW,SAAS,KAAK;GAC5C,OAAO,SAAS,sBAAsB,GAAG,WAAW;EACtD;CACF;CAEA,MAAM,YAAY,SAAkB,MAAe,QACjD,MAAM,SAAS,KAAA,GAAW,GAAG;CAC/B,MAAM,SAAS,SAAkB,mBAC/B,MAAM,SAAS,cAAc;CAE/B,OAAO,OAAO,OAAO,UAAU;EAC7B;EACA,QAAQ,WAAW;CACrB,CAAC;AACH"}
@@ -1,4 +1,4 @@
1
- import { ClientOptions } from "@modelcontextprotocol/client";
1
+ import { n as CORSOptions } from "./types-D2naO3rA.js";
2
2
  import {
3
3
  CreateMcpHandlerOptions,
4
4
  McpHandlerRequestOptions,
@@ -6,44 +6,6 @@ import {
6
6
  ServerNotifier
7
7
  } from "@modelcontextprotocol/server";
8
8
 
9
- //#region src/mcp/types.d.ts
10
- type MaybePromise<T> = T | Promise<T>;
11
- type HttpTransportType = "sse" | "streamable-http";
12
- type BaseTransportType = HttpTransportType | "rpc";
13
- type TransportType = BaseTransportType | "auto";
14
- /**
15
- * Agents-owned MCP client configuration. Only these SDK behaviours are part of
16
- * the supported interface; new beta SDK fields are not persisted or exposed
17
- * accidentally.
18
- */
19
- interface McpClientOptions {
20
- capabilities?: ClientOptions["capabilities"];
21
- jsonSchemaValidator?: ClientOptions["jsonSchemaValidator"];
22
- versionNegotiation?: ClientOptions["versionNegotiation"];
23
- inputRequired?: ClientOptions["inputRequired"];
24
- listChanged?: ClientOptions["listChanged"];
25
- supportedProtocolVersions?: ClientOptions["supportedProtocolVersions"];
26
- enforceStrictCapabilities?: ClientOptions["enforceStrictCapabilities"];
27
- debouncedNotificationMethods?: ClientOptions["debouncedNotificationMethods"];
28
- listMaxPages?: ClientOptions["listMaxPages"];
29
- responseCacheStore?: ClientOptions["responseCacheStore"];
30
- cachePartition?: ClientOptions["cachePartition"];
31
- defaultCacheTtlMs?: ClientOptions["defaultCacheTtlMs"];
32
- }
33
- interface CORSOptions {
34
- origin?: string;
35
- methods?: string;
36
- headers?: string;
37
- maxAge?: number;
38
- exposeHeaders?: string;
39
- }
40
- interface ServeOptions {
41
- binding?: string;
42
- corsOptions?: CORSOptions;
43
- transport?: TransportType;
44
- jurisdiction?: DurableObjectJurisdiction;
45
- }
46
- //#endregion
47
9
  //#region src/mcp/server/auth-context.d.ts
48
10
  interface McpAuthContext {
49
11
  props: Record<string, unknown>;
@@ -92,16 +54,10 @@ declare function createStatelessMcpHandler(
92
54
  //#endregion
93
55
  export {
94
56
  McpAuthContext as a,
95
- CORSOptions as c,
96
- ServeOptions as d,
97
- TransportType as f,
98
57
  createStatelessMcpHandler as i,
99
- MaybePromise as l,
100
58
  StatelessMcpHandler as n,
101
59
  getMcpAuthContext as o,
102
60
  StatelessMcpServerInput as r,
103
- BaseTransportType as s,
104
- CreateStatelessMcpHandlerOptions as t,
105
- McpClientOptions as u
61
+ CreateStatelessMcpHandlerOptions as t
106
62
  };
107
- //# sourceMappingURL=handler-stateless-DxYpJ_XF.d.ts.map
63
+ //# sourceMappingURL=handler-stateless-C90kD5_R.d.ts.map
@@ -274,21 +274,21 @@ type ContainerStatus =
274
274
  | "stopped";
275
275
  /** One event on a session's stream. */
276
276
  type ContainerSessionEvent =
277
- /** What the adapter reported, tagged with its operation. */ | (ContainerEvent & {
278
- readonly operationId: string | null;
279
- })
280
- | {
281
- readonly type: "operation-start";
282
- readonly operationId: string;
283
- }
284
- | {
285
- readonly type: "operation-end";
286
- readonly result: ContainerOperationResult;
287
- }
288
- | {
289
- readonly type: "container";
290
- readonly status: ContainerStatus;
291
- };
277
+ | /** What the adapter reported, tagged with its operation. */ (ContainerEvent & {
278
+ readonly operationId: string | null;
279
+ })
280
+ | {
281
+ readonly type: "operation-start";
282
+ readonly operationId: string;
283
+ }
284
+ | {
285
+ readonly type: "operation-end";
286
+ readonly result: ContainerOperationResult;
287
+ }
288
+ | {
289
+ readonly type: "container";
290
+ readonly status: ContainerStatus;
291
+ };
292
292
  /** The state of a session when a stream starts. */
293
293
  type ContainerSessionSnapshot = {
294
294
  readonly session: ContainerSessionId;
@@ -1,7 +1,6 @@
1
1
  import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "../../classPrivateFieldGet2-DZBYAB34.js";
2
2
  import { t as _classPrivateMethodInitSpec } from "../../classPrivateMethodInitSpec-qMjJ6sHQ.js";
3
3
  import { t as LifecycleCapability } from "../../capability-DBAKc6UZ.js";
4
- import "../../lifecycle-v1rKHV2C.js";
5
4
  import { n as openHarnessStore } from "../../store-CslVzfN7.js";
6
5
  import { d as parseDaemonMessage, i as CONTAINER_HEALTH_PATH, l as chunkEntries, o as CONTAINER_SESSION_PATH, r as CONTAINER_ENV, s as CONTAINER_TOKEN_HEADER } from "../../protocol-cOklVBBD.js";
7
6
  import { WorkerEntrypoint } from "cloudflare:workers";