agents 0.30.0 → 0.31.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 (130) hide show
  1. package/README.md +4 -2
  2. package/dist/{agent-routing-CDbpVjYq.d.ts → agent-routing-wS1TimZ_.d.ts} +64 -603
  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-Bamxxb6Y.d.ts} +2 -2
  6. package/dist/agent-tools.d.ts +1 -1
  7. package/dist/{ai-iXw0uOGj.d.ts → ai-CDn3Abax.d.ts} +30 -4
  8. package/dist/{ai-sdk-DRPh2rRa.js → ai-sdk-Kon40i0q.js} +2 -36
  9. package/dist/ai-sdk-Kon40i0q.js.map +1 -0
  10. package/dist/ai-sdk-hW3vntnk.d.ts +72 -0
  11. package/dist/browser/ai.d.ts +1 -1
  12. package/dist/browser/ai.js +16 -3
  13. package/dist/browser/ai.js.map +1 -1
  14. package/dist/browser/index.d.ts +64 -16
  15. package/dist/browser/index.js +4 -4
  16. package/dist/browser/tools/ai-sdk.d.ts +7 -70
  17. package/dist/browser/tools/ai-sdk.js +4 -4
  18. package/dist/browser/tools/ai-sdk.js.map +1 -1
  19. package/dist/browser/tools/pi.d.ts +9 -15
  20. package/dist/browser/tools/pi.js +6 -14
  21. package/dist/browser/tools/pi.js.map +1 -1
  22. package/dist/browser/tools/tanstack-ai.d.ts +46 -23
  23. package/dist/browser/tools/tanstack-ai.js +8 -4
  24. package/dist/browser/tools/tanstack-ai.js.map +1 -1
  25. package/dist/{browser-DccPw_wW.js → browser-1eUbPvC2.js} +413 -14
  26. package/dist/browser-1eUbPvC2.js.map +1 -0
  27. package/dist/{browser-DlXhSAdf.d.ts → browser-D9RNpJuT.d.ts} +254 -20
  28. package/dist/browser-tool-BhjCcNVE.d.ts +71 -0
  29. package/dist/browser-tool-lGnvEBLJ.js +497 -0
  30. package/dist/browser-tool-lGnvEBLJ.js.map +1 -0
  31. package/dist/capability-id-B3J8Nok_.js +13 -0
  32. package/dist/capability-id-B3J8Nok_.js.map +1 -0
  33. package/dist/chat/index.d.ts +2 -2
  34. package/dist/chat-sdk/index.d.ts +3 -3
  35. package/dist/chat-sdk/index.js +1 -1
  36. package/dist/client-4OlMIJx-.js.map +1 -1
  37. package/dist/{client-BnYbNT3z.js → client-DMWujQJ1.js} +68 -244
  38. package/dist/client-DMWujQJ1.js.map +1 -0
  39. package/dist/{client-C27CtRZr.d.ts → client-wn4-yqGz.d.ts} +9 -7
  40. package/dist/client.d.ts +1 -1
  41. package/dist/{connector-DAXBOIIi.js → connector-CM-uuxKM.js} +96 -8
  42. package/dist/connector-CM-uuxKM.js.map +1 -0
  43. package/dist/{connector-20DJ6p4k.d.ts → connector-DZ71EjE-.d.ts} +109 -9
  44. package/dist/experimental/webmcp.js +1 -1
  45. package/dist/{handler-stateless-Bly_nSH3.js → handler-stateless-B5hU3dxK.js} +35 -2
  46. package/dist/handler-stateless-B5hU3dxK.js.map +1 -0
  47. package/dist/{handler-stateless-DxYpJ_XF.d.ts → handler-stateless-C90kD5_R.d.ts} +3 -47
  48. package/dist/harness/container/index.d.ts +15 -15
  49. package/dist/harness/opencode/index.js.map +1 -1
  50. package/dist/harness/pi/index.d.ts +7 -3
  51. package/dist/harness/pi/index.js +46 -15
  52. package/dist/harness/pi/index.js.map +1 -1
  53. package/dist/harness/think/index.d.ts +2 -1
  54. package/dist/{images-xaDv2Fqe.js → images-CfuRCjwq.js} +1 -5
  55. package/dist/images-CfuRCjwq.js.map +1 -0
  56. package/dist/{index-DCxk3OSJ.d.ts → index-8k4qsX1T.d.ts} +2 -28
  57. package/dist/index.d.ts +14 -14
  58. package/dist/index.js +2 -2
  59. package/dist/internal-hosts-Kfp5A392.d.ts +230 -0
  60. package/dist/internal-kmw70xwR.js.map +1 -1
  61. package/dist/invoker-BC1SZ3q1.js +26 -0
  62. package/dist/invoker-BC1SZ3q1.js.map +1 -0
  63. package/dist/invoker-DoLFPJZV.d.ts +21 -0
  64. package/dist/mcp/client/index.d.ts +15 -1
  65. package/dist/mcp/client/index.js +2 -2
  66. package/dist/mcp/client/x402.d.ts +7 -5
  67. package/dist/mcp/client/x402.js +34 -1
  68. package/dist/mcp/client/x402.js.map +1 -1
  69. package/dist/mcp/index.d.ts +561 -27
  70. package/dist/mcp/index.js +180 -3
  71. package/dist/mcp/index.js.map +1 -1
  72. package/dist/mcp/server/index.d.ts +1 -1
  73. package/dist/mcp/server/index.js +1 -1
  74. package/dist/models/ai-sdk/index.d.ts +2 -2
  75. package/dist/models/ai-sdk/index.js +1 -1
  76. package/dist/models/opencode/index.d.ts +2 -2
  77. package/dist/models/opencode/index.js +1 -1
  78. package/dist/models/pi-ai/index.d.ts +3 -28
  79. package/dist/models/pi-ai/index.js +31 -16
  80. package/dist/models/pi-ai/index.js.map +1 -1
  81. package/dist/protocol-BEgrJYC5.d.ts +29 -29
  82. package/dist/react.d.ts +2 -2
  83. package/dist/routing/index.d.ts +1 -1
  84. package/dist/serializable.d.ts +1 -1
  85. package/dist/{session-store-yvwq1f9x.js → session-7CDgVE0z.js} +455 -33
  86. package/dist/session-7CDgVE0z.js.map +1 -0
  87. package/dist/{session-store-_IK6dV-w.d.ts → session-store-B7Ca-u1t.d.ts} +8 -1
  88. package/dist/settings-Dk2il2Hf.js.map +1 -1
  89. package/dist/{src-DfLzdwlK.js → src-BGolXG_H.js} +18 -2
  90. package/dist/src-BGolXG_H.js.map +1 -0
  91. package/dist/sub-routing.d.ts +12 -12
  92. package/dist/tool-CTp72Jb_.d.ts +10 -10
  93. package/dist/tool-DoVberpN.d.ts +22 -22
  94. package/dist/tool-helpers-BodWi4gd.js +256 -0
  95. package/dist/tool-helpers-BodWi4gd.js.map +1 -0
  96. package/dist/{transport-CPh7YGiw.d.ts → transport-5moD2pW5.d.ts} +1 -43
  97. package/dist/types-D2naO3rA.d.ts +49 -0
  98. package/dist/voice/index.d.ts +1 -1
  99. package/dist/workflow-types.d.ts +1 -1
  100. package/dist/workflows.d.ts +1 -1
  101. package/dist/workflows.js +1 -1
  102. package/docs/browse-the-web.md +247 -413
  103. package/docs/get-current-agent.md +4 -7
  104. package/docs/harnesses/pi.md +28 -28
  105. package/docs/human-in-the-loop.md +3 -7
  106. package/docs/index.md +6 -6
  107. package/docs/mcp-client.md +4 -28
  108. package/docs/mcp-servers.md +137 -411
  109. package/docs/mcp-transports.md +30 -289
  110. package/docs/models-pi-ai.md +9 -11
  111. package/docs/models.md +1 -8
  112. package/docs/routing.md +0 -2
  113. package/docs/securing-mcp-servers.md +120 -304
  114. package/package.json +8 -3
  115. package/dist/ai-sdk-DRPh2rRa.js.map +0 -1
  116. package/dist/browser-DccPw_wW.js.map +0 -1
  117. package/dist/browser-tool-B1mhifin.js +0 -616
  118. package/dist/browser-tool-B1mhifin.js.map +0 -1
  119. package/dist/browser-tool-Cxjk5sgG.d.ts +0 -92
  120. package/dist/client-BnYbNT3z.js.map +0 -1
  121. package/dist/connector-DAXBOIIi.js.map +0 -1
  122. package/dist/handler-stateless-Bly_nSH3.js.map +0 -1
  123. package/dist/images-xaDv2Fqe.js.map +0 -1
  124. package/dist/invoker-CG0_p_Wq.d.ts +0 -20
  125. package/dist/invoker-CHMnoxIA.js +0 -57
  126. package/dist/invoker-CHMnoxIA.js.map +0 -1
  127. package/dist/session-store-yvwq1f9x.js.map +0 -1
  128. package/dist/src-DfLzdwlK.js.map +0 -1
  129. package/dist/tool-helpers-O5BDVEAY.js +0 -58
  130. package/dist/tool-helpers-O5BDVEAY.js.map +0 -1
@@ -1,46 +1,579 @@
1
1
  import {
2
- $t as RPCServerTransport,
2
+ S as ConnectionContext,
3
+ x as Connection
4
+ } from "../capability-runner-BiVUtjqC.js";
5
+ import {
6
+ $t as RPCClientTransportOptions,
3
7
  Bt as MCPConnectionResult,
4
8
  Ft as MCPClientElicitationHandlers,
5
9
  Gt as MCP_SERVER_ID_MAX_LENGTH,
6
10
  Jt as normalizeServerId,
7
11
  Pt as MCPClientElicitationHandler,
8
- Qt as RPCClientTransportOptions,
12
+ Qt as RPCClientTransport,
9
13
  Rt as MCPClientOAuthCallbackConfig,
10
14
  Vt as MCPDiscoverResult,
11
15
  Wt as MCPServerOptions,
12
16
  Xt as MCPElicitationHandlers,
13
17
  Yt as MCPElicitationHandler,
14
- Zt as RPCClientTransport,
15
- _n as WorkerTransportOptions,
16
- an as McpAgent,
17
- cn as createMcpHandler,
18
- dn as CreateMcpHandlerOptions,
19
- en as RPCServerTransportOptions,
20
- fn as LegacyMcpHandler,
21
- gn as WorkerTransport,
22
- hn as TransportState,
23
- in as ElicitResult,
24
- ln as experimental_createMcpHandler,
25
- mn as MCPStorageApi,
26
- nn as ElicitRequest,
27
- on as ClearableEventStore,
28
- pn as createLegacyMcpHandler,
29
- rn as ElicitRequestSchema,
30
- sn as DurableObjectEventStore,
31
- tn as RPC_DO_PREFIX,
32
- un as CreateLegacyMcpHandlerOptions,
33
- vn as SSEEdgeClientTransport,
34
- yn as StreamableHTTPEdgeClientTransport,
18
+ c as Agent,
19
+ en as RPC_DO_PREFIX,
35
20
  zt as MCPClientOAuthResult
36
- } from "../agent-routing-CDbpVjYq.js";
21
+ } from "../agent-routing-wS1TimZ_.js";
22
+ import {
23
+ a as ServeOptions,
24
+ i as McpClientOptions,
25
+ n as CORSOptions,
26
+ r as MaybePromise,
27
+ t as BaseTransportType
28
+ } from "../types-D2naO3rA.js";
37
29
  import {
38
30
  a as McpAuthContext,
39
31
  n as StatelessMcpHandler,
40
32
  o as getMcpAuthContext,
41
- t as CreateStatelessMcpHandlerOptions,
42
- u as McpClientOptions
43
- } from "../handler-stateless-DxYpJ_XF.js";
33
+ t as CreateStatelessMcpHandlerOptions
34
+ } from "../handler-stateless-C90kD5_R.js";
35
+ import {
36
+ ElicitRequest,
37
+ ElicitResult,
38
+ SSEClientTransport,
39
+ SSEClientTransportOptions,
40
+ StreamableHTTPClientTransport,
41
+ StreamableHTTPClientTransportOptions
42
+ } from "@modelcontextprotocol/client";
43
+ import {
44
+ ElicitRequestSchema,
45
+ ElicitResult as ElicitResult$2,
46
+ InitializeRequestParams,
47
+ JSONRPCMessage as JSONRPCMessage$1,
48
+ MessageExtraInfo as MessageExtraInfo$1,
49
+ RequestId
50
+ } from "@modelcontextprotocol/sdk/types.js";
51
+ import { McpServerFactory } from "@modelcontextprotocol/server";
52
+ import { McpServer as McpServer$1 } from "@modelcontextprotocol/sdk/server/mcp.js";
53
+ import { Server as Server$1 } from "@modelcontextprotocol/sdk/server/index.js";
54
+ import {
55
+ EventStore as EventStore$1,
56
+ StreamId as StreamId$1,
57
+ WebStandardStreamableHTTPServerTransport as WebStandardStreamableHTTPServerTransport$1,
58
+ WebStandardStreamableHTTPServerTransportOptions
59
+ } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
60
+ import {
61
+ EventId,
62
+ EventStore,
63
+ StreamId
64
+ } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
65
+ import {
66
+ Transport as Transport$1,
67
+ TransportSendOptions as TransportSendOptions$1
68
+ } from "@modelcontextprotocol/sdk/shared/transport.js";
69
+ import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
70
+
71
+ //#region src/mcp/rpc-server.d.ts
72
+ interface RPCServerTransportOptions {
73
+ timeout?: number;
74
+ }
75
+ declare class RPCServerTransport implements Transport$1 {
76
+ private _started;
77
+ private _protocolVersion?;
78
+ private _timeout;
79
+ private _pendingRequests;
80
+ private _pendingContinuations;
81
+ sessionId?: string;
82
+ onclose?: () => void;
83
+ onerror?: (error: Error) => void;
84
+ onmessage?: (message: JSONRPCMessage$1, extra?: MessageExtraInfo$1) => void;
85
+ constructor(options?: RPCServerTransportOptions);
86
+ setProtocolVersion(version: string): void;
87
+ getProtocolVersion(): string | undefined;
88
+ start(): Promise<void>;
89
+ close(): Promise<void>;
90
+ private _makeTimeout;
91
+ private _appendPending;
92
+ private _completePending;
93
+ private _completeRequest;
94
+ private _appendRequest;
95
+ private _completeContinuation;
96
+ private _appendContinuation;
97
+ send(
98
+ message: JSONRPCMessage$1,
99
+ options?: TransportSendOptions$1
100
+ ): Promise<void>;
101
+ /**
102
+ * @internal Called by McpAgent.handleMcpMessage() — not for external use.
103
+ *
104
+ * Wait for the next unmatched send() call that expects a client response or
105
+ * completes a resumed tool call.
106
+ *
107
+ * Used after resolving an elicitation response: the original tool call has
108
+ * already returned the elicitation request to the RPC client, and the resumed
109
+ * tool handler will eventually send the final tool result. That final response
110
+ * has the original tool request id, so there is no active handle() waiter left
111
+ * for id-based routing; this continuation waiter receives it instead.
112
+ */
113
+ _awaitPendingResponse(): Promise<
114
+ JSONRPCMessage$1 | JSONRPCMessage$1[] | undefined
115
+ >;
116
+ handle(
117
+ message: JSONRPCMessage$1 | JSONRPCMessage$1[]
118
+ ): Promise<JSONRPCMessage$1 | JSONRPCMessage$1[] | undefined>;
119
+ }
120
+ //#endregion
121
+ //#region src/mcp/client/transports.d.ts
122
+ /**
123
+ * @deprecated Use SSEClientTransport from @modelcontextprotocol/client instead. This alias will be removed in the next major version.
124
+ */
125
+ declare class SSEEdgeClientTransport extends SSEClientTransport {
126
+ constructor(url: URL, options: SSEClientTransportOptions);
127
+ }
128
+ /**
129
+ * @deprecated Use StreamableHTTPClientTransport from @modelcontextprotocol/client instead. This alias will be removed in the next major version.
130
+ */
131
+ declare class StreamableHTTPEdgeClientTransport extends StreamableHTTPClientTransport {
132
+ constructor(url: URL, options: StreamableHTTPClientTransportOptions);
133
+ }
134
+ //#endregion
135
+ //#region src/mcp/server/worker-transport.d.ts
136
+ /**
137
+ * Pluggable storage adapter for persisting `WorkerTransport` state across
138
+ * Durable Object hibernation / restart cycles.
139
+ *
140
+ * A typical implementation reads/writes a single key on `this.ctx.storage`
141
+ * inside a Durable Object or Agent.
142
+ */
143
+ interface MCPStorageApi {
144
+ get(): Promise<TransportState | undefined> | TransportState | undefined;
145
+ set(state: TransportState): Promise<void> | void;
146
+ }
147
+ /** Shape of the persisted transport state. */
148
+ interface TransportState {
149
+ sessionId?: string;
150
+ initialized: boolean;
151
+ initializeParams?: InitializeRequestParams;
152
+ }
153
+ interface WorkerTransportOptions extends WebStandardStreamableHTTPServerTransportOptions {
154
+ /**
155
+ * CORS options applied to every response and to OPTIONS preflight.
156
+ * Defaults: `origin: *`, expose `mcp-session-id`, allow the standard MCP
157
+ * methods/headers, max-age 86400.
158
+ */
159
+ corsOptions?: CORSOptions;
160
+ /**
161
+ * Optional storage adapter for persisting transport state across DO
162
+ * hibernation / restart. Use this to keep an MCP session alive across
163
+ * Durable Object wake-ups.
164
+ */
165
+ storage?: MCPStorageApi;
166
+ }
167
+ declare class WorkerTransport extends WebStandardStreamableHTTPServerTransport$1 {
168
+ private readonly _corsOptions?;
169
+ private readonly _storage?;
170
+ private _stateRestored;
171
+ private _capturedInitializeParams?;
172
+ private _userOnSessionInitialized?;
173
+ private _bridgeInstalled;
174
+ /**
175
+ * Request ids whose SSE stream was deliberately torn down via
176
+ * `closeSSEStream`. The SDK's `send()` throws "No connection established"
177
+ * when a request id has no stream — a race that surfaces whenever the
178
+ * server's tool handler resolves *after* the caller closed the stream
179
+ * (e.g. polling-style early-close, or test fixtures closing mid-flight).
180
+ * We swallow `send()` for these ids so the rejection doesn't bubble out
181
+ * of the protocol layer as an unhandled rejection. Mirrors the
182
+ * silent-noop behaviour of the pre-refactor `WorkerTransport`.
183
+ */
184
+ private readonly _closedRequestIds;
185
+ constructor(options?: WorkerTransportOptions);
186
+ /**
187
+ * Backwards-compatible alias for the SDK's internal `_started` flag.
188
+ * Several callers and tests check `transport.started` directly.
189
+ */
190
+ get started(): boolean;
191
+ /**
192
+ * Top-level request entry point. Handles CORS preflight, restores any
193
+ * persisted state on first invocation, then delegates to the SDK transport
194
+ * and finally appends CORS headers to whatever response comes back.
195
+ */
196
+ handleRequest(
197
+ request: Request,
198
+ options?: {
199
+ parsedBody?: unknown;
200
+ authInfo?: AuthInfo;
201
+ }
202
+ ): Promise<Response>;
203
+ /**
204
+ * The SDK's 405 responses advertise `Allow: GET, POST, DELETE` because
205
+ * OPTIONS is handled outside the SDK. Since our wrapper *does* handle
206
+ * OPTIONS, advertise it in `Allow` so clients can probe accurately.
207
+ */
208
+ private normalizeAllowHeader;
209
+ closeSSEStream(requestId: RequestId): void;
210
+ close(): Promise<void>;
211
+ /**
212
+ * Swallow two classes of message that would otherwise surface as
213
+ * unhandled rejections from the SDK transport's `send()`:
214
+ *
215
+ * 1. Replayed initialize responses (the `RESTORE_REQUEST_ID` sentinel)
216
+ * — we synthesise these in `restoreState()` to rebuild server
217
+ * capabilities; there's no real client waiting for the response.
218
+ * 2. Sends for a request id whose SSE stream has been deliberately
219
+ * closed via `closeSSEStream`. The protocol layer's tool-handler
220
+ * promise may settle after the close, and the SDK's `send()` throws
221
+ * "No connection established" — a race the pre-refactor transport
222
+ * silently swallowed.
223
+ *
224
+ * Everything else is delegated. We use `await super.send(...)` rather
225
+ * than `return super.send(...)` so any rejection is observed inside this
226
+ * async frame; without the await, the test runner's
227
+ * unhandled-rejection tracker can fire before the caller's own `await`
228
+ * observes it.
229
+ */
230
+ send(
231
+ message: JSONRPCMessage$1,
232
+ options?: TransportSendOptions$1
233
+ ): Promise<void>;
234
+ private getCorsHeaders;
235
+ private withCorsHeaders;
236
+ private installOnSessionInitializedBridge;
237
+ private captureInitializeParams;
238
+ private restoreState;
239
+ private saveState;
240
+ }
241
+ //#endregion
242
+ //#region src/mcp/server/handler-legacy.d.ts
243
+ /** Options for the retained SDK v1, sessionful handler. */
244
+ interface CreateLegacyMcpHandlerOptions extends WorkerTransportOptions {
245
+ /** Exact route handled by this handler. @default "/mcp" */
246
+ route?: string;
247
+ /** Application props exposed through {@link getMcpAuthContext}. */
248
+ authContext?: McpAuthContext;
249
+ /** Pre-created sessionful transport. */
250
+ transport?: WorkerTransport;
251
+ }
252
+ type CreateMcpHandlerOptions = CreateLegacyMcpHandlerOptions;
253
+ type LegacyMcpHandler = (
254
+ request: Request,
255
+ env: unknown,
256
+ ctx: ExecutionContext
257
+ ) => Promise<Response>;
258
+ /**
259
+ * Create a sessionful Legacy MCP handler backed by SDK v1.
260
+ *
261
+ * New Stateless servers should use `createMcpHandler` from
262
+ * `agents/mcp/server` instead.
263
+ */
264
+ declare function createLegacyMcpHandler(
265
+ server: McpServer$1 | Server$1,
266
+ options?: CreateLegacyMcpHandlerOptions
267
+ ): LegacyMcpHandler;
268
+ //#endregion
269
+ //#region src/mcp/server/handler-compat.d.ts
270
+ /**
271
+ * @deprecated Passing an SDK v1 server to createMcpHandler is deprecated and
272
+ * will be removed in the next major version. Pass an SDK v2 factory to
273
+ * createMcpHandler. Use createLegacyMcpHandler only to temporarily retain
274
+ * sessionful SDK v1 behavior while migrating.
275
+ */
276
+ declare function createMcpHandler(
277
+ server: McpServer$1 | Server$1,
278
+ options?: CreateMcpHandlerOptions
279
+ ): LegacyMcpHandler;
280
+ declare function createMcpHandler(
281
+ factory: McpServerFactory,
282
+ options?: CreateStatelessMcpHandlerOptions
283
+ ): StatelessMcpHandler;
284
+ /**
285
+ * @deprecated Pass an SDK v2 factory to createMcpHandler.
286
+ * experimental_createMcpHandler will be removed in the next major version.
287
+ * Use createLegacyMcpHandler only to temporarily retain sessionful SDK v1
288
+ * behavior while migrating.
289
+ */
290
+ declare function experimental_createMcpHandler(
291
+ server: McpServer$1 | Server$1,
292
+ options?: CreateMcpHandlerOptions
293
+ ): LegacyMcpHandler;
294
+ //#endregion
295
+ //#region src/mcp/server/event-store.d.ts
296
+ /**
297
+ * Durable Object–backed {@link EventStore} for SSE resumability.
298
+ *
299
+ * Default for `McpAgent`. Override `McpAgent.getEventStore()` to swap
300
+ * or disable.
301
+ *
302
+ * ## Storage layout
303
+ *
304
+ * Events are stored under `__mcp_event__:<streamId>:<seqHex>`, where
305
+ * `<seqHex>` is a 16-char zero-padded counter so events in a stream
306
+ * sort lexicographically and `getStreamIdForEventId` can recover the
307
+ * stream from `eventId` without a storage hit.
308
+ *
309
+ * ## Lifecycle
310
+ *
311
+ * Each POST tool-call stream's events live only until the final
312
+ * response is delivered. The transport calls {@link clearStream}
313
+ * immediately after writing the close frame, so storage growth is
314
+ * bounded by the in-flight POST streams plus the standalone GET
315
+ * stream. There is no background sweep — quiescent agents do no work,
316
+ * and the DO itself dies with the session.
317
+ *
318
+ * Standalone GET stream events (`_GET_stream`) are *not* cleared
319
+ * automatically; they accumulate for the lifetime of the DO. Bounded
320
+ * by session length in practice.
321
+ *
322
+ * Trade-off: if the client TCP connection dies *after* the close
323
+ * frame has been enqueued on the WS but before the bytes reach the
324
+ * client, the final message is unreplayable. Every earlier event in
325
+ * the stream is still replayable while the in-flight stream is open.
326
+ *
327
+ * ## Stream id constraints
328
+ *
329
+ * `streamId` MUST NOT contain `:`. `storeEvent` asserts this so
330
+ * embedders using custom stream ids fail loudly rather than risk
331
+ * prefix-scan collisions (e.g. clearing `a` accidentally hitting
332
+ * `a:b`). Default ids (`connection.id` UUIDs and the literal
333
+ * `_GET_stream`) already satisfy this.
334
+ */
335
+ declare class DurableObjectEventStore implements EventStore {
336
+ private static readonly EVENT_KEY_PREFIX;
337
+ private static readonly SEQ_PAD;
338
+ /** DO storage caps multi-key delete at 128. */
339
+ private static readonly DELETE_CHUNK;
340
+ /** Defensive ceiling on a single replay batch. A live stream's
341
+ * event count is small (progress notifications + final result);
342
+ * this is here so a pathological history can't OOM the DO. */
343
+ private static readonly REPLAY_LIMIT;
344
+ private readonly storage;
345
+ /** In-memory seq counters per stream, rehydrated lazily from storage. */
346
+ private readonly seqByStream;
347
+ private readonly seqInit;
348
+ constructor(storage: DurableObjectStorage);
349
+ storeEvent(streamId: StreamId, message: JSONRPCMessage$1): Promise<EventId>;
350
+ getStreamIdForEventId(eventId: EventId): Promise<StreamId | undefined>;
351
+ replayEventsAfter(
352
+ lastEventId: EventId,
353
+ {
354
+ send
355
+ }: {
356
+ send: (eventId: EventId, message: JSONRPCMessage$1) => Promise<void>;
357
+ }
358
+ ): Promise<StreamId>;
359
+ /**
360
+ * Drop the event log for a single stream. Called by the transport
361
+ * immediately after a POST's final response has been written to the
362
+ * wire — no future `Last-Event-ID` for this stream is expected to
363
+ * resolve.
364
+ *
365
+ * Lists and deletes in chunks of {@link DELETE_CHUNK} (128, the DO
366
+ * storage cap) so we never load the entire event log into memory.
367
+ * After deleting, the next `list` call won't see the deleted keys,
368
+ * so passing `start: <prefix>` again is enough — no cursor bookkeeping.
369
+ */
370
+ clearStream(streamId: StreamId): Promise<void>;
371
+ private ensureSeqLoaded;
372
+ }
373
+ //#endregion
374
+ //#region src/mcp/server/transport.d.ts
375
+ /**
376
+ * An {@link EventStore} that supports dropping all events for a single
377
+ * stream id. Implemented by {@link DurableObjectEventStore}.
378
+ */
379
+ interface ClearableEventStore extends EventStore$1 {
380
+ clearStream(streamId: StreamId$1): Promise<void>;
381
+ }
382
+ //#endregion
383
+ //#region src/mcp/server/legacy-agent.d.ts
384
+ /**
385
+ * @deprecated McpAgent is feature-frozen. Migrate to an SDK v2 factory with
386
+ * createMcpHandler from agents/mcp/server. When sessionful features prevent an
387
+ * immediate migration, run the stateless route beside the existing McpAgent
388
+ * route until clients transition and sessions drain.
389
+ */
390
+ declare abstract class McpAgent<
391
+ Env extends Cloudflare.Env = Cloudflare.Env,
392
+ State = unknown,
393
+ Props extends Record<string, unknown> = Record<string, unknown>
394
+ > extends Agent<Env, State, Props> {
395
+ private _transport?;
396
+ private _pendingElicitations;
397
+ props?: Props;
398
+ shouldSendProtocolMessages(
399
+ _connection: Connection,
400
+ ctx: ConnectionContext
401
+ ): boolean;
402
+ abstract server: MaybePromise<McpServer$1 | Server$1>;
403
+ abstract init(): Promise<void>;
404
+ setInitializeRequest(initializeRequest: JSONRPCMessage$1): Promise<void>;
405
+ getInitializeRequest(): Promise<JSONRPCMessage$1 | undefined>;
406
+ /**
407
+ * End a streamable HTTP session (`DELETE`). Teardown is deferred to the
408
+ * agent's alarm (#1625), so the stored initialize request is cleared too:
409
+ * every route treats a session without one as unknown, which makes requests
410
+ * carrying the terminated session ID get 404 as the spec requires. Teardown
411
+ * is scheduled first, so a failure part-way leaves a session the client can
412
+ * `DELETE` again rather than one that is never cleaned up.
413
+ *
414
+ * @internal
415
+ */
416
+ _cf_terminateSession(): Promise<void>;
417
+ /**
418
+ * Storage key prefix for the `streamId -> requestIds` mapping used
419
+ * to support POST stream resumption across WebSocket reconnects.
420
+ *
421
+ * @internal
422
+ */
423
+ private static readonly STREAM_REQS_KEY_PREFIX;
424
+ /** Persist the `requestIds` for a POST stream. @internal */
425
+ setStreamRequestIds(streamId: string, requestIds: RequestId[]): Promise<void>;
426
+ /** Read the persisted `requestIds` for a POST stream. @internal */
427
+ getStreamRequestIds(streamId: string): Promise<RequestId[] | undefined>;
428
+ /** Drop the persisted `requestIds` for a POST stream. @internal */
429
+ deleteStreamRequestIds(streamId: string): Promise<void>;
430
+ /**
431
+ * Reverse lookup: find which POST stream a given `requestId` belongs
432
+ * to, and return the stream's full `requestIds` list in the same
433
+ * pass. Used by the transport when the originating WS has dropped,
434
+ * so `send()` can still record events for replay and decide whether
435
+ * the stream is fully responded — mirrors the SDK's
436
+ * `_requestToStreamMapping` which outlives connection loss.
437
+ *
438
+ * Returning `requestIds` alongside `streamId` lets `send()` skip a
439
+ * second `getStreamRequestIds` read on the same key.
440
+ *
441
+ * O(n) in the number of in-flight POST streams — single-digit in
442
+ * practice since each stream is cleaned up on its final response.
443
+ * The `limit` is a defensive ceiling so an abandoned-POST leak can't
444
+ * unbounded-load this scan; if you hit it, something else has gone
445
+ * wrong and `send()` will throw `No active stream found`.
446
+ *
447
+ * @internal
448
+ */
449
+ getStreamForRequestId(requestId: RequestId): Promise<
450
+ | {
451
+ streamId: string;
452
+ requestIds: RequestId[];
453
+ }
454
+ | undefined
455
+ >;
456
+ /** Read the transport type for this agent.
457
+ * This relies on the naming scheme being `sse:${sessionId}`,
458
+ * `streamable-http:${sessionId}`, or `rpc:${sessionId}`.
459
+ */
460
+ getTransportType(): BaseTransportType;
461
+ /** Read the sessionId for this agent.
462
+ * This relies on the naming scheme being `sse:${sessionId}`
463
+ * or `streamable-http:${sessionId}`.
464
+ */
465
+ getSessionId(): string;
466
+ /** Get the unique WebSocket. SSE transport only. */
467
+ getWebSocket(): Connection<unknown> | null;
468
+ /**
469
+ * Returns options for configuring the RPC server transport.
470
+ * Override this method to customize RPC transport behavior (e.g., timeout).
471
+ *
472
+ * @example
473
+ * ```typescript
474
+ * class MyMCP extends McpAgent {
475
+ * protected getRpcTransportOptions() {
476
+ * return { timeout: 120000 }; // 2 minutes
477
+ * }
478
+ * }
479
+ * ```
480
+ */
481
+ protected getRpcTransportOptions(): RPCServerTransportOptions;
482
+ /**
483
+ * Returns the {@link EventStore} for SSE resumability. Defaults to a
484
+ * {@link DurableObjectEventStore} backed by this agent's storage,
485
+ * letting clients reconnect with `Last-Event-ID` after the Cloudflare
486
+ * edge closes an idle SSE stream (~5 minute watchdog) instead of
487
+ * relying on a server-side keepalive that would block hibernation.
488
+ *
489
+ * Per-stream events are cleared by the transport immediately after
490
+ * the final response is written to the wire, so there's no
491
+ * background cleanup — storage cost is bounded by the in-flight
492
+ * streams alone.
493
+ *
494
+ * Override to disable (`return undefined`) or swap implementations.
495
+ */
496
+ protected getEventStore(): EventStore | undefined;
497
+ /** Returns a new transport matching the type of the Agent. */
498
+ private initTransport;
499
+ /** Update and store the props */
500
+ updateProps(props?: Props): Promise<void>;
501
+ reinitializeServer(): Promise<void>;
502
+ /** Sets up the MCP transport and server every time the Agent is started.*/
503
+ onStart(props?: Props): Promise<void>;
504
+ /** Validates new WebSocket connections. */
505
+ onConnect(
506
+ conn: Connection,
507
+ { request: req }: ConnectionContext
508
+ ): Promise<void>;
509
+ /** Handles MCP Messages for the legacy SSE transport. */
510
+ onSSEMcpMessage(
511
+ _sessionId: string,
512
+ messageBody: unknown,
513
+ extraInfo?: MessageExtraInfo$1
514
+ ): Promise<Error | null>;
515
+ /** Elicit user input with a message and schema */
516
+ elicitInput(
517
+ params: {
518
+ message: string;
519
+ requestedSchema: unknown;
520
+ },
521
+ options?: {
522
+ relatedRequestId?: RequestId;
523
+ }
524
+ ): Promise<ElicitResult$2>;
525
+ /** Handle elicitation responses via in-memory resolver */
526
+ private _handleElicitationResponse;
527
+ /**
528
+ * Handle an RPC message for MCP
529
+ * This method is called by the RPC stub to process MCP messages
530
+ * @param message The JSON-RPC message(s) to handle
531
+ * @returns The response message(s) or undefined
532
+ */
533
+ handleMcpMessage(
534
+ message: JSONRPCMessage$1 | JSONRPCMessage$1[]
535
+ ): Promise<JSONRPCMessage$1 | JSONRPCMessage$1[] | undefined>;
536
+ /** Return a handler for the given path for this MCP.
537
+ * Defaults to Streamable HTTP transport.
538
+ */
539
+ static serve(
540
+ path: string,
541
+ { binding, corsOptions, transport, jurisdiction }?: ServeOptions
542
+ ): {
543
+ fetch<Env>(
544
+ this: void,
545
+ request: Request,
546
+ env: Env,
547
+ ctx: ExecutionContext
548
+ ): Promise<Response>;
549
+ };
550
+ /**
551
+ * Legacy api
552
+ **/
553
+ static mount(
554
+ path: string,
555
+ opts?: Omit<ServeOptions, "transport">
556
+ ): {
557
+ fetch<Env>(
558
+ this: void,
559
+ request: Request,
560
+ env: Env,
561
+ ctx: ExecutionContext
562
+ ): Promise<Response>;
563
+ };
564
+ static serveSSE(
565
+ path: string,
566
+ opts?: Omit<ServeOptions, "transport">
567
+ ): {
568
+ fetch<Env>(
569
+ this: void,
570
+ request: Request,
571
+ env: Env,
572
+ ctx: ExecutionContext
573
+ ): Promise<Response>;
574
+ };
575
+ }
576
+ //#endregion
44
577
  export {
45
578
  type ClearableEventStore,
46
579
  type CreateLegacyMcpHandlerOptions,
@@ -82,3 +615,4 @@ export {
82
615
  getMcpAuthContext,
83
616
  normalizeServerId
84
617
  };
618
+ //# sourceMappingURL=index.d.ts.map