agents 0.17.3 → 0.17.4

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.
@@ -41,6 +41,7 @@ import {
41
41
  import {
42
42
  CallToolRequest,
43
43
  CallToolResultSchema,
44
+ ClientCapabilities,
44
45
  CompatibilityCallToolResultSchema,
45
46
  ElicitRequest,
46
47
  ElicitRequest as ElicitRequest$1,
@@ -808,11 +809,30 @@ type MCPDiscoveryResult = {
808
809
  success: boolean;
809
810
  error?: string;
810
811
  };
812
+ /**
813
+ * Handler for server-initiated `elicitation/create` requests.
814
+ * Held in memory only — never persisted — so it must be re-supplied when a
815
+ * connection is recreated (e.g. after Durable Object hibernation).
816
+ */
817
+ type MCPElicitationHandler = (request: ElicitRequest) => Promise<ElicitResult>;
818
+ type MCPElicitationHandlers = {
819
+ form?: MCPElicitationHandler;
820
+ url?: MCPElicitationHandler;
821
+ };
811
822
  declare class MCPClientConnection {
812
823
  url: URL;
824
+ private readonly _info;
813
825
  options: {
814
826
  transport: MCPTransportOptions;
815
827
  client: McpClientOptions;
828
+ elicitationHandlers?: MCPElicitationHandlers;
829
+ /**
830
+ * Client capabilities persisted from a previous session, advertised
831
+ * until handlers are reconfigured after a hibernation restore. Cleared
832
+ * by {@link configureElicitationHandlers} — reconfigured handlers are
833
+ * the source of truth. Explicit `client.capabilities` win per key.
834
+ */
835
+ capabilitySeed?: ClientCapabilities;
816
836
  };
817
837
  client: Client;
818
838
  connectionState: MCPConnectionState;
@@ -839,14 +859,41 @@ declare class MCPClientConnection {
839
859
  private _discoveryAbortController;
840
860
  private readonly _onObservabilityEvent;
841
861
  readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
862
+ /**
863
+ * Whether the connection advertised the elicitation capability. The SDK
864
+ * client refuses to register an `elicitation/create` request handler when
865
+ * the capability was not declared, so handler registration is gated on
866
+ * this.
867
+ */
868
+ private _elicitationEnabled;
842
869
  constructor(
843
870
  url: URL,
844
- info: ConstructorParameters<typeof Client>[0],
871
+ _info: ConstructorParameters<typeof Client>[0],
845
872
  options?: {
846
873
  transport: MCPTransportOptions;
847
874
  client: McpClientOptions;
875
+ elicitationHandlers?: MCPElicitationHandlers;
876
+ /**
877
+ * Client capabilities persisted from a previous session, advertised
878
+ * until handlers are reconfigured after a hibernation restore. Cleared
879
+ * by {@link configureElicitationHandlers} — reconfigured handlers are
880
+ * the source of truth. Explicit `client.capabilities` win per key.
881
+ */
882
+ capabilitySeed?: ClientCapabilities;
848
883
  }
849
884
  );
885
+ private createClient;
886
+ /**
887
+ * Configure the handler used for server-initiated elicitation requests.
888
+ *
889
+ * If the connection has not been initialized yet, rebuild the SDK client so
890
+ * handler-driven elicitation capabilities are reflected in the initial
891
+ * handshake. A rebuild (rather than `Client.registerCapabilities`) is
892
+ * required because SDK capability registration is merge-only — it cannot
893
+ * un-advertise a mode when handlers are cleared before connecting. Active
894
+ * connections keep their negotiated capabilities until they reconnect.
895
+ */
896
+ configureElicitationHandlers(handlers?: MCPElicitationHandlers): void;
850
897
  /**
851
898
  * Initialize a client connection, if authentication is required, the connection will be in the AUTHENTICATING state
852
899
  * Sets connection state based on the result and emits observability events
@@ -1047,10 +1094,14 @@ declare class MCPClientConnection {
1047
1094
  }[]
1048
1095
  >;
1049
1096
  /**
1050
- * Handle elicitation request from server
1051
- * Automatically uses the Agent's built-in elicitation handling if available
1097
+ * Handle elicitation request from server.
1098
+ *
1099
+ * Delegates to the `elicitationHandlers` connection option when provided.
1100
+ *
1101
+ * @deprecated Overriding or instance-patching this method directly is
1102
+ * deprecated — pass the `elicitationHandlers` connection option instead.
1052
1103
  */
1053
- handleElicitationRequest(_request: ElicitRequest): Promise<ElicitResult>;
1104
+ handleElicitationRequest(request: ElicitRequest): Promise<ElicitResult>;
1054
1105
  private isResumedStreamableHttpSession;
1055
1106
  get sessionId(): string | undefined;
1056
1107
  private getTransportName;
@@ -1135,6 +1186,12 @@ type MCPServerOptions = {
1135
1186
  sessionId?: string;
1136
1187
  } /** Retry options for connection and reconnection attempts */;
1137
1188
  retry?: RetryOptions;
1189
+ /**
1190
+ * Client capabilities advertised from configured handlers (currently the
1191
+ * elicitation modes). Handlers are functions and cannot be persisted, so
1192
+ * this records what they advertised for restores after hibernation.
1193
+ */
1194
+ capabilities?: ClientCapabilities;
1138
1195
  };
1139
1196
  /**
1140
1197
  * Result of an OAuth callback request
@@ -1207,6 +1264,14 @@ type MCPClientOAuthResult =
1207
1264
  authSuccess: false /** May contain untrusted content from external OAuth providers. Escape appropriately for your output context. */;
1208
1265
  authError: string;
1209
1266
  };
1267
+ type MCPClientElicitationHandler = (
1268
+ request: ElicitRequest,
1269
+ serverId: string
1270
+ ) => Promise<ElicitResult>;
1271
+ type MCPClientElicitationHandlers = {
1272
+ form?: MCPClientElicitationHandler;
1273
+ url?: MCPClientElicitationHandler;
1274
+ };
1210
1275
  type MCPClientManagerOptions = {
1211
1276
  storage: DurableObjectStorage;
1212
1277
  createAuthProvider?: (callbackUrl: string) => AgentMcpOAuthProvider;
@@ -1238,6 +1303,7 @@ declare class MCPClientManager {
1238
1303
  private _createAuthProviderFn?;
1239
1304
  private _isRestored;
1240
1305
  private _pendingConnections;
1306
+ private _elicitationHandlers?;
1241
1307
  /** @internal Protected for testing purposes. */
1242
1308
  protected readonly _onObservabilityEvent: Emitter<MCPObservabilityEvent>;
1243
1309
  readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
@@ -1257,6 +1323,12 @@ declare class MCPClientManager {
1257
1323
  _version: string,
1258
1324
  options: MCPClientManagerOptions
1259
1325
  );
1326
+ /**
1327
+ * Scope the manager-level elicitation handler to a single connection.
1328
+ * Returns undefined when no handler is configured so the connection keeps
1329
+ * its default throwing behavior.
1330
+ */
1331
+ private scopedElicitationHandlers;
1260
1332
  private sql;
1261
1333
  private saveServerToStorage;
1262
1334
  private removeServerFromStorage;
@@ -1287,6 +1359,19 @@ declare class MCPClientManager {
1287
1359
  private _renameInMemoryConnection;
1288
1360
  private getServersFromStorage;
1289
1361
  private filterConnections;
1362
+ /**
1363
+ * Get the parsed server_options for a stored server, if any.
1364
+ */
1365
+ private getStoredServerOptions;
1366
+ /**
1367
+ * Clear the capabilities persisted on a stored server row. Called once a
1368
+ * seeded connection's handshake completes (see `createConnection`): the
1369
+ * stamp is valid for one successful restore — sessions that configure
1370
+ * handlers re-stamp every row, so a deploy that stops configuring them
1371
+ * stops advertising stale modes after its first connected wake instead of
1372
+ * forever, while wakes that never handshake don't burn the stamp.
1373
+ */
1374
+ private clearStoredCapabilities;
1290
1375
  /**
1291
1376
  * Get the retry options for a server from stored server_options
1292
1377
  */
@@ -1445,6 +1530,33 @@ declare class MCPClientManager {
1445
1530
  * @param config OAuth callback configuration
1446
1531
  */
1447
1532
  configureOAuthCallback(config: MCPClientOAuthCallbackConfig): void;
1533
+ /**
1534
+ * Configure handling for server-initiated `elicitation/create` requests.
1535
+ *
1536
+ * The handler is held in memory only and applied to every MCP connection
1537
+ * created or restored by this manager. Call this before registering
1538
+ * connections when you want the initial MCP handshake to advertise
1539
+ * handler-driven form- and url-mode elicitation. Existing active connections
1540
+ * keep their negotiated capabilities until they reconnect.
1541
+ *
1542
+ * The advertised modes are persisted with each stored server, so
1543
+ * connections restored after hibernation re-advertise them at the handshake
1544
+ * even when this is called later in the wake-up (e.g. from onStart) — the
1545
+ * handlers attach to the live connections as soon as this runs.
1546
+ *
1547
+ * Pass undefined to clear the handler.
1548
+ *
1549
+ * @param handlers Elicitation handlers keyed by mode, each scoped with the server id that sent the request
1550
+ */
1551
+ configureElicitationHandlers(handlers?: MCPClientElicitationHandlers): void;
1552
+ /** Client capabilities advertised from the currently configured handlers. */
1553
+ private advertisedHandlerCapabilities;
1554
+ /**
1555
+ * Record the handler-derived capabilities on every stored server row so a
1556
+ * restore after hibernation re-advertises them before the handlers
1557
+ * themselves are reconfigured.
1558
+ */
1559
+ private persistAdvertisedCapabilities;
1448
1560
  /**
1449
1561
  * Get the current OAuth callback configuration
1450
1562
  * @returns The current OAuth callback configuration
@@ -1743,9 +1855,7 @@ declare class MCPClientManager {
1743
1855
  uri: string;
1744
1856
  text: string;
1745
1857
  mimeType?: string | undefined;
1746
- _meta /** Include only connections matching this server ID (or IDs). */?/** Include only connections matching this server ID (or IDs). */ :
1747
- | Record<string, unknown>
1748
- | undefined;
1858
+ _meta?: Record<string, unknown> | undefined;
1749
1859
  }
1750
1860
  | {
1751
1861
  uri: string;
@@ -1784,11 +1894,7 @@ declare class MCPClientManager {
1784
1894
  icons?:
1785
1895
  | {
1786
1896
  src: string;
1787
- mimeType?/**
1788
- * Event that fires whenever any MCP server state changes (registered, connected, removed, etc.)
1789
- * This is useful for broadcasting server state to clients.
1790
- */
1791
- : string | undefined;
1897
+ mimeType?: string | undefined;
1792
1898
  sizes?: string[] | undefined;
1793
1899
  theme?: "light" | "dark" | undefined;
1794
1900
  }[]
@@ -4663,6 +4769,7 @@ declare class Agent<
4663
4769
  state: typeof MCPConnectionState.READY;
4664
4770
  }
4665
4771
  >;
4772
+ private _isAbsoluteHttpUrl;
4666
4773
  removeMcpServer(id: string): Promise<void>;
4667
4774
  getMcpServers(): MCPServersState;
4668
4775
  /**
@@ -5275,71 +5382,72 @@ type AgentToolEventState<Part extends AgentToolRunPart = AgentToolRunPart> = {
5275
5382
  //#endregion
5276
5383
  export {
5277
5384
  RoutingRetryOptions as $,
5278
- McpClientOptions as $t,
5385
+ WorkerTransport as $t,
5279
5386
  AgentGetOptions as A,
5280
- getNamespacedData as At,
5387
+ MCP_SERVER_ID_MAX_LENGTH as At,
5281
5388
  EmailSendBinding as B,
5282
- McpAgent as Bt,
5389
+ RPC_DO_PREFIX as Bt,
5283
5390
  DetachedRunAgentToolResult as C,
5284
- MCPConnectionResult as Ct,
5391
+ MCPClientOAuthCallbackConfig as Ct,
5285
5392
  AddRpcMcpServerOptions as D,
5286
- MCPServerOptions as Dt,
5393
+ MCPOAuthCallbackResult as Dt,
5287
5394
  AddMcpServerOptions as E,
5288
- MCPServerFilter as Et,
5395
+ MCPDiscoverResult as Et,
5289
5396
  Connection$1 as F,
5290
- RPCServerTransportOptions as Ft,
5397
+ MCPElicitationHandlers as Ft,
5291
5398
  FiberStatus as G,
5292
- experimental_createMcpHandler as Gt,
5399
+ ClearableEventStore as Gt,
5293
5400
  FiberInspection as H,
5294
- DurableObjectEventStore as Ht,
5401
+ ElicitRequestSchema$1 as Ht,
5295
5402
  ConnectionContext$1 as I,
5296
- RPC_DO_PREFIX as It,
5403
+ RPCClientTransport as It,
5297
5404
  MCPServerMessage as J,
5298
- TransportState as Jt,
5405
+ createMcpHandler as Jt,
5299
5406
  ListFibersOptions as K,
5300
- McpAuthContext as Kt,
5407
+ DurableObjectEventStore as Kt,
5301
5408
  DEFAULT_AGENT_STATIC_OPTIONS as L,
5302
- ElicitRequest$1 as Lt,
5409
+ RPCClientTransportOptions as Lt,
5303
5410
  AgentOptions as M,
5304
- RPCClientTransport as Mt,
5411
+ getNamespacedData as Mt,
5305
5412
  AgentStaticOptions as N,
5306
- RPCClientTransportOptions as Nt,
5413
+ normalizeServerId as Nt,
5307
5414
  Agent as O,
5308
- MCP_SERVER_ID_MAX_LENGTH as Ot,
5415
+ MCPServerFilter as Ot,
5309
5416
  CallableMetadata as P,
5310
- RPCServerTransport as Pt,
5417
+ MCPElicitationHandler as Pt,
5311
5418
  RPCResponse as Q,
5312
- StreamableHTTPEdgeClientTransport as Qt,
5419
+ TransportState as Qt,
5313
5420
  DeleteFibersOptions as R,
5314
- ElicitRequestSchema$1 as Rt,
5421
+ RPCServerTransport as Rt,
5315
5422
  DetachedAgentToolConfig as S,
5316
- MCPClientOAuthResult as St,
5423
+ MCPClientManagerOptions as St,
5317
5424
  RunAgentToolResult as T,
5318
- MCPOAuthCallbackResult as Tt,
5425
+ MCPConnectionResult as Tt,
5319
5426
  FiberRecoveryContext as U,
5320
- CreateMcpHandlerOptions as Ut,
5427
+ ElicitResult$1 as Ut,
5321
5428
  FiberContext as V,
5322
- ClearableEventStore as Vt,
5429
+ ElicitRequest$1 as Vt,
5323
5430
  FiberRecoveryResult as W,
5324
- createMcpHandler as Wt,
5431
+ McpAgent as Wt,
5325
5432
  QueueItem as X,
5326
- WorkerTransportOptions as Xt,
5433
+ McpAuthContext as Xt,
5327
5434
  MCPServersState as Y,
5328
- WorkerTransport as Yt,
5435
+ experimental_createMcpHandler as Yt,
5329
5436
  RPCRequest as Z,
5330
- SSEEdgeClientTransport as Zt,
5437
+ getMcpAuthContext as Zt,
5331
5438
  AgentToolRunState as _,
5332
5439
  MCPAITool as _t,
5333
5440
  AgentToolEvent as a,
5334
- routeSubAgentRequest as an,
5441
+ SUB_PREFIX as an,
5335
5442
  StartFiberResult as at,
5336
5443
  AgentToolTerminalStatus as b,
5337
- MCPClientManagerOptions as bt,
5444
+ MCPClientElicitationHandlers as bt,
5338
5445
  AgentToolFailure as c,
5446
+ parseSubAgentPath as cn,
5339
5447
  SubAgentClass as ct,
5340
5448
  AgentToolMilestone as d,
5341
5449
  callable as dt,
5342
- TransportType as en,
5450
+ WorkerTransportOptions as en,
5343
5451
  Schedule as et,
5344
5452
  AgentToolProgress as f,
5345
5453
  getAgentByName as ft,
@@ -5348,44 +5456,47 @@ export {
5348
5456
  AgentToolRunInspection as h,
5349
5457
  routeAgentRequest as ht,
5350
5458
  AgentToolDisplayMetadata as i,
5351
- parseSubAgentPath as in,
5459
+ TransportType as in,
5352
5460
  StartFiberOptions as it,
5353
5461
  AgentNamespace as j,
5354
- normalizeServerId as jt,
5462
+ RegisterServerOptions as jt,
5355
5463
  AgentContext as k,
5356
- RegisterServerOptions as kt,
5464
+ MCPServerOptions as kt,
5357
5465
  AgentToolInterruptedReason as l,
5466
+ routeSubAgentRequest as ln,
5358
5467
  SubAgentStub as lt,
5359
5468
  AgentToolRunInfo as m,
5360
5469
  routeAgentEmail as mt,
5361
5470
  AGENT_TOOL_PROGRESS_PART as n,
5362
- SubAgentPathMatch as nn,
5471
+ StreamableHTTPEdgeClientTransport as nn,
5363
5472
  SendEmailOptions as nt,
5364
5473
  AgentToolEventMessage as o,
5474
+ SubAgentPathMatch as on,
5365
5475
  StateUpdateMessage as ot,
5366
5476
  AgentToolProgressSnapshot as p,
5367
5477
  getCurrentAgent as pt,
5368
5478
  MCPServer as q,
5369
- getMcpAuthContext as qt,
5479
+ CreateMcpHandlerOptions as qt,
5370
5480
  AgentToolChildAdapter as r,
5371
- getSubAgentByName as rn,
5481
+ McpClientOptions as rn,
5372
5482
  SqlError as rt,
5373
5483
  AgentToolEventState as s,
5484
+ getSubAgentByName as sn,
5374
5485
  StreamingResponse as st,
5375
5486
  AGENT_TOOL_MILESTONE_PART as t,
5376
- SUB_PREFIX as tn,
5487
+ SSEEdgeClientTransport as tn,
5377
5488
  ScheduleCriteria as tt,
5378
5489
  AgentToolLifecycleResult as u,
5379
5490
  WSMessage$1 as ut,
5380
5491
  AgentToolRunStatus as v,
5381
5492
  MCPAIToolSet as vt,
5382
5493
  RunAgentToolOptions as w,
5383
- MCPDiscoverResult as wt,
5494
+ MCPClientOAuthResult as wt,
5384
5495
  ChatCapableAgentClass as x,
5385
- MCPClientOAuthCallbackConfig as xt,
5496
+ MCPClientManager as xt,
5386
5497
  AgentToolStoredChunk as y,
5387
- MCPClientManager as yt,
5498
+ MCPClientElicitationHandler as yt,
5388
5499
  EmailRoutingOptions as z,
5389
- ElicitResult$1 as zt
5500
+ RPCServerTransportOptions as zt
5390
5501
  };
5391
- //# sourceMappingURL=agent-tool-types-CNyE1iz_.d.ts.map
5502
+ //# sourceMappingURL=agent-tool-types-OhWqAbCp.d.ts.map
@@ -24,7 +24,7 @@ import {
24
24
  w as RunAgentToolOptions,
25
25
  x as ChatCapableAgentClass,
26
26
  y as AgentToolStoredChunk
27
- } from "./agent-tool-types-CNyE1iz_.js";
27
+ } from "./agent-tool-types-OhWqAbCp.js";
28
28
  export {
29
29
  AGENT_TOOL_MILESTONE_PART,
30
30
  AGENT_TOOL_PROGRESS_PART,
@@ -4,7 +4,7 @@ import {
4
4
  o as AgentToolEventMessage,
5
5
  s as AgentToolEventState,
6
6
  y as AgentToolStoredChunk
7
- } from "./agent-tool-types-CNyE1iz_.js";
7
+ } from "./agent-tool-types-OhWqAbCp.js";
8
8
 
9
9
  //#region src/chat/agent-tools.d.ts
10
10
  type AgentToolProgressEmitResult = "emitted" | "coalesced" | "inactive";
@@ -130,4 +130,4 @@ export {
130
130
  interceptAgentToolBroadcast as s,
131
131
  AgentToolBroadcastHooks as t
132
132
  };
133
- //# sourceMappingURL=agent-tools-BeOheFBK.d.ts.map
133
+ //# sourceMappingURL=agent-tools-LdNKGZT9.d.ts.map
@@ -19,7 +19,7 @@ import {
19
19
  w as RunAgentToolOptions,
20
20
  x as ChatCapableAgentClass,
21
21
  y as AgentToolStoredChunk
22
- } from "./agent-tool-types-CNyE1iz_.js";
22
+ } from "./agent-tool-types-OhWqAbCp.js";
23
23
  import { Tool } from "ai";
24
24
 
25
25
  //#region src/agent-tools.d.ts
@@ -4,7 +4,7 @@ import {
4
4
  a as AgentToolEvent,
5
5
  o as AgentToolEventMessage,
6
6
  s as AgentToolEventState
7
- } from "../agent-tool-types-CNyE1iz_.js";
7
+ } from "../agent-tool-types-OhWqAbCp.js";
8
8
  import {
9
9
  n as ClientToolSchema,
10
10
  r as createToolsFromClientSchemas,
@@ -18,7 +18,7 @@ import {
18
18
  r as AgentToolProgressEmitResult,
19
19
  s as interceptAgentToolBroadcast,
20
20
  t as AgentToolBroadcastHooks
21
- } from "../agent-tools-BeOheFBK.js";
21
+ } from "../agent-tools-LdNKGZT9.js";
22
22
  import { JSONSchema7, UIMessage } from "ai";
23
23
  import { Connection } from "agents";
24
24
 
@@ -2,7 +2,7 @@ import {
2
2
  O as Agent,
3
3
  ct as SubAgentClass,
4
4
  lt as SubAgentStub
5
- } from "../agent-tool-types-CNyE1iz_.js";
5
+ } from "../agent-tool-types-OhWqAbCp.js";
6
6
  import { Lock, QueueEntry, StateAdapter } from "chat";
7
7
 
8
8
  //#region src/chat-sdk/agent.d.ts