agents 0.0.0-ed3f94d → 0.0.0-edd3357

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 (60) hide show
  1. package/dist/ai-chat-agent.d.ts +1 -2
  2. package/dist/ai-chat-agent.js +57 -350
  3. package/dist/ai-chat-agent.js.map +1 -1
  4. package/dist/ai-chat-v5-migration.js +0 -1
  5. package/dist/ai-react.d.ts +1 -8
  6. package/dist/ai-react.js +111 -157
  7. package/dist/ai-react.js.map +1 -1
  8. package/dist/ai-types.d.ts +0 -1
  9. package/dist/ai-types.js +1 -2
  10. package/dist/{chunk-BER7KXUJ.js → chunk-AVYJQSLW.js} +1 -2
  11. package/dist/chunk-AVYJQSLW.js.map +1 -0
  12. package/dist/{chunk-Z44WASMA.js → chunk-LL2AFX7V.js} +2 -7
  13. package/dist/{chunk-Z44WASMA.js.map → chunk-LL2AFX7V.js.map} +1 -1
  14. package/dist/{chunk-3OT2NNEW.js → chunk-MH46VMM4.js} +67 -396
  15. package/dist/chunk-MH46VMM4.js.map +1 -0
  16. package/dist/{chunk-254F4GDT.js → chunk-YDUDMOL6.js} +50 -97
  17. package/dist/chunk-YDUDMOL6.js.map +1 -0
  18. package/dist/{client-DVoPb3-C.d.ts → client-CvaJdLQA.d.ts} +26 -131
  19. package/dist/client.js +1 -2
  20. package/dist/index.d.ts +32 -25
  21. package/dist/index.js +4 -5
  22. package/dist/mcp/client.d.ts +1 -2
  23. package/dist/mcp/client.js +1 -2
  24. package/dist/mcp/do-oauth-client-provider.js +1 -2
  25. package/dist/mcp/index.d.ts +31 -13
  26. package/dist/mcp/index.js +163 -233
  27. package/dist/mcp/index.js.map +1 -1
  28. package/dist/observability/index.d.ts +24 -12
  29. package/dist/observability/index.js +4 -5
  30. package/dist/react.d.ts +6 -10
  31. package/dist/react.js +3 -101
  32. package/dist/react.js.map +1 -1
  33. package/dist/schedule.js +0 -2
  34. package/dist/schedule.js.map +1 -1
  35. package/package.json +6 -19
  36. package/src/index.ts +57 -141
  37. package/dist/_esm-LV5FJ3HK.js +0 -3922
  38. package/dist/_esm-LV5FJ3HK.js.map +0 -1
  39. package/dist/ccip-CMBYN64O.js +0 -15
  40. package/dist/ccip-CMBYN64O.js.map +0 -1
  41. package/dist/chunk-254F4GDT.js.map +0 -1
  42. package/dist/chunk-3OT2NNEW.js.map +0 -1
  43. package/dist/chunk-5Y6BEZDY.js +0 -276
  44. package/dist/chunk-5Y6BEZDY.js.map +0 -1
  45. package/dist/chunk-BER7KXUJ.js.map +0 -1
  46. package/dist/chunk-JJBFIGUC.js +0 -5202
  47. package/dist/chunk-JJBFIGUC.js.map +0 -1
  48. package/dist/chunk-PR4QN5HX.js +0 -43
  49. package/dist/chunk-PR4QN5HX.js.map +0 -1
  50. package/dist/chunk-TYAY6AU6.js +0 -159
  51. package/dist/chunk-TYAY6AU6.js.map +0 -1
  52. package/dist/codemode/ai.d.ts +0 -25
  53. package/dist/codemode/ai.js +0 -5112
  54. package/dist/codemode/ai.js.map +0 -1
  55. package/dist/mcp/x402.d.ts +0 -39
  56. package/dist/mcp/x402.js +0 -3195
  57. package/dist/mcp/x402.js.map +0 -1
  58. package/dist/mcp-BH1fJeiU.d.ts +0 -58
  59. package/dist/secp256k1-M22GZP2U.js +0 -2193
  60. package/dist/secp256k1-M22GZP2U.js.map +0 -1
@@ -16,7 +16,6 @@ import {
16
16
  GetPromptRequest
17
17
  } from "@modelcontextprotocol/sdk/types.js";
18
18
  import { ToolSet } from "ai";
19
- import { M as MCPObservabilityEvent } from "./mcp-BH1fJeiU.js";
20
19
  import {
21
20
  SSEClientTransport,
22
21
  SSEClientTransportOptions
@@ -27,11 +26,6 @@ import {
27
26
  } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
28
27
  import { AgentsOAuthProvider } from "./mcp/do-oauth-client-provider.js";
29
28
 
30
- interface Disposable {
31
- dispose(): void;
32
- }
33
- type Event<T> = (listener: (e: T) => void) => Disposable;
34
-
35
29
  declare class SSEEdgeClientTransport extends SSEClientTransport {
36
30
  private authProvider;
37
31
  /**
@@ -60,38 +54,14 @@ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTran
60
54
  >;
61
55
  }
62
56
 
63
- type MaybePromise<T> = T | Promise<T>;
64
- type BaseTransportType = "sse" | "streamable-http";
65
- type TransportType = BaseTransportType | "auto";
66
- interface CORSOptions {
67
- origin?: string;
68
- methods?: string;
69
- headers?: string;
70
- maxAge?: number;
71
- exposeHeaders?: string;
72
- }
73
- interface ServeOptions {
74
- binding?: string;
75
- corsOptions?: CORSOptions;
76
- transport?: BaseTransportType;
77
- }
78
-
79
- /**
80
- * Connection state for MCP client connections
81
- */
82
- type MCPConnectionState =
83
- | "authenticating"
84
- | "connecting"
85
- | "ready"
86
- | "discovering"
87
- | "failed";
88
57
  type MCPTransportOptions = (
89
58
  | SSEClientTransportOptions
90
59
  | StreamableHTTPClientTransportOptions
91
60
  ) & {
92
61
  authProvider?: AgentsOAuthProvider;
93
- type?: TransportType;
62
+ type?: "sse" | "streamable-http" | "auto";
94
63
  };
64
+ type TransportType = Exclude<MCPTransportOptions["type"], "auto">;
95
65
  declare class MCPClientConnection {
96
66
  url: URL;
97
67
  options: {
@@ -99,16 +69,18 @@ declare class MCPClientConnection {
99
69
  client: ConstructorParameters<typeof Client>[1];
100
70
  };
101
71
  client: Client;
102
- connectionState: MCPConnectionState;
103
- lastConnectedTransport: BaseTransportType | undefined;
72
+ connectionState:
73
+ | "authenticating"
74
+ | "connecting"
75
+ | "ready"
76
+ | "discovering"
77
+ | "failed";
104
78
  instructions?: string;
105
79
  tools: Tool[];
106
80
  prompts: Prompt[];
107
81
  resources: Resource[];
108
82
  resourceTemplates: ResourceTemplate[];
109
83
  serverCapabilities: ServerCapabilities | undefined;
110
- private readonly _onObservabilityEvent;
111
- readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
112
84
  constructor(
113
85
  url: URL,
114
86
  info: ConstructorParameters<typeof Client>[0],
@@ -120,27 +92,10 @@ declare class MCPClientConnection {
120
92
  /**
121
93
  * Initialize a client connection
122
94
  *
95
+ * @param code Optional OAuth code to initialize the connection with if auth hasn't been initialized
123
96
  * @returns
124
97
  */
125
- init(): Promise<void>;
126
- /**
127
- * Finish OAuth by probing transports based on configured type.
128
- * - Explicit: finish on that transport
129
- * - Auto: try streamable-http, then sse on 404/405/Not Implemented
130
- */
131
- private finishAuthProbe;
132
- /**
133
- * Complete OAuth authorization
134
- */
135
- completeAuthorization(code: string): Promise<void>;
136
- /**
137
- * Establish connection after successful authorization
138
- */
139
- establishConnection(): Promise<void>;
140
- /**
141
- * Discover server capabilities and register tools, resources, prompts, and templates
142
- */
143
- private discoverAndRegister;
98
+ init(code?: string): Promise<void>;
144
99
  /**
145
100
  * Notification handler registration
146
101
  */
@@ -175,12 +130,12 @@ declare class MCPClientConnection {
175
130
  }
176
131
  | undefined;
177
132
  description?: string | undefined;
178
- title?: string | undefined;
179
133
  _meta?:
180
134
  | {
181
135
  [x: string]: unknown;
182
136
  }
183
137
  | undefined;
138
+ title?: string | undefined;
184
139
  annotations?:
185
140
  | {
186
141
  [x: string]: unknown;
@@ -207,12 +162,12 @@ declare class MCPClientConnection {
207
162
  name: string;
208
163
  uri: string;
209
164
  description?: string | undefined;
210
- title?: string | undefined;
211
165
  _meta?:
212
166
  | {
213
167
  [x: string]: unknown;
214
168
  }
215
169
  | undefined;
170
+ title?: string | undefined;
216
171
  icons?:
217
172
  | {
218
173
  [x: string]: unknown;
@@ -229,12 +184,12 @@ declare class MCPClientConnection {
229
184
  [x: string]: unknown;
230
185
  name: string;
231
186
  description?: string | undefined;
232
- title?: string | undefined;
233
187
  _meta?:
234
188
  | {
235
189
  [x: string]: unknown;
236
190
  }
237
191
  | undefined;
192
+ title?: string | undefined;
238
193
  icons?:
239
194
  | {
240
195
  [x: string]: unknown;
@@ -259,12 +214,12 @@ declare class MCPClientConnection {
259
214
  name: string;
260
215
  uriTemplate: string;
261
216
  description?: string | undefined;
262
- title?: string | undefined;
263
217
  _meta?:
264
218
  | {
265
219
  [x: string]: unknown;
266
220
  }
267
221
  | undefined;
222
+ title?: string | undefined;
268
223
  mimeType?: string | undefined;
269
224
  }[]
270
225
  >;
@@ -279,22 +234,14 @@ declare class MCPClientConnection {
279
234
  * @returns The transport for the client
280
235
  */
281
236
  getTransport(
282
- transportType: BaseTransportType
237
+ transportType: TransportType
283
238
  ): SSEEdgeClientTransport | StreamableHTTPEdgeClientTransport;
284
- private tryConnect;
285
- private _capabilityErrorHandler;
239
+ tryConnect(
240
+ transportType: MCPTransportOptions["type"],
241
+ code?: string
242
+ ): Promise<void>;
286
243
  }
287
244
 
288
- type MCPClientOAuthCallbackConfig = {
289
- successRedirect?: string;
290
- errorRedirect?: string;
291
- customHandler?: (result: MCPClientOAuthResult) => Response;
292
- };
293
- type MCPClientOAuthResult = {
294
- serverId: string;
295
- authSuccess: boolean;
296
- authError?: string;
297
- };
298
245
  /**
299
246
  * Utility class that aggregates multiple MCP clients into one
300
247
  */
@@ -304,12 +251,6 @@ declare class MCPClientManager {
304
251
  mcpConnections: Record<string, MCPClientConnection>;
305
252
  private _callbackUrls;
306
253
  private _didWarnAboutUnstableGetAITools;
307
- private _oauthCallbackConfig?;
308
- private _connectionDisposables;
309
- private readonly _onObservabilityEvent;
310
- readonly onObservabilityEvent: Event<MCPObservabilityEvent>;
311
- private readonly _onConnected;
312
- readonly onConnected: Event<string>;
313
254
  /**
314
255
  * @param _name Name of the MCP client
315
256
  * @param _version Version of the MCP Client
@@ -340,44 +281,9 @@ declare class MCPClientManager {
340
281
  clientId?: string;
341
282
  }>;
342
283
  isCallbackRequest(req: Request): boolean;
343
- handleCallbackRequest(req: Request): Promise<
344
- | {
345
- serverId: string;
346
- authSuccess: boolean;
347
- authError?: undefined;
348
- }
349
- | {
350
- serverId: string;
351
- authSuccess: boolean;
352
- authError: string;
353
- }
354
- >;
355
- /**
356
- * Establish connection in the background after OAuth completion
357
- * This method is called asynchronously and doesn't block the OAuth callback response
358
- * @param serverId The server ID to establish connection for
359
- */
360
- establishConnection(serverId: string): Promise<void>;
361
- /**
362
- * Register a callback URL for OAuth handling
363
- * @param url The callback URL to register
364
- */
365
- registerCallbackUrl(url: string): void;
366
- /**
367
- * Unregister a callback URL
368
- * @param serverId The server ID whose callback URL should be removed
369
- */
370
- unregisterCallbackUrl(serverId: string): void;
371
- /**
372
- * Configure OAuth callback handling
373
- * @param config OAuth callback configuration
374
- */
375
- configureOAuthCallback(config: MCPClientOAuthCallbackConfig): void;
376
- /**
377
- * Get the current OAuth callback configuration
378
- * @returns The current OAuth callback configuration
379
- */
380
- getOAuthCallbackConfig(): MCPClientOAuthCallbackConfig | undefined;
284
+ handleCallbackRequest(req: Request): Promise<{
285
+ serverId: string;
286
+ }>;
381
287
  /**
382
288
  * @returns namespaced list of tools
383
289
  */
@@ -394,16 +300,12 @@ declare class MCPClientManager {
394
300
  /**
395
301
  * Closes all connections to MCP servers
396
302
  */
397
- closeAllConnections(): Promise<void>;
303
+ closeAllConnections(): Promise<void[]>;
398
304
  /**
399
305
  * Closes a connection to an MCP server
400
306
  * @param id The id of the connection to close
401
307
  */
402
308
  closeConnection(id: string): Promise<void>;
403
- /**
404
- * Dispose the manager and all resources.
405
- */
406
- dispose(): Promise<void>;
407
309
  /**
408
310
  * @returns namespaced list of prompts
409
311
  */
@@ -5106,15 +5008,8 @@ declare function getNamespacedData<T extends keyof NamespacedData>(
5106
5008
  ): NamespacedData[T];
5107
5009
 
5108
5010
  export {
5109
- type BaseTransportType as B,
5110
- type MaybePromise as M,
5111
- type ServeOptions as S,
5112
- type TransportType as T,
5113
- SSEEdgeClientTransport as a,
5114
- StreamableHTTPEdgeClientTransport as b,
5115
- type MCPClientOAuthResult as c,
5116
- type MCPClientOAuthCallbackConfig as d,
5117
- MCPClientManager as e,
5118
- type MCPConnectionState as f,
5011
+ MCPClientManager as M,
5012
+ SSEEdgeClientTransport as S,
5013
+ StreamableHTTPEdgeClientTransport as a,
5119
5014
  getNamespacedData as g
5120
5015
  };
package/dist/client.js CHANGED
@@ -3,8 +3,7 @@ import {
3
3
  agentFetch,
4
4
  camelCaseToKebabCase
5
5
  } from "./chunk-QEVM4BVL.js";
6
- import "./chunk-BER7KXUJ.js";
7
- import "./chunk-PR4QN5HX.js";
6
+ import "./chunk-AVYJQSLW.js";
8
7
  export {
9
8
  AgentClient,
10
9
  agentFetch,
package/dist/index.d.ts CHANGED
@@ -8,17 +8,12 @@ import {
8
8
  } from "@modelcontextprotocol/sdk/types.js";
9
9
  import { Server, Connection, PartyServerOptions } from "partyserver";
10
10
  export { Connection, ConnectionContext, WSMessage } from "partyserver";
11
- import {
12
- e as MCPClientManager,
13
- T as TransportType,
14
- f as MCPConnectionState
15
- } from "./client-DVoPb3-C.js";
11
+ import { M as MCPClientManager } from "./client-CvaJdLQA.js";
16
12
  import { Observability } from "./observability/index.js";
17
13
  import { MessageType } from "./ai-types.js";
18
14
  import "zod";
19
15
  import "@modelcontextprotocol/sdk/shared/protocol.js";
20
16
  import "ai";
21
- import "./mcp-BH1fJeiU.js";
22
17
  import "@modelcontextprotocol/sdk/client/sse.js";
23
18
  import "@modelcontextprotocol/sdk/client/streamableHttp.js";
24
19
  import "./mcp/do-oauth-client-provider.js";
@@ -129,7 +124,6 @@ type Schedule<T = string> = {
129
124
  cron: string;
130
125
  }
131
126
  );
132
-
133
127
  /**
134
128
  * MCP Server state update message from server -> Client
135
129
  */
@@ -149,7 +143,7 @@ type MCPServer = {
149
143
  name: string;
150
144
  server_url: string;
151
145
  auth_url: string | null;
152
- state: MCPConnectionState;
146
+ state: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
153
147
  instructions: string | null;
154
148
  capabilities: ServerCapabilities | null;
155
149
  };
@@ -172,9 +166,8 @@ declare class Agent<
172
166
  Props extends Record<string, unknown> = Record<string, unknown>
173
167
  > extends Server<Env, Props> {
174
168
  private _state;
175
- private _disposables;
176
169
  private _ParentClass;
177
- readonly mcp: MCPClientManager;
170
+ mcp: MCPClientManager;
178
171
  /**
179
172
  * Initial state for the Agent
180
173
  * Override to provide default state values
@@ -351,40 +344,55 @@ declare class Agent<
351
344
  /**
352
345
  * Connect to a new MCP Server
353
346
  *
354
- * @param serverName Name of the MCP server
355
347
  * @param url MCP Server SSE URL
356
- * @param callbackHost Base host for the agent, used for the redirect URI. If not provided, will be derived from the current request.
348
+ * @param callbackHost Base host for the agent, used for the redirect URI.
357
349
  * @param agentsPrefix agents routing prefix if not using `agents`
358
- * @param options MCP client and transport options
350
+ * @param options MCP client and transport (header) options
359
351
  * @returns authUrl
360
352
  */
361
353
  addMcpServer(
362
354
  serverName: string,
363
355
  url: string,
364
- callbackHost?: string,
356
+ callbackHost: string,
365
357
  agentsPrefix?: string,
366
358
  options?: {
367
359
  client?: ConstructorParameters<typeof Client>[1];
360
+ transport?: {
361
+ headers: HeadersInit;
362
+ };
363
+ }
364
+ ): Promise<{
365
+ id: string;
366
+ authUrl: string | undefined;
367
+ }>;
368
+ _connectToMcpServerInternal(
369
+ _serverName: string,
370
+ url: string,
371
+ callbackUrl: string,
372
+ options?: {
373
+ client?: ConstructorParameters<typeof Client>[1];
374
+ /**
375
+ * We don't expose the normal set of transport options because:
376
+ * 1) we can't serialize things like the auth provider or a fetch function into the DB for reconnection purposes
377
+ * 2) We probably want these options to be agnostic to the transport type (SSE vs Streamable)
378
+ *
379
+ * This has the limitation that you can't override fetch, but I think headers should handle nearly all cases needed (i.e. non-standard bearer auth).
380
+ */
368
381
  transport?: {
369
382
  headers?: HeadersInit;
370
- type?: TransportType;
371
383
  };
384
+ },
385
+ reconnect?: {
386
+ id: string;
387
+ oauthClientId?: string;
372
388
  }
373
389
  ): Promise<{
374
390
  id: string;
375
391
  authUrl: string | undefined;
392
+ clientId: string | undefined;
376
393
  }>;
377
- private _connectToMcpServerInternal;
378
394
  removeMcpServer(id: string): Promise<void>;
379
395
  getMcpServers(): MCPServersState;
380
- private broadcastMcpServers;
381
- /**
382
- * Handle OAuth callback response using MCPClientManager configuration
383
- * @param result OAuth callback result
384
- * @param request The original request (needed for base URL)
385
- * @returns Response for the OAuth callback
386
- */
387
- private handleOAuthCallbackResponse;
388
396
  }
389
397
  /**
390
398
  * Namespace for creating Agent instances
@@ -544,7 +552,6 @@ export {
544
552
  type Schedule,
545
553
  type StateUpdateMessage,
546
554
  StreamingResponse,
547
- TransportType,
548
555
  callable,
549
556
  createAddressBasedEmailResolver,
550
557
  createCatchAllEmailResolver,
package/dist/index.js CHANGED
@@ -10,12 +10,11 @@ import {
10
10
  routeAgentEmail,
11
11
  routeAgentRequest,
12
12
  unstable_callable
13
- } from "./chunk-254F4GDT.js";
14
- import "./chunk-3OT2NNEW.js";
15
- import "./chunk-Z44WASMA.js";
13
+ } from "./chunk-YDUDMOL6.js";
14
+ import "./chunk-MH46VMM4.js";
15
+ import "./chunk-LL2AFX7V.js";
16
16
  import "./chunk-QEVM4BVL.js";
17
- import "./chunk-BER7KXUJ.js";
18
- import "./chunk-PR4QN5HX.js";
17
+ import "./chunk-AVYJQSLW.js";
19
18
  export {
20
19
  Agent,
21
20
  StreamingResponse,
@@ -3,8 +3,7 @@ import '@modelcontextprotocol/sdk/client/index.js';
3
3
  import '@modelcontextprotocol/sdk/shared/protocol.js';
4
4
  import '@modelcontextprotocol/sdk/types.js';
5
5
  import 'ai';
6
- export { e as MCPClientManager, d as MCPClientOAuthCallbackConfig, c as MCPClientOAuthResult, g as getNamespacedData } from '../client-DVoPb3-C.js';
7
- import '../mcp-BH1fJeiU.js';
6
+ export { M as MCPClientManager, g as getNamespacedData } from '../client-CvaJdLQA.js';
8
7
  import '@modelcontextprotocol/sdk/client/sse.js';
9
8
  import '@modelcontextprotocol/sdk/client/streamableHttp.js';
10
9
  import './do-oauth-client-provider.js';
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  MCPClientManager,
3
3
  getNamespacedData
4
- } from "../chunk-3OT2NNEW.js";
5
- import "../chunk-PR4QN5HX.js";
4
+ } from "../chunk-MH46VMM4.js";
6
5
  export {
7
6
  MCPClientManager,
8
7
  getNamespacedData
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  DurableObjectOAuthClientProvider
3
- } from "../chunk-Z44WASMA.js";
4
- import "../chunk-PR4QN5HX.js";
3
+ } from "../chunk-LL2AFX7V.js";
5
4
  export {
6
5
  DurableObjectOAuthClientProvider
7
6
  };
@@ -2,14 +2,12 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
2
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import { JSONRPCMessage, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
4
4
  export { ElicitRequest, ElicitRequestSchema, ElicitResult } from '@modelcontextprotocol/sdk/types.js';
5
- import { Agent } from '../index.js';
6
- import { M as MaybePromise, B as BaseTransportType, S as ServeOptions } from '../client-DVoPb3-C.js';
7
- export { d as MCPClientOAuthCallbackConfig, c as MCPClientOAuthResult, a as SSEEdgeClientTransport, b as StreamableHTTPEdgeClientTransport } from '../client-DVoPb3-C.js';
8
- import { Connection, ConnectionContext } from 'partyserver';
5
+ import { Agent, AgentContext } from '../index.js';
6
+ export { S as SSEEdgeClientTransport, a as StreamableHTTPEdgeClientTransport } from '../client-CvaJdLQA.js';
7
+ import { Connection, ConnectionContext, WSMessage } from 'partyserver';
9
8
  import 'cloudflare:workers';
10
9
  import '@modelcontextprotocol/sdk/client/index.js';
11
10
  import '../observability/index.js';
12
- import '../mcp-BH1fJeiU.js';
13
11
  import '../ai-types.js';
14
12
  import 'ai';
15
13
  import 'zod';
@@ -20,34 +18,54 @@ import './do-oauth-client-provider.js';
20
18
  import '@modelcontextprotocol/sdk/client/auth.js';
21
19
  import '@modelcontextprotocol/sdk/shared/auth.js';
22
20
 
21
+ type MaybePromise<T> = T | Promise<T>;
22
+ type TransportType = "sse" | "streamable-http";
23
+ interface CORSOptions {
24
+ origin?: string;
25
+ methods?: string;
26
+ headers?: string;
27
+ maxAge?: number;
28
+ exposeHeaders?: string;
29
+ }
30
+ interface ServeOptions {
31
+ binding?: string;
32
+ corsOptions?: CORSOptions;
33
+ transport?: TransportType;
34
+ }
35
+
23
36
  declare abstract class McpAgent<Env = unknown, State = unknown, Props extends Record<string, unknown> = Record<string, unknown>> extends Agent<Env, State, Props> {
24
37
  private _transport?;
38
+ private _requestIdToConnectionId;
39
+ private _standaloneSseConnectionId?;
25
40
  props?: Props;
26
41
  abstract server: MaybePromise<McpServer | Server>;
27
42
  abstract init(): Promise<void>;
43
+ constructor(ctx: AgentContext, env: Env);
28
44
  setInitializeRequest(initializeRequest: JSONRPCMessage): Promise<void>;
29
45
  getInitializeRequest(): Promise<JSONRPCMessage | undefined>;
30
46
  /** Read the transport type for this agent.
31
47
  * This relies on the naming scheme being `sse:${sessionId}`
32
48
  * or `streamable-http:${sessionId}`.
33
49
  */
34
- getTransportType(): BaseTransportType;
35
- /** Read the sessionId for this agent.
36
- * This relies on the naming scheme being `sse:${sessionId}`
37
- * or `streamable-http:${sessionId}`.
38
- */
39
- getSessionId(): string;
50
+ getTransportType(): TransportType;
51
+ /** Get the WebSocket for the standalone SSE if any. Streamable HTTP only. */
52
+ private getWebSocketForStandaloneSse;
40
53
  /** Get the unique WebSocket. SSE transport only. */
41
54
  private getWebSocket;
55
+ /** Get the corresponding WebSocket for a responseId. Streamable HTTP only. */
56
+ private getWebSocketForResponseID;
42
57
  /** Returns a new transport matching the type of the Agent. */
43
58
  private initTransport;
44
59
  /** Update and store the props */
45
60
  updateProps(props?: Props): Promise<void>;
46
- reinitializeServer(): Promise<void>;
47
61
  /** Sets up the MCP transport and server every time the Agent is started.*/
48
62
  onStart(props?: Props): Promise<void>;
49
63
  /** Validates new WebSocket connections. */
50
- onConnect(conn: Connection, { request: req }: ConnectionContext): Promise<void>;
64
+ onConnect(conn: Connection, _: ConnectionContext): Promise<void>;
65
+ /** Handles MCP Messages for Streamable HTTP. */
66
+ onMessage(connection: Connection, event: WSMessage): Promise<void>;
67
+ /** Remove clients from our cache when they disconnect */
68
+ onClose(conn: Connection, _code: number, _reason: string, _wasClean: boolean): Promise<void>;
51
69
  /** Handles MCP Messages for the legacy SSE transport. */
52
70
  onSSEMcpMessage(_sessionId: string, messageBody: unknown): Promise<Error | null>;
53
71
  /** Elicit user input with a message and schema */