agents 0.21.0 → 0.22.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 (137) hide show
  1. package/README.md +1 -0
  2. package/dist/{agent-tool-types-CzGGB-20.d.ts → agent-routing-CnkaHb-v.d.ts} +2921 -3057
  3. package/dist/agent-routing.d.ts +14 -0
  4. package/dist/agent-routing.js +187 -0
  5. package/dist/agent-routing.js.map +1 -0
  6. package/dist/agent-tool-types.d.ts +26 -26
  7. package/dist/{agent-tools-zR2d5uij.d.ts → agent-tools-C0XJqWzB.d.ts} +7 -7
  8. package/dist/agent-tools.d.ts +21 -21
  9. package/dist/agent-tools.js +2 -1
  10. package/dist/agent-tools.js.map +1 -1
  11. package/dist/browser/ai.js +2 -1
  12. package/dist/browser/ai.js.map +1 -1
  13. package/dist/capability-BjSKYpzg.js +42 -0
  14. package/dist/capability-BjSKYpzg.js.map +1 -0
  15. package/dist/capability-runner-CvHGZqUu.d.ts +150 -0
  16. package/dist/chat/index.d.ts +22 -15
  17. package/dist/chat/index.js +4 -4
  18. package/dist/chat/index.js.map +1 -1
  19. package/dist/chat/react.d.ts +14 -1
  20. package/dist/chat/react.js +82 -52
  21. package/dist/chat/react.js.map +1 -1
  22. package/dist/chat/transport.js +1 -1
  23. package/dist/chat-sdk/index.d.ts +4 -4
  24. package/dist/chat-sdk/index.js +1 -1
  25. package/dist/{client-zqKcsyFa.js → client-jagG8a9_.js} +129 -37
  26. package/dist/client-jagG8a9_.js.map +1 -0
  27. package/dist/client.d.ts +1 -1
  28. package/dist/client.js +1 -1
  29. package/dist/{cloudflare-BduZwmYK.js → cloudflare-Dzvc7V2N.js} +10 -3
  30. package/dist/{cloudflare-BduZwmYK.js.map → cloudflare-Dzvc7V2N.js.map} +1 -1
  31. package/dist/current-agent-CuMErtly.d.ts +283 -0
  32. package/dist/current-agent-DhoDkSnH.js +51 -0
  33. package/dist/current-agent-DhoDkSnH.js.map +1 -0
  34. package/dist/diagnostics-CaBjfz4J.js +41 -0
  35. package/dist/diagnostics-CaBjfz4J.js.map +1 -0
  36. package/dist/{do-oauth-client-provider-VTZj2VtM.d.ts → do-oauth-client-provider-Tmf1vgKz.d.ts} +2 -2
  37. package/dist/durable-object-lifecycle-D6nNQJJd.js +862 -0
  38. package/dist/durable-object-lifecycle-D6nNQJJd.js.map +1 -0
  39. package/dist/{email-CL27preh.d.ts → email-7TatiTnl.d.ts} +38 -9
  40. package/dist/email-send.d.ts +15 -0
  41. package/dist/email-send.js +32 -0
  42. package/dist/email-send.js.map +1 -0
  43. package/dist/email.d.ts +14 -10
  44. package/dist/email.js.map +1 -1
  45. package/dist/experimental/memory/session/index.d.ts +3 -2
  46. package/dist/experimental/memory/session/index.js +15 -10
  47. package/dist/experimental/memory/session/index.js.map +1 -1
  48. package/dist/{handler-stateless-C_bo-Ytq.d.ts → handler-stateless-DxYpJ_XF.d.ts} +3 -3
  49. package/dist/{handler-stateless-CIkKPETH.js → handler-stateless-VvrWSAVA.js} +5 -5
  50. package/dist/handler-stateless-VvrWSAVA.js.map +1 -0
  51. package/dist/{index-BRnybD6X.d.ts → index-DcSAZKsB.d.ts} +19 -31
  52. package/dist/index.d.ts +98 -95
  53. package/dist/index.js +10 -7234
  54. package/dist/internal_context-BlxFEWfn.d.ts +19 -0
  55. package/dist/internal_context.d.ts +10 -4
  56. package/dist/internal_context.js +1 -10
  57. package/dist/{client-invoker-BNSZxAkv.d.ts → invoker-CG0_p_Wq.d.ts} +2 -2
  58. package/dist/{client-invoker-VNZ7X0nn.js → invoker-CHMnoxIA.js} +2 -2
  59. package/dist/invoker-CHMnoxIA.js.map +1 -0
  60. package/dist/lifecycle/index.d.ts +48 -0
  61. package/dist/lifecycle/index.js +4 -0
  62. package/dist/mcp/{do-oauth-client-provider.d.ts → client/do-oauth-client-provider.d.ts} +1 -1
  63. package/dist/mcp/{do-oauth-client-provider.js → client/do-oauth-client-provider.js} +1 -1
  64. package/dist/mcp/client/do-oauth-client-provider.js.map +1 -0
  65. package/dist/mcp/client/index.d.ts +42 -0
  66. package/dist/mcp/{client.js → client/index.js} +1 -1
  67. package/dist/mcp/{x402.d.ts → client/x402.d.ts} +2 -2
  68. package/dist/mcp/{x402.js → client/x402.js} +2 -2
  69. package/dist/mcp/client/x402.js.map +1 -0
  70. package/dist/mcp/index.d.ts +36 -36
  71. package/dist/mcp/index.js +14 -16
  72. package/dist/mcp/index.js.map +1 -1
  73. package/dist/mcp/{server.d.ts → server/index.d.ts} +1 -1
  74. package/dist/mcp/{server.js → server/index.js} +1 -1
  75. package/dist/observability/ai/index.js +50 -35
  76. package/dist/observability/ai/index.js.map +1 -1
  77. package/dist/observability/index.d.ts +4 -4
  78. package/dist/observability/index.js +3 -50
  79. package/dist/observability/index.js.map +1 -1
  80. package/dist/{protocol-Dqc2MQxo.js → protocol-B0nh6KNf.js} +19 -21
  81. package/dist/protocol-B0nh6KNf.js.map +1 -0
  82. package/dist/react.d.ts +4 -4
  83. package/dist/react.js +1 -1
  84. package/dist/schedule.d.ts +25 -94
  85. package/dist/schedule.js +1 -98
  86. package/dist/schedule.js.map +1 -1
  87. package/dist/scheduler-CR9RHGos.js +857 -0
  88. package/dist/scheduler-CR9RHGos.js.map +1 -0
  89. package/dist/scheduler-DQoTGoAW.d.ts +224 -0
  90. package/dist/schedules/index.d.ts +22 -0
  91. package/dist/schedules/index.js +2 -0
  92. package/dist/schedules/parser.d.ts +79 -0
  93. package/dist/schedules/parser.js +103 -0
  94. package/dist/schedules/parser.js.map +1 -0
  95. package/dist/serializable.d.ts +1 -1
  96. package/dist/sql-error-CPY-GXyI.d.ts +12 -0
  97. package/dist/sql-error.d.ts +2 -0
  98. package/dist/sql-error.js +16 -0
  99. package/dist/sql-error.js.map +1 -0
  100. package/dist/src-5W6JNKVb.js +6613 -0
  101. package/dist/src-5W6JNKVb.js.map +1 -0
  102. package/dist/sub-routing.d.ts +12 -12
  103. package/dist/workflow-types.d.ts +25 -25
  104. package/dist/workflows.d.ts +22 -22
  105. package/dist/workflows.js +2 -1
  106. package/dist/workflows.js.map +1 -1
  107. package/dist/{ws-chat-transport-CIoOBbO7.js → ws-chat-transport-rWwta645.js} +152 -15
  108. package/dist/ws-chat-transport-rWwta645.js.map +1 -0
  109. package/docs/agent-class.md +28 -86
  110. package/docs/chat-agents.md +13 -12
  111. package/docs/durable-execution.md +1 -1
  112. package/docs/http-websockets.md +1 -11
  113. package/docs/human-in-the-loop.md +1 -1
  114. package/docs/index.md +1 -0
  115. package/docs/lifecycle.md +323 -0
  116. package/docs/long-running-agents.md +2 -4
  117. package/docs/mcp-client.md +55 -0
  118. package/docs/observability.md +11 -11
  119. package/docs/resumable-streaming.md +1 -1
  120. package/docs/scheduling.md +175 -15
  121. package/docs/server-driven-messages.md +1 -1
  122. package/docs/sub-agents.md +1 -1
  123. package/package.json +30 -21
  124. package/dist/cli/index.d.ts +0 -1
  125. package/dist/cli/index.js +0 -26
  126. package/dist/cli/index.js.map +0 -1
  127. package/dist/client-invoker-VNZ7X0nn.js.map +0 -1
  128. package/dist/client-zqKcsyFa.js.map +0 -1
  129. package/dist/handler-stateless-CIkKPETH.js.map +0 -1
  130. package/dist/index.js.map +0 -1
  131. package/dist/internal_context-Dg4Cgjcu.d.ts +0 -37
  132. package/dist/internal_context.js.map +0 -1
  133. package/dist/mcp/client.d.ts +0 -42
  134. package/dist/mcp/do-oauth-client-provider.js.map +0 -1
  135. package/dist/mcp/x402.js.map +0 -1
  136. package/dist/protocol-Dqc2MQxo.js.map +0 -1
  137. package/dist/ws-chat-transport-CIoOBbO7.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import { t as WebSocketChatTransport } from "../ws-chat-transport-CIoOBbO7.js";
1
+ import { t as WebSocketChatTransport } from "../ws-chat-transport-rWwta645.js";
2
2
  export { WebSocketChatTransport };
@@ -1,8 +1,8 @@
1
1
  import {
2
- O as Agent,
3
- ct as SubAgentClass,
4
- lt as SubAgentStub
5
- } from "../agent-tool-types-CzGGB-20.js";
2
+ M as SubAgentClass,
3
+ N as SubAgentStub,
4
+ c as Agent
5
+ } from "../agent-routing-CnkaHb-v.js";
6
6
  import { Lock, QueueEntry, StateAdapter } from "chat";
7
7
 
8
8
  //#region src/chat-sdk/agent.d.ts
@@ -1,4 +1,4 @@
1
- import { Agent, getCurrentAgent } from "../index.js";
1
+ import { a as getCurrentAgent, t as Agent } from "../src-5W6JNKVb.js";
2
2
  //#region src/chat-sdk/agent.ts
3
3
  const NEXT_CLEANUP_AT_KEY = "next_cleanup_at";
4
4
  const CLEANUP_SCHEDULE_ID_KEY = "cleanup_schedule_id";
@@ -1,8 +1,9 @@
1
+ import { getAgentByName } from "./agent-routing.js";
2
+ import { t as LifecycleCapability } from "./capability-BjSKYpzg.js";
1
3
  import { tryN } from "./retries.js";
2
- import { n as callV2Tool } from "./client-invoker-VNZ7X0nn.js";
3
- import { DurableObjectOAuthClientProvider } from "./mcp/do-oauth-client-provider.js";
4
+ import { n as callV2Tool } from "./invoker-CHMnoxIA.js";
5
+ import { DurableObjectOAuthClientProvider } from "./mcp/client/do-oauth-client-provider.js";
4
6
  import { nanoid } from "nanoid";
5
- import { getServerByName } from "partyserver";
6
7
  import { z } from "zod";
7
8
  import { Client, SSEClientTransport, SdkHttpError, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
8
9
  import { CfWorkerJsonSchemaValidator } from "@modelcontextprotocol/client/validators/cf-worker";
@@ -65,7 +66,7 @@ async function raceWithSignal(promise, signal) {
65
66
  });
66
67
  }
67
68
  //#endregion
68
- //#region src/mcp/client-catalog.ts
69
+ //#region src/mcp/client/catalog.ts
69
70
  async function fetchMcpTools(client, options) {
70
71
  let aggregate = [];
71
72
  let page = { tools: [] };
@@ -119,7 +120,7 @@ async function fetchMcpResourceTemplates(client, options) {
119
120
  return aggregate;
120
121
  }
121
122
  //#endregion
122
- //#region src/mcp/client-runtime.ts
123
+ //#region src/mcp/client/runtime.ts
123
124
  var CompatibleWorkerJsonSchemaValidator = class extends CfWorkerJsonSchemaValidator {
124
125
  constructor(..._args) {
125
126
  super(..._args);
@@ -197,7 +198,7 @@ function createMcpSdkClient(info, options, capabilitySeed, handlerModes, callbac
197
198
  };
198
199
  }
199
200
  //#endregion
200
- //#region src/mcp/errors.ts
201
+ //#region src/mcp/client/errors.ts
201
202
  function toErrorMessage(error) {
202
203
  return error instanceof Error ? error.message : String(error);
203
204
  }
@@ -230,6 +231,10 @@ function isTransportNotImplemented(error) {
230
231
  //#endregion
231
232
  //#region src/mcp/rpc.ts
232
233
  const RPC_DO_PREFIX = "rpc:";
234
+ /** Narrow an unknown runtime binding to an MCP Durable Object namespace. */
235
+ function isDurableObjectNamespace(namespace) {
236
+ return typeof namespace === "object" && namespace !== null && "newUniqueId" in namespace && typeof namespace.newUniqueId === "function" && "idFromName" in namespace && typeof namespace.idFromName === "function";
237
+ }
233
238
  function makeInvalidRequestError(id) {
234
239
  return {
235
240
  jsonrpc: "2.0",
@@ -259,7 +264,7 @@ var RPCClientTransport = class {
259
264
  async start() {
260
265
  if (this._started) throw new Error("Transport already started");
261
266
  const doName = `${RPC_DO_PREFIX}${this._name}`;
262
- this._stub = await getServerByName(this._namespace, doName, { props: this._props });
267
+ this._stub = await getAgentByName(this._namespace, doName, { props: this._props });
263
268
  this._started = true;
264
269
  }
265
270
  async close() {
@@ -444,7 +449,7 @@ var RPCServerTransport = class {
444
449
  }
445
450
  };
446
451
  //#endregion
447
- //#region src/mcp/client-connection.ts
452
+ //#region src/mcp/client/connection.ts
448
453
  /**
449
454
  * Connection state machine for MCP client connections.
450
455
  *
@@ -1004,7 +1009,21 @@ var MCPClientConnection = class {
1004
1009
  }
1005
1010
  };
1006
1011
  //#endregion
1007
- //#region src/mcp/client-storage.ts
1012
+ //#region src/mcp/client/storage.ts
1013
+ /** Create the durable MCP server catalog table when it does not exist. */
1014
+ function ensureMcpServerTable(storage) {
1015
+ storage.sql.exec(`
1016
+ CREATE TABLE IF NOT EXISTS cf_agents_mcp_servers (
1017
+ id TEXT PRIMARY KEY NOT NULL,
1018
+ name TEXT NOT NULL,
1019
+ server_url TEXT NOT NULL,
1020
+ callback_url TEXT NOT NULL,
1021
+ client_id TEXT,
1022
+ auth_url TEXT,
1023
+ server_options TEXT
1024
+ )
1025
+ `);
1026
+ }
1008
1027
  function persistClientOptions(client) {
1009
1028
  if (!client) return void 0;
1010
1029
  return {
@@ -1085,7 +1104,40 @@ function withMcpSession(options, session) {
1085
1104
  };
1086
1105
  }
1087
1106
  //#endregion
1088
- //#region src/mcp/client.ts
1107
+ //#region src/mcp/client/rpc.ts
1108
+ /** Restore persisted RPC connections through a manager's public transport API. */
1109
+ async function restoreRpcConnections(manager, env, servers) {
1110
+ if (!env) {
1111
+ for (const server of servers) console.warn(`[MCPClientManager] Cannot restore RPC MCP server "${server.name}": no env was provided; pass { env } when constructing MCPClientManager`);
1112
+ return;
1113
+ }
1114
+ for (const server of servers) {
1115
+ if (manager.mcpConnections[server.id]) continue;
1116
+ const options = decodeMcpServerOptions(server.server_options);
1117
+ const binding = options.bindingName ? Object.entries(env).find(([name]) => name === options.bindingName)?.[1] : void 0;
1118
+ if (!isDurableObjectNamespace(binding)) {
1119
+ console.warn(`[MCPClientManager] Cannot restore RPC MCP server "${server.name}": binding "${options.bindingName ?? "<missing>"}" not found in env`);
1120
+ continue;
1121
+ }
1122
+ const normalizedName = server.server_url.replace(RPC_DO_PREFIX, "");
1123
+ try {
1124
+ await manager.connect(`${RPC_DO_PREFIX}${normalizedName}`, {
1125
+ reconnect: { id: server.id },
1126
+ transport: {
1127
+ type: "rpc",
1128
+ namespace: binding,
1129
+ name: normalizedName,
1130
+ props: options.props
1131
+ }
1132
+ });
1133
+ if (manager.mcpConnections[server.id]?.connectionState === MCPConnectionState.CONNECTED) await manager.discoverIfConnected(server.id);
1134
+ } catch (error) {
1135
+ console.error(`[MCPClientManager] Error restoring RPC MCP server "${server.name}":`, error);
1136
+ }
1137
+ }
1138
+ }
1139
+ //#endregion
1140
+ //#region src/mcp/client/index.ts
1089
1141
  /** Maximum length of a normalized MCP server id. */
1090
1142
  const MCP_SERVER_ID_MAX_LENGTH = 64;
1091
1143
  /**
@@ -1215,16 +1267,23 @@ var ConnectRetryError = class extends Error {
1215
1267
  this.result = result;
1216
1268
  }
1217
1269
  };
1270
+ const MCP_SCHEMA_VERSION_KEY = "cf_agents:mcp_schema_version";
1271
+ const CURRENT_MCP_SCHEMA_VERSION = 1;
1218
1272
  /**
1219
- * Utility class that aggregates multiple MCP clients into one
1273
+ * A Durable Object capability that persists and aggregates MCP client
1274
+ * connections. Installing it directly on a Lifecycle (outside `agent.mcp`)
1275
+ * is experimental: that capability surface may change before stabilizing.
1220
1276
  */
1221
- var MCPClientManager = class {
1277
+ var MCPClientManager = class extends LifecycleCapability {
1222
1278
  /**
1223
- * @param _name Name of the MCP client
1224
- * @param _version Version of the MCP Client
1225
- * @param options Storage adapter for persisting MCP server state
1279
+ * Construct a reusable Durable Object MCP client capability.
1280
+ *
1281
+ * @param _name - MCP client implementation name sent during negotiation.
1282
+ * @param _version - MCP client implementation version sent during negotiation.
1283
+ * @param options - Optional runtime bindings and OAuth configuration.
1226
1284
  */
1227
- constructor(_name, _version, options) {
1285
+ constructor(_name, _version, options = {}) {
1286
+ super("mcp");
1228
1287
  this._name = _name;
1229
1288
  this._version = _version;
1230
1289
  this.mcpConnections = {};
@@ -1237,10 +1296,44 @@ var MCPClientManager = class {
1237
1296
  this.onObservabilityEvent = this._onObservabilityEvent.event;
1238
1297
  this._onServerStateChanged = new Emitter();
1239
1298
  this.onServerStateChanged = this._onServerStateChanged.event;
1240
- if (!options.storage) throw new Error("MCPClientManager requires a valid DurableObjectStorage instance");
1241
- this._storage = options.storage;
1299
+ this._env = options.env;
1242
1300
  this._createAuthProviderFn = options.createAuthProvider;
1243
1301
  }
1302
+ /** Restore persisted HTTP and RPC connections before the host handles work. */
1303
+ async onStart() {
1304
+ if ((await this.lifecycle.storage.get(MCP_SCHEMA_VERSION_KEY) ?? 0) < CURRENT_MCP_SCHEMA_VERSION) {
1305
+ ensureMcpServerTable(this.lifecycle.storage);
1306
+ await this.lifecycle.storage.put(MCP_SCHEMA_VERSION_KEY, CURRENT_MCP_SCHEMA_VERSION);
1307
+ }
1308
+ await this.restoreConnectionsFromStorage(this._name);
1309
+ await restoreRpcConnections(this, this._env, this.getRpcServersFromStorage());
1310
+ this._onServerStateChanged.fire();
1311
+ }
1312
+ /** Intercept a registered MCP OAuth callback request. */
1313
+ async onRequest(context) {
1314
+ const { request } = context;
1315
+ if (!this.isCallbackRequest(request)) return void 0;
1316
+ const result = await this.handleCallbackRequest(request);
1317
+ if (result.authSuccess) this.establishConnection(result.serverId).catch((error) => {
1318
+ console.error("[MCPClientManager] Connection establishment after OAuth failed:", error);
1319
+ });
1320
+ return this.oauthCallbackResponse(result, request);
1321
+ }
1322
+ oauthCallbackResponse(result, request) {
1323
+ const config = this.getOAuthCallbackConfig();
1324
+ if (config?.customHandler) return config.customHandler(result);
1325
+ const baseOrigin = new URL(request.url).origin;
1326
+ const redirect = result.authSuccess ? config?.successRedirect : config?.errorRedirect;
1327
+ if (!redirect) return Response.redirect(baseOrigin);
1328
+ try {
1329
+ const target = new URL(redirect, baseOrigin);
1330
+ if (!result.authSuccess) target.searchParams.set("error", result.authError);
1331
+ return Response.redirect(target);
1332
+ } catch (error) {
1333
+ console.error("Invalid OAuth callback redirect URL:", redirect, error);
1334
+ return Response.redirect(baseOrigin);
1335
+ }
1336
+ }
1244
1337
  /**
1245
1338
  * Scope the manager-level elicitation handler to a single connection.
1246
1339
  * Returns undefined when no handler is configured so the connection keeps
@@ -1257,7 +1350,7 @@ var MCPClientManager = class {
1257
1350
  };
1258
1351
  }
1259
1352
  sql(query, ...bindings) {
1260
- return [...this._storage.sql.exec(query, ...bindings)];
1353
+ return [...this.lifecycle.storage.sql.exec(query, ...bindings)];
1261
1354
  }
1262
1355
  saveServerToStorage(server) {
1263
1356
  this.sql(`INSERT OR REPLACE INTO cf_agents_mcp_servers (
@@ -1302,7 +1395,7 @@ var MCPClientManager = class {
1302
1395
  const oldPrefix = `/${clientName}/${oldId}/`;
1303
1396
  const newPrefix = `/${clientName}/${newId}/`;
1304
1397
  try {
1305
- const keys = await this._storage.list({ prefix: oldPrefix });
1398
+ const keys = await this.lifecycle.storage.list({ prefix: oldPrefix });
1306
1399
  if (keys.size > 0) {
1307
1400
  const writes = {};
1308
1401
  const deletes = [];
@@ -1311,8 +1404,8 @@ var MCPClientManager = class {
1311
1404
  writes[newKey] = value;
1312
1405
  deletes.push(oldKey);
1313
1406
  }
1314
- await this._storage.put(writes);
1315
- await this._storage.delete(deletes);
1407
+ await this.lifecycle.storage.put(writes);
1408
+ await this.lifecycle.storage.delete(deletes);
1316
1409
  }
1317
1410
  } catch (error) {
1318
1411
  console.warn(`[MCPClientManager] OAuth key migration ${oldPrefix} → ${newPrefix} failed:`, error);
@@ -1489,23 +1582,19 @@ var MCPClientManager = class {
1489
1582
  * @internal
1490
1583
  */
1491
1584
  createAuthProvider(serverId, callbackUrl, clientName, clientId) {
1492
- if (!this._storage) throw new Error("Cannot create auth provider: storage is not initialized");
1493
- const authProvider = new DurableObjectOAuthClientProvider(this._storage, clientName, callbackUrl);
1585
+ const authProvider = new DurableObjectOAuthClientProvider(this.lifecycle.storage, clientName, callbackUrl);
1494
1586
  authProvider.serverId = serverId;
1495
1587
  if (clientId) authProvider.clientId = clientId;
1496
1588
  return authProvider;
1497
1589
  }
1498
- /**
1499
- * Get saved RPC servers from storage (servers with rpc:// URLs).
1500
- * These are restored separately by the Agent class since they need env bindings.
1501
- */
1590
+ /** Get saved RPC servers from storage (servers with `rpc://` URLs). */
1502
1591
  getRpcServersFromStorage() {
1503
1592
  return this.getServersFromStorage().filter((s) => s.server_url.startsWith(RPC_DO_PREFIX));
1504
1593
  }
1505
1594
  /**
1506
1595
  * Save an RPC server to storage for hibernation recovery.
1507
- * The bindingName is stored in server_options so the Agent can look up
1508
- * the namespace from env during restore.
1596
+ * The binding name is stored so this manager can resolve the namespace from
1597
+ * its runtime environment during restore.
1509
1598
  */
1510
1599
  saveRpcServerToStorage(id, name, normalizedName, bindingName, props) {
1511
1600
  this.saveServerToStorage({
@@ -1523,12 +1612,9 @@ var MCPClientManager = class {
1523
1612
  });
1524
1613
  }
1525
1614
  /**
1526
- * Restore MCP server connections from storage
1527
- * This method is called on Agent initialization to restore previously connected servers.
1528
- * RPC servers (rpc:// URLs) are skipped here -- they are restored by the Agent class
1529
- * which has access to env bindings.
1615
+ * Restore persisted HTTP MCP connections.
1530
1616
  *
1531
- * @param clientName Name to use for OAuth client (typically the agent instance name)
1617
+ * @param clientName - Durable Object identity used to scope OAuth state.
1532
1618
  */
1533
1619
  async restoreConnectionsFromStorage(clientName) {
1534
1620
  if (this._isRestored) return;
@@ -1766,10 +1852,16 @@ var MCPClientManager = class {
1766
1852
  */
1767
1853
  async registerServer(id, options) {
1768
1854
  if (isBlockedUrl(options.url)) throw new Error(`Blocked URL: ${options.url} — MCP client connections to private/internal addresses are not allowed`);
1855
+ const authProvider = options.transport?.authProvider ?? (options.callbackUrl ? this._createAuthProviderFn?.(options.callbackUrl) ?? this.createAuthProvider(id, options.callbackUrl, this._name, options.clientId) : void 0);
1856
+ if (authProvider) {
1857
+ authProvider.serverId = id;
1858
+ if (options.clientId) authProvider.clientId = options.clientId;
1859
+ }
1769
1860
  this.createConnection(id, options.url, {
1770
1861
  client: options.client,
1771
1862
  transport: {
1772
1863
  ...options.transport,
1864
+ authProvider,
1773
1865
  type: options.transport?.type ?? "auto"
1774
1866
  }
1775
1867
  });
@@ -2380,6 +2472,6 @@ function getNamespacedData(mcpClients, type) {
2380
2472
  });
2381
2473
  }
2382
2474
  //#endregion
2383
- export { MCPConnectionState as a, RPC_DO_PREFIX as c, normalizeServerId as i, DisposableStore as l, MCP_SERVER_ID_MAX_LENGTH as n, RPCClientTransport as o, getNamespacedData as r, RPCServerTransport as s, MCPClientManager as t };
2475
+ export { ensureMcpServerTable as a, RPCServerTransport as c, DisposableStore as d, normalizeServerId as i, RPC_DO_PREFIX as l, MCP_SERVER_ID_MAX_LENGTH as n, MCPConnectionState as o, getNamespacedData as r, RPCClientTransport as s, MCPClientManager as t, isDurableObjectNamespace as u };
2384
2476
 
2385
- //# sourceMappingURL=client-zqKcsyFa.js.map
2477
+ //# sourceMappingURL=client-jagG8a9_.js.map