agents 0.0.0-cec3cca → 0.0.0-cf3b3d7

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 (33) hide show
  1. package/dist/ai-chat-agent.d.ts +3 -3
  2. package/dist/ai-chat-agent.js +3 -3
  3. package/dist/ai-chat-agent.js.map +1 -1
  4. package/dist/ai-react.d.ts +4 -4
  5. package/dist/ai-react.js +8 -3
  6. package/dist/ai-react.js.map +1 -1
  7. package/dist/{client-Csp_m13H.d.ts → client-BaCHMay9.d.ts} +191 -79
  8. package/dist/{client-9Ld2_lnt.js → client-DpkZyXgJ.js} +239 -124
  9. package/dist/client-DpkZyXgJ.js.map +1 -0
  10. package/dist/codemode/ai.js +3 -3
  11. package/dist/do-oauth-client-provider-CnbnngL2.d.ts +134 -0
  12. package/dist/{do-oauth-client-provider-CswoD5Lu.js → do-oauth-client-provider-D2P1lSft.js} +2 -2
  13. package/dist/do-oauth-client-provider-D2P1lSft.js.map +1 -0
  14. package/dist/{index-DFqsR7mb.d.ts → index-DCRAdW9R.d.ts} +30 -18
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +3 -3
  17. package/dist/mcp/client.d.ts +3 -3
  18. package/dist/mcp/client.js +2 -1
  19. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  20. package/dist/mcp/do-oauth-client-provider.js +1 -1
  21. package/dist/mcp/index.d.ts +68 -29
  22. package/dist/mcp/index.js +80 -10
  23. package/dist/mcp/index.js.map +1 -1
  24. package/dist/observability/index.js +3 -3
  25. package/dist/{react-NCPvtyCY.d.ts → react-DM_FD53F.d.ts} +31 -33
  26. package/dist/react.d.ts +4 -4
  27. package/dist/{src-Dz0H9hSU.js → src-Dk8lwxHf.js} +181 -138
  28. package/dist/src-Dk8lwxHf.js.map +1 -0
  29. package/package.json +46 -38
  30. package/dist/client-9Ld2_lnt.js.map +0 -1
  31. package/dist/do-oauth-client-provider-CswoD5Lu.js.map +0 -1
  32. package/dist/do-oauth-client-provider-DGc5pP0l.d.ts +0 -55
  33. package/dist/src-Dz0H9hSU.js.map +0 -1
@@ -1,6 +1,18 @@
1
1
  import { t as MCPObservabilityEvent } from "./mcp-Dw5vDrY8.js";
2
- import { t as AgentsOAuthProvider } from "./do-oauth-client-provider-DGc5pP0l.js";
2
+ import {
3
+ i as MCPServerRow,
4
+ r as MCPClientStorage,
5
+ t as AgentsOAuthProvider
6
+ } from "./do-oauth-client-provider-CnbnngL2.js";
3
7
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
8
+ import {
9
+ SSEClientTransport,
10
+ SSEClientTransportOptions
11
+ } from "@modelcontextprotocol/sdk/client/sse.js";
12
+ import {
13
+ StreamableHTTPClientTransport,
14
+ StreamableHTTPClientTransportOptions
15
+ } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
4
16
  import {
5
17
  CallToolRequest,
6
18
  CallToolResultSchema,
@@ -15,14 +27,6 @@ import {
15
27
  ServerCapabilities,
16
28
  Tool
17
29
  } from "@modelcontextprotocol/sdk/types.js";
18
- import {
19
- SSEClientTransport,
20
- SSEClientTransportOptions
21
- } from "@modelcontextprotocol/sdk/client/sse.js";
22
- import {
23
- StreamableHTTPClientTransport,
24
- StreamableHTTPClientTransportOptions
25
- } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
26
30
  import * as ai0 from "ai";
27
31
  import { ToolSet } from "ai";
28
32
  import * as zod0 from "zod";
@@ -32,40 +36,10 @@ import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
32
36
  interface Disposable {
33
37
  dispose(): void;
34
38
  }
35
- type Event<T$1> = (listener: (e: T$1) => void) => Disposable;
36
- //#endregion
37
- //#region src/mcp/sse-edge.d.ts
38
- declare class SSEEdgeClientTransport extends SSEClientTransport {
39
- private authProvider;
40
- /**
41
- * Creates a new EdgeSSEClientTransport, which overrides fetch to be compatible with the CF workers environment
42
- */
43
- constructor(url: URL, options: SSEClientTransportOptions);
44
- authHeaders(): Promise<
45
- | {
46
- Authorization: string;
47
- }
48
- | undefined
49
- >;
50
- }
51
- //#endregion
52
- //#region src/mcp/streamable-http-edge.d.ts
53
- declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
54
- private authProvider;
55
- /**
56
- * Creates a new StreamableHTTPEdgeClientTransport, which overrides fetch to be compatible with the CF workers environment
57
- */
58
- constructor(url: URL, options: StreamableHTTPClientTransportOptions);
59
- authHeaders(): Promise<
60
- | {
61
- Authorization: string;
62
- }
63
- | undefined
64
- >;
65
- }
39
+ type Event<T> = (listener: (e: T) => void) => Disposable;
66
40
  //#endregion
67
41
  //#region src/mcp/types.d.ts
68
- type MaybePromise<T$1> = T$1 | Promise<T$1>;
42
+ type MaybePromise<T> = T | Promise<T>;
69
43
  type BaseTransportType = "sse" | "streamable-http";
70
44
  type TransportType = BaseTransportType | "auto";
71
45
  interface CORSOptions {
@@ -84,13 +58,43 @@ interface ServeOptions {
84
58
  //#endregion
85
59
  //#region src/mcp/client-connection.d.ts
86
60
  /**
87
- * Connection state for MCP client connections
61
+ * Connection state machine for MCP client connections.
62
+ *
63
+ * State transitions:
64
+ * - Non-OAuth: init() → "connecting" → "discovering" → "ready"
65
+ * - OAuth: init() → "authenticating" → (callback) → "connecting" → "discovering" → "ready"
66
+ * - Any state can transition to "failed" on error
88
67
  */
89
68
  type MCPConnectionState =
69
+ /**
70
+ * Waiting for OAuth authorization to complete.
71
+ * Server requires OAuth and user must complete the authorization flow.
72
+ * Next state: "connecting" (after handleCallbackRequest + establishConnection)
73
+ */
90
74
  | "authenticating"
75
+ /**
76
+ * Establishing transport connection to MCP server.
77
+ * OAuth (if required) is complete, now connecting to the actual MCP endpoint.
78
+ * Next state: "discovering" (after transport connected)
79
+ */
91
80
  | "connecting"
81
+ /**
82
+ * Fully connected and ready to use.
83
+ * Tools, resources, and prompts have been discovered and registered.
84
+ * This is the terminal success state.
85
+ */
92
86
  | "ready"
87
+ /**
88
+ * Discovering server capabilities (tools, resources, prompts).
89
+ * Transport is connected, now fetching available capabilities via MCP protocol.
90
+ * Next state: "ready" (after capabilities fetched)
91
+ */
93
92
  | "discovering"
93
+ /**
94
+ * Connection failed at some point.
95
+ * Check observability events for error details.
96
+ * This is a terminal error state.
97
+ */
94
98
  | "failed";
95
99
  type MCPTransportOptions = (
96
100
  | SSEClientTransportOptions
@@ -295,12 +299,51 @@ declare class MCPClientConnection {
295
299
  */
296
300
  getTransport(
297
301
  transportType: BaseTransportType
298
- ): StreamableHTTPEdgeClientTransport | SSEEdgeClientTransport;
302
+ ): StreamableHTTPClientTransport | SSEClientTransport;
299
303
  private tryConnect;
300
304
  private _capabilityErrorHandler;
301
305
  }
302
306
  //#endregion
303
307
  //#region src/mcp/client.d.ts
308
+ /**
309
+ * Options that can be stored in the server_options column
310
+ * This is what gets JSON.stringify'd and stored in the database
311
+ */
312
+ type MCPServerOptions = {
313
+ client?: ConstructorParameters<typeof Client>[1];
314
+ transport?: {
315
+ headers?: HeadersInit;
316
+ type?: TransportType;
317
+ };
318
+ };
319
+ /**
320
+ * Options for registering an MCP server
321
+ */
322
+ type RegisterServerOptions = {
323
+ url: string;
324
+ name: string;
325
+ callbackUrl: string;
326
+ client?: ConstructorParameters<typeof Client>[1];
327
+ transport?: MCPTransportOptions;
328
+ authUrl?: string;
329
+ clientId?: string;
330
+ };
331
+ /**
332
+ * Result of attempting to connect to an MCP server.
333
+ * Returns the current connection state after the operation.
334
+ *
335
+ * - "ready": Connection established and ready to use (non-OAuth)
336
+ * - "authenticating": OAuth required, user must visit authUrl to authorize
337
+ */
338
+ type MCPConnectionResult =
339
+ | {
340
+ state: "ready";
341
+ }
342
+ | {
343
+ state: "authenticating";
344
+ authUrl: string;
345
+ clientId?: string;
346
+ };
304
347
  type MCPClientOAuthCallbackConfig = {
305
348
  successRedirect?: string;
306
349
  errorRedirect?: string;
@@ -311,6 +354,9 @@ type MCPClientOAuthResult = {
311
354
  authSuccess: boolean;
312
355
  authError?: string;
313
356
  };
357
+ type MCPClientManagerOptions = {
358
+ storage: MCPClientStorage;
359
+ };
314
360
  /**
315
361
  * Utility class that aggregates multiple MCP clients into one
316
362
  */
@@ -318,27 +364,51 @@ declare class MCPClientManager {
318
364
  private _name;
319
365
  private _version;
320
366
  mcpConnections: Record<string, MCPClientConnection>;
321
- private _callbackUrls;
322
367
  private _didWarnAboutUnstableGetAITools;
323
368
  private _oauthCallbackConfig?;
324
369
  private _connectionDisposables;
370
+ private _storage;
371
+ private _isRestored;
325
372
  private readonly _onObservabilityEvent;
326
373
  readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
327
- private readonly _onConnected;
328
- readonly onConnected: Event<string>;
374
+ private readonly _onServerStateChanged;
375
+ /**
376
+ * Event that fires whenever any MCP server state changes (registered, connected, removed, etc.)
377
+ * This is useful for broadcasting server state to clients.
378
+ */
379
+ readonly onServerStateChanged: Event<void>;
329
380
  /**
330
381
  * @param _name Name of the MCP client
331
382
  * @param _version Version of the MCP Client
332
- * @param auth Auth paramters if being used to create a DurableObjectOAuthClientProvider
383
+ * @param options Storage adapter for persisting MCP server state
333
384
  */
334
- constructor(_name: string, _version: string);
385
+ constructor(
386
+ _name: string,
387
+ _version: string,
388
+ options: MCPClientManagerOptions
389
+ );
335
390
  jsonSchema: typeof ai0.jsonSchema | undefined;
391
+ /**
392
+ * Create an auth provider for a server
393
+ * @internal
394
+ */
395
+ private createAuthProvider;
396
+ /**
397
+ * Restore MCP server connections from storage
398
+ * This method is called on Agent initialization to restore previously connected servers
399
+ *
400
+ * @param clientName Name to use for OAuth client (typically the agent instance name)
401
+ */
402
+ restoreConnectionsFromStorage(clientName: string): Promise<void>;
336
403
  /**
337
404
  * Connect to and register an MCP server
338
405
  *
339
- * @param transportConfig Transport config
340
- * @param clientConfig Client config
341
- * @param capabilities Client capabilities (i.e. if the client supports roots/sampling)
406
+ * @deprecated This method is maintained for backward compatibility.
407
+ * For new code, use registerServer() and connectToServer() separately.
408
+ *
409
+ * @param url Server URL
410
+ * @param options Connection options
411
+ * @returns Object with server ID, auth URL (if OAuth), and client ID (if OAuth)
342
412
  */
343
413
  connect(
344
414
  url: string,
@@ -356,17 +426,47 @@ declare class MCPClientManager {
356
426
  authUrl?: string;
357
427
  clientId?: string;
358
428
  }>;
359
- isCallbackRequest(req: Request): boolean;
429
+ /**
430
+ * Create an in-memory connection object and set up observability
431
+ * Does NOT save to storage - use registerServer() for that
432
+ */
433
+ private createConnection;
434
+ /**
435
+ * Register an MCP server connection without connecting
436
+ * Creates the connection object, sets up observability, and saves to storage
437
+ *
438
+ * @param id Server ID
439
+ * @param options Registration options including URL, name, callback URL, and connection config
440
+ * @returns Server ID
441
+ */
442
+ registerServer(id: string, options: RegisterServerOptions): Promise<string>;
443
+ /**
444
+ * Connect to an already registered MCP server and initialize the connection.
445
+ *
446
+ * For OAuth servers, this returns `{ state: "authenticating", authUrl, clientId? }`
447
+ * without establishing the connection. The user must complete the OAuth flow via
448
+ * the authUrl, which will trigger a callback handled by `handleCallbackRequest()`.
449
+ *
450
+ * For non-OAuth servers, this establishes the connection immediately and returns
451
+ * `{ state: "ready" }`.
452
+ *
453
+ * Updates storage with auth URL and client ID after connection.
454
+ *
455
+ * @param id Server ID (must be registered first via registerServer())
456
+ * @returns Connection result with current state and OAuth info (if applicable)
457
+ */
458
+ connectToServer(id: string): Promise<MCPConnectionResult>;
459
+ isCallbackRequest(req: Request): Promise<boolean>;
360
460
  handleCallbackRequest(req: Request): Promise<
361
461
  | {
362
462
  serverId: string;
363
463
  authSuccess: boolean;
364
- authError?: undefined;
464
+ authError: string;
365
465
  }
366
466
  | {
367
467
  serverId: string;
368
468
  authSuccess: boolean;
369
- authError: string;
469
+ authError?: undefined;
370
470
  }
371
471
  >;
372
472
  /**
@@ -375,16 +475,6 @@ declare class MCPClientManager {
375
475
  * @param serverId The server ID to establish connection for
376
476
  */
377
477
  establishConnection(serverId: string): Promise<void>;
378
- /**
379
- * Register a callback URL for OAuth handling
380
- * @param url The callback URL to register
381
- */
382
- registerCallbackUrl(url: string): void;
383
- /**
384
- * Unregister a callback URL
385
- * @param serverId The server ID whose callback URL should be removed
386
- */
387
- unregisterCallbackUrl(serverId: string): void;
388
478
  /**
389
479
  * Configure OAuth callback handling
390
480
  * @param config OAuth callback configuration
@@ -399,6 +489,18 @@ declare class MCPClientManager {
399
489
  * @returns namespaced list of tools
400
490
  */
401
491
  listTools(): NamespacedData["tools"];
492
+ /**
493
+ * Lazy-loads the jsonSchema function from the AI SDK.
494
+ *
495
+ * This defers importing the "ai" package until it's actually needed, which helps reduce
496
+ * initial bundle size and startup time. The jsonSchema function is required for converting
497
+ * MCP tools into AI SDK tool definitions via getAITools().
498
+ *
499
+ * @internal This method is for internal use only. It's automatically called before operations
500
+ * that need jsonSchema (like getAITools() or OAuth flows). External consumers should not need
501
+ * to call this directly.
502
+ */
503
+ ensureJsonSchema(): Promise<void>;
402
504
  /**
403
505
  * @returns a set of tools that you can use with the AI SDK
404
506
  */
@@ -417,6 +519,14 @@ declare class MCPClientManager {
417
519
  * @param id The id of the connection to close
418
520
  */
419
521
  closeConnection(id: string): Promise<void>;
522
+ /**
523
+ * Remove an MCP server from storage
524
+ */
525
+ removeServer(serverId: string): Promise<void>;
526
+ /**
527
+ * List all MCP servers from storage
528
+ */
529
+ listServers(): Promise<MCPServerRow[]>;
420
530
  /**
421
531
  * Dispose the manager and all resources.
422
532
  */
@@ -5293,23 +5403,25 @@ type NamespacedData = {
5293
5403
  serverId: string;
5294
5404
  })[];
5295
5405
  };
5296
- declare function getNamespacedData<T$1 extends keyof NamespacedData>(
5406
+ declare function getNamespacedData<T extends keyof NamespacedData>(
5297
5407
  mcpClients: Record<string, MCPClientConnection>,
5298
- type: T$1
5299
- ): NamespacedData[T$1];
5408
+ type: T
5409
+ ): NamespacedData[T];
5300
5410
  //#endregion
5301
5411
  export {
5302
- MCPConnectionState as a,
5303
- MaybePromise as c,
5304
- StreamableHTTPEdgeClientTransport as d,
5305
- SSEEdgeClientTransport as f,
5306
- getNamespacedData as i,
5307
- ServeOptions as l,
5308
- MCPClientOAuthCallbackConfig as n,
5309
- BaseTransportType as o,
5310
- MCPClientOAuthResult as r,
5311
- CORSOptions as s,
5412
+ MCPConnectionResult as a,
5413
+ getNamespacedData as c,
5414
+ CORSOptions as d,
5415
+ MaybePromise as f,
5416
+ MCPClientOAuthResult as i,
5417
+ MCPConnectionState as l,
5418
+ TransportType as m,
5419
+ MCPClientManagerOptions as n,
5420
+ MCPServerOptions as o,
5421
+ ServeOptions as p,
5422
+ MCPClientOAuthCallbackConfig as r,
5423
+ RegisterServerOptions as s,
5312
5424
  MCPClientManager as t,
5313
- TransportType as u
5425
+ BaseTransportType as u
5314
5426
  };
5315
- //# sourceMappingURL=client-Csp_m13H.d.ts.map
5427
+ //# sourceMappingURL=client-BaCHMay9.d.ts.map