@dudko.dev/agent-web 0.0.39 → 0.0.41

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 (40) hide show
  1. package/README.md +407 -13
  2. package/dist/agent-web.js +169 -161
  3. package/dist/agent-web.js.map +1 -1
  4. package/dist/chunk-4FBTBE74.js +510 -0
  5. package/dist/chunk-4FBTBE74.js.map +1 -0
  6. package/dist/{chunk-TZITKUFW.js → chunk-L7Y3QRAM.js} +152 -20
  7. package/dist/chunk-L7Y3QRAM.js.map +1 -0
  8. package/dist/{chunk-V3JOK7EW.js → chunk-YPCHD6DV.js} +4 -2
  9. package/dist/chunk-YPCHD6DV.js.map +1 -0
  10. package/dist/chunk-YUA2BHRM.js +584 -0
  11. package/dist/chunk-YUA2BHRM.js.map +1 -0
  12. package/dist/elicitation-BA1knkdA.d.cts +566 -0
  13. package/dist/elicitation-BA1knkdA.d.ts +566 -0
  14. package/dist/index.cjs +1819 -223
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +690 -117
  17. package/dist/index.d.ts +690 -117
  18. package/dist/index.js +1281 -187
  19. package/dist/index.js.map +1 -1
  20. package/dist/mcp.cjs +2240 -95
  21. package/dist/mcp.cjs.map +1 -1
  22. package/dist/mcp.d.cts +303 -21
  23. package/dist/mcp.d.ts +303 -21
  24. package/dist/mcp.js +1675 -91
  25. package/dist/mcp.js.map +1 -1
  26. package/dist/{sandbox-KG6OUG24.js → sandbox-ZDQIIZS7.js} +21 -8
  27. package/dist/sandbox-ZDQIIZS7.js.map +1 -0
  28. package/dist/sandbox-worker.cjs +3 -1
  29. package/dist/sandbox-worker.cjs.map +1 -1
  30. package/dist/sandbox-worker.js +1 -1
  31. package/package.json +5 -5
  32. package/dist/chunk-A6ZJALLU.js +0 -254
  33. package/dist/chunk-A6ZJALLU.js.map +0 -1
  34. package/dist/chunk-CTXDKSDD.js +0 -39
  35. package/dist/chunk-CTXDKSDD.js.map +0 -1
  36. package/dist/chunk-TZITKUFW.js.map +0 -1
  37. package/dist/chunk-V3JOK7EW.js.map +0 -1
  38. package/dist/sandbox-KG6OUG24.js.map +0 -1
  39. package/dist/vault-BatBaRQP.d.cts +0 -36
  40. package/dist/vault-BatBaRQP.d.ts +0 -36
package/dist/mcp.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { OAuthClientProvider, OAuthDiscoveryState } from '@modelcontextprotocol/sdk/client/auth.js';
2
- export { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js';
3
- import { StreamableHTTPReconnectionOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
4
- import { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
1
+ import { OAuthClientProvider, FetchLike, StreamableHTTPReconnectionOptions, OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens, OAuthDiscoveryState } from '@modelcontextprotocol/client';
2
+ export { UnauthorizedError } from '@modelcontextprotocol/client';
5
3
  import { ToolSet } from 'ai';
6
- import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
7
- import { VaultOptions } from './index.js';
4
+ import { H as McpElicitationHandler, J as McpElicitationOptions, y as McpAppResource, z as McpAppVisibility, K as McpAppDownloadResource, g as McpAppToolResult } from './elicitation-BA1knkdA.js';
5
+ import { McpSkillsSetting, VaultOptions } from './index.js';
6
+ export { h as MCP_APPS_EXTENSION, L as MCP_APP_DEFAULT_VISIBILITY, N as MCP_APP_MAX_DOMAINS, O as MCP_APP_MAX_DOWNLOAD_BYTES, i as MCP_APP_MAX_HTML_CHARS, j as MCP_APP_MAX_RESULT_CHARS, k as MCP_APP_MIME_TYPE, P as MCP_ELICITATION_MAX_PER_RUN, Q as MCP_ELICITATION_MAX_PER_TOOL_CALL, R as MCP_ELICITATION_TIMEOUT_MS, w as McpAppCsp, x as McpAppPermissions, S as McpAppResourceError, T as McpAppToolMeta, U as McpAppsMode, W as McpElicitationContent, X as McpElicitationContext, A as McpElicitationFieldSchema, f as McpElicitationReason, Y as McpElicitationRequest, Z as McpElicitationResult, e as McpElicitationSchema, _ as isMcpAppMimeType, $ as isMcpAppUri, a0 as mcpAppCspOf, a1 as mcpAppDownloadOf, D as mcpAppOrigin, a2 as mcpAppPermissionsOf, a3 as mcpAppResourceOf, a4 as mcpAppToolMeta, a5 as mcpAppToolResultOf, a6 as mcpAppsModeOf, a7 as normalizeMcpElicitationSchema, a8 as validateMcpElicitationContent } from './elicitation-BA1knkdA.js';
8
7
 
9
8
  /**
10
9
  * What the MCP connectors of the two agent packages share: how a server's `instructions` reach a
11
- * system prompt, and how a tool result's `structuredContent` reaches the model. Pure, no imports.
10
+ * system prompt, how a tool result's `structuredContent` reaches the model, and what the
11
+ * per-server `protocol` option means. Pure, no imports.
12
12
  *
13
13
  * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-shared.ts`) and
14
14
  * `@dudko.dev/agent-web` (`src/mcp/shared.ts`): change both. The Node package's
@@ -33,12 +33,41 @@ declare const MCP_INSTRUCTIONS_MAX_CHARS_TOTAL = 8000;
33
33
  * or as another server's note.
34
34
  */
35
35
  declare const renderMcpInstructions: (list: readonly McpServerInstructions[] | undefined) => string;
36
+ /**
37
+ * Which revisions of the protocol a connection to one server may use (the server config's
38
+ * `protocol`):
39
+ *
40
+ * - `'legacy'` (default): the 2025 revisions, the `initialize` handshake. Nothing of the 2026
41
+ * revision is sent.
42
+ * - `'auto'`: ask first (`server/discover`); a server that answers with 2026-07-28 is spoken to
43
+ * that way, any other is given the 2025 handshake. Decided once, at connect.
44
+ * - `'modern'`: 2026-07-28 only. A server that does not offer it fails the connect.
45
+ */
46
+ type McpProtocolMode = 'legacy' | 'auto' | 'modern';
47
+ /** The revision `protocol: 'modern'` pins: the one this connector is tested against. */
48
+ declare const MCP_MODERN_PROTOCOL_VERSION = "2026-07-28";
49
+ /** What a connection negotiated with one server. */
50
+ interface McpServerProtocol {
51
+ /** The server's name: its key in the host's configuration. */
52
+ server: string;
53
+ /** The protocol revision in use, e.g. `2025-11-25` or `2026-07-28`. */
54
+ version: string;
55
+ /** `modern` from 2026-07-28 on (stateless, `server/discover`), `legacy` before. */
56
+ era: 'legacy' | 'modern';
57
+ }
58
+ /**
59
+ * The request headers the 2026-07-28 revision adds to every POST (its Streamable HTTP "request
60
+ * metadata"), beside `MCP-Protocol-Version`, which the 2025 revisions already send after
61
+ * `initialize`. A page can send them only to a server whose `Access-Control-Allow-Headers` lists
62
+ * them.
63
+ */
64
+ declare const MCP_MODERN_REQUEST_HEADERS: readonly string[];
36
65
 
37
66
  /**
38
67
  * A remote MCP server reached over StreamableHTTP. Browsers can ONLY speak the
39
68
  * HTTP transport — stdio (child processes) is Node-only and intentionally
40
69
  * unsupported here. This connector lives behind the `@dudko.dev/agent-web/mcp`
41
- * subpath so `@modelcontextprotocol/sdk` never enters the core bundle.
70
+ * subpath so `@modelcontextprotocol/client` never enters the core bundle.
42
71
  *
43
72
  * Three ways to authenticate, in ascending order of capability:
44
73
  * 1. `headers` — a static token you already hold.
@@ -66,6 +95,50 @@ interface McpHttpServerConfig {
66
95
  reconnection?: Partial<StreamableHTTPReconnectionOptions>;
67
96
  /** Give up on this server after this many ms of connect + listing (overrides the option). */
68
97
  connectTimeoutMs?: number;
98
+ /**
99
+ * Which revisions of the protocol this connection may use. Default `'legacy'`:
100
+ * the 2025 revisions (the `initialize` handshake), exactly what was sent before
101
+ * this option existed. `'auto'` asks the server first (`server/discover`) and
102
+ * speaks 2026-07-28 to one that offers it, the 2025 handshake to any other;
103
+ * `'modern'` is 2026-07-28 only, and a server that does not offer it fails the
104
+ * connect. Decided once, at connect: a tool call is never retried in another
105
+ * revision.
106
+ *
107
+ * CORS: 2026-07-28 adds the request headers `Mcp-Method` and `Mcp-Name` (and
108
+ * sends `MCP-Protocol-Version` on every request, the first included). A server
109
+ * whose `Access-Control-Allow-Headers` does not list them cannot be reached
110
+ * that way from a page: `'modern'` then fails, and `'auto'` falls back to the
111
+ * 2025 revisions with a warning that names the headers. See the README, "CORS".
112
+ *
113
+ * On 2026-07-28 there is no session; a tool-list change arrives over a
114
+ * `subscriptions/listen` stream this connector opens - and opens again, with
115
+ * backoff, when it ends while the connection is open (then `onToolsChanged`
116
+ * fires once: a change in the gap was announced to nobody) - and an
117
+ * `input_required` result fails the call unless the connection was given
118
+ * `onElicitation` (see `ConnectMcpOptions`).
119
+ */
120
+ protocol?: McpProtocolMode;
121
+ /**
122
+ * EXPERIMENTAL (the Skills extension is Beta): load the skills this server serves
123
+ * (`io.modelcontextprotocol/skills`) into the agent's skills catalog, as `<server>/<skill>`.
124
+ * Off by default: without it the extension is not declared and nothing of it is sent. Needs
125
+ * the 2026-07-28 revision (`protocol: 'auto'` or `'modern'`): the extension is written against
126
+ * it. The skills come with the server's tools (each mounted tool carries them, like the
127
+ * server's instructions), so merging `tools` into the agent's config is all a host does. Their
128
+ * text is third-party - knowledge only, never policy; see the README, "MCP skills".
129
+ * `true`, or `{ consent }`: when a person is asked before one of its skills enters the model's
130
+ * context - `'once-per-skill'` (default, or the agent's `mcpSkills.consent`), `'ask'` (every
131
+ * run) or `'never'` (a server you vetted).
132
+ */
133
+ skills?: McpSkillsSetting;
134
+ /**
135
+ * MCP Apps for THIS server, over the connection's `apps`: `false` keeps its apps off while
136
+ * other servers' are shown - nothing is declared to it, no app of it is read, no `mcp.app`
137
+ * event is told, and a tool it marks for its app only (`visibility` without `'model'`) is
138
+ * not mounted; its other tools are the model's, as plain tools. `true` turns them on for this
139
+ * server alone. Left out, the connection's `apps` decides.
140
+ */
141
+ apps?: boolean;
69
142
  }
70
143
  interface McpCatalogEntry {
71
144
  name: string;
@@ -73,6 +146,11 @@ interface McpCatalogEntry {
73
146
  server: string;
74
147
  /** The server marked the tool read-only (`annotations.readOnlyHint`). */
75
148
  readOnly?: boolean;
149
+ /**
150
+ * With `apps: true`: the MCP App (`ui://…`) the tool declares. Its results then come with an
151
+ * `mcp.app` event, and the host can show the app (`ConnectedMcp.apps`).
152
+ */
153
+ app?: string;
76
154
  }
77
155
  interface McpServerResult {
78
156
  name: string;
@@ -100,13 +178,75 @@ interface ConnectedMcp {
100
178
  * the agent's config is all a host does.
101
179
  */
102
180
  instructions: McpServerInstructions[];
181
+ /**
182
+ * The protocol revision negotiated with each connected server, in declaration
183
+ * order: `2025-…` after the `initialize` handshake (always, for a server
184
+ * without `protocol`), `2026-07-28` when `protocol: 'auto'` or `'modern'`
185
+ * found a server that offers it. Fixed for the life of the connection.
186
+ */
187
+ protocols: McpServerProtocol[];
103
188
  /**
104
189
  * Re-list one server's tools and rewrite its entries in `tools`/`catalog`.
105
190
  * Both are mutated in place, so anything holding a reference (including a
106
191
  * live agent config) sees the new set. Throws if the server isn't connected.
192
+ * With `skills: true` it lists the server's skills again too (an agent built
193
+ * after the refresh has the new ones; one built before keeps what it read).
107
194
  */
108
195
  refreshServer: (name: string) => Promise<void>;
109
196
  close: () => Promise<void>;
197
+ /**
198
+ * MCP Apps, present only on a connection made with `apps: true`: read an app's HTML and make
199
+ * the tool calls an app asks for. See {@link McpAppsConnection}.
200
+ */
201
+ apps?: McpAppsConnection;
202
+ }
203
+ /** A tool of a server as an app of that server sees it (see `McpAppsConnection.appTool`). */
204
+ interface McpAppTool {
205
+ /** The server's own name for the tool. */
206
+ name: string;
207
+ /**
208
+ * The name the agent's consent rules match: the key the tool is mounted under, or the key it
209
+ * would have (`server__tool`) when it is for apps only and not mounted.
210
+ */
211
+ key: string;
212
+ description: string;
213
+ inputSchema: unknown;
214
+ /** `annotations.readOnlyHint`: the consent gate lets it through in 'ask-writes'. */
215
+ readOnly: boolean;
216
+ visibility: McpAppVisibility[];
217
+ /** The app it declares, if any. */
218
+ resourceUri?: string;
219
+ }
220
+ /**
221
+ * The host's side of MCP Apps for one connection (`apps: true`). Every call names the server:
222
+ * an app may read and call only what its own server declared.
223
+ *
224
+ * - `readUiResource` reads an app's document with `resources/read` - only a `ui://` URI that a
225
+ * tool of THAT server declares in its current listing, from that server and nowhere else;
226
+ * checked (MIME type, size, URI) and cached per connection.
227
+ * - `appTool` is a server's tool an app may call: listed, with `visibility` including `'app'`.
228
+ * - `callAppTool` sends that tool call and returns the raw result for the app. It does NOT ask
229
+ * the user: a host calls it only after its consent, e.g. `Agent.approveAppToolCall`.
230
+ */
231
+ interface McpAppsConnection {
232
+ readUiResource: (server: string, uri: string, options?: {
233
+ signal?: AbortSignal;
234
+ }) => Promise<McpAppResource>;
235
+ appTool: (server: string, name: string) => McpAppTool | undefined;
236
+ /**
237
+ * A resource of that server for a file its app asks the host to save (`ui/download-file` with
238
+ * a `resource_link`): `resources/read` on THAT server only - never a fetch of the URI - its
239
+ * `text` or base64 `blob` as bytes, at most `maxBytes` (default `MCP_APP_MAX_DOWNLOAD_BYTES`),
240
+ * not cached. Only a server whose apps are on. It does NOT ask the user, nor judge the type:
241
+ * the host does both before it saves anything.
242
+ */
243
+ readResource: (server: string, uri: string, options?: {
244
+ signal?: AbortSignal;
245
+ maxBytes?: number;
246
+ }) => Promise<McpAppDownloadResource>;
247
+ callAppTool: (server: string, name: string, args: Record<string, unknown>, options?: {
248
+ signal?: AbortSignal;
249
+ }) => Promise<McpAppToolResult>;
110
250
  }
111
251
  interface ConnectMcpOptions {
112
252
  clientName?: string;
@@ -116,6 +256,14 @@ interface ConnectMcpOptions {
116
256
  * Fires when a server pushes `notifications/tools/list_changed`. Call
117
257
  * `refreshServer(name)` from a point where no run is reading `tools` — this
118
258
  * connector deliberately does not refresh behind a running agent's back.
259
+ * On a 2026-07-28 connection (`protocol`) the notice arrives over a
260
+ * `subscriptions/listen` stream, opened only when this callback is given and
261
+ * opened again when it ends (backoff from 1 s to 60 s, at most 10 attempts in
262
+ * a row; never after a 401 / 403 / 404 / 405). Once a stream is back this
263
+ * callback fires as for a notice, since a change in the gap was not announced.
264
+ * On a server with `skills: true` it also fires for a resource list change
265
+ * (`notifications/resources/list_changed`): that is how a change of its
266
+ * skills is announced, and `refreshServer` lists them again.
119
267
  */
120
268
  onToolsChanged?: (server: string) => void;
121
269
  /**
@@ -124,6 +272,47 @@ interface ConnectMcpOptions {
124
272
  * mount — one hanging server no longer holds every other one hostage.
125
273
  */
126
274
  connectTimeoutMs?: number;
275
+ /**
276
+ * MCP elicitation: a server may ask the user for input in the middle of a tool
277
+ * call (a form, or - with `elicitation.url` - a link to open), and this
278
+ * callback answers: accept with the form's values, decline, or cancel. The
279
+ * HOST decides, never the model: the question is not shown to the model, and
280
+ * the answer goes only to the server that asked - not into the model's
281
+ * context, an event, a log or a run checkpoint.
282
+ *
283
+ * Without the callback the capability is not declared, a server cannot ask,
284
+ * and nothing is sent that was not sent before. The server's message and form
285
+ * are third-party text: cleaned, capped and restricted to a flat form before
286
+ * the callback sees them; the answer is checked against the form before it is
287
+ * sent. A link (URL mode) is only handed to the callback: this package never
288
+ * fetches or opens it. A callback that throws or does not answer in time
289
+ * cancels the question and fails the tool call; nothing is retried.
290
+ *
291
+ * Inside an agent run the two events `mcp.elicitation-requested` /
292
+ * `mcp.elicitation-answered` are emitted (the answered one never carries a
293
+ * value). On the 2025 revisions the calls to a server with this option run
294
+ * one at a time: its question does not say which call it belongs to.
295
+ */
296
+ onElicitation?: McpElicitationHandler;
297
+ /**
298
+ * Its settings: `timeoutMs` (default 300 000: a human is answering; the
299
+ * step's `chatTimeoutMs` stops while a question waits),
300
+ * `maxPerToolCall` (5), `maxPerRun` (20), `url` (also accept URL mode; default
301
+ * false), `subagents` (let a call made by a helper - a subagent - ask too;
302
+ * default false: its question is cancelled without the callback being called).
303
+ */
304
+ elicitation?: McpElicitationOptions;
305
+ /**
306
+ * MCP Apps (the `io.modelcontextprotocol/ui` extension): declare the extension in the
307
+ * handshake, read each tool's `_meta.ui` (its `ui://` app and its `visibility`), emit an
308
+ * `mcp.app` event in a run when such a tool returns, and give the host `ConnectedMcp.apps` to
309
+ * read the app and make the calls it asks for. A tool whose `visibility` leaves out `'model'`
310
+ * is then not mounted (it is for its app only). The app's HTML never reaches the model.
311
+ *
312
+ * Off by default: nothing is declared, `_meta` is not read, every tool is mounted as before and
313
+ * the wire is unchanged. A server's own `apps` (`McpHttpServerConfig.apps`) wins over this one.
314
+ */
315
+ apps?: boolean;
127
316
  }
128
317
  /**
129
318
  * Flatten an MCP tool result's content into something a model can read. Unlike
@@ -144,9 +333,17 @@ declare const flattenContent: (content: unknown) => unknown;
144
333
  * bug that lets OAuth and `initialize` succeed and then kills the connection
145
334
  * moments later, looking for all the world like the consent step failed.
146
335
  *
336
+ * With `protocol: 'auto'` or `'modern'` the transport also sends the request
337
+ * headers of the 2026-07-28 revision, on the very first request. The browser
338
+ * will not say which header a preflight refused either, so each one is tried on
339
+ * its own: the ones that do not get through are the ones missing from the
340
+ * server's `Access-Control-Allow-Headers`, and they are named.
341
+ *
147
342
  * Exported because a UI wants to say this too, not just log it.
148
343
  */
149
- declare const diagnoseMcpCors: (url: string, fetchFn?: FetchLike) => Promise<string | undefined>;
344
+ declare const diagnoseMcpCors: (url: string, fetchFn?: FetchLike, opts?: {
345
+ protocol?: McpProtocolMode;
346
+ }) => Promise<string | undefined>;
150
347
  /**
151
348
  * Connect to one or more HTTP MCP servers and return their tools + catalogue.
152
349
  * Servers connect concurrently; tools, catalogue, and results merge in the
@@ -156,8 +353,9 @@ declare const connectMcpHttp: (servers: Record<string, McpHttpServerConfig>, opt
156
353
 
157
354
  /**
158
355
  * Browser-side OAuth 2.1 for remote MCP servers: Dynamic Client Registration
159
- * (RFC 7591) or a client ID metadata document (CIMD), PKCE authorization-code
160
- * flow, refresh-token rotation, and the `iss` check on the way back (RFC 9207).
356
+ * (RFC 7591) or a client ID metadata document (CIMD) - automatically or one of
357
+ * them only (`registration`) - PKCE authorization-code flow, refresh-token
358
+ * rotation, and the `iss` check on the way back (RFC 9207).
161
359
  *
162
360
  * The heavy lifting lives in the MCP SDK — `auth()` discovers the protected
163
361
  * resource (RFC 9728), registers the client if we have no client_id yet,
@@ -199,6 +397,25 @@ declare class MemoryOAuthStorage implements McpOAuthStorage {
199
397
  set(key: string, value: string): Promise<void>;
200
398
  delete(key: string): Promise<void>;
201
399
  }
400
+ /**
401
+ * How the OAuth client is registered with a server's authorization server
402
+ * (`BrowserOAuthProviderOptions.registration`):
403
+ *
404
+ * - `'auto'` (the default): by the client ID metadata document (CIMD) when the
405
+ * authorization server advertises `client_id_metadata_document_supported` and
406
+ * a `clientMetadataUrl` is set, by dynamic client registration (DCR, RFC 7591)
407
+ * otherwise. A client already in storage is used as it is.
408
+ * - `'cimd'`: by the metadata document only. Needs `clientMetadataUrl`. An
409
+ * authorization server that does not advertise support is refused before
410
+ * anything is sent to its registration endpoint.
411
+ * - `'dcr'`: by dynamic registration only, even with a `clientMetadataUrl` set:
412
+ * the SDK is never shown the URL.
413
+ *
414
+ * The Node package has the same option, with the same names; change both.
415
+ */
416
+ type McpOAuthRegistration = 'auto' | 'cimd' | 'dcr';
417
+ /** How a stored client was registered: see {@link BrowserOAuthProvider.registrationKind}. */
418
+ type McpOAuthRegistrationKind = 'cimd' | 'dcr';
202
419
  interface BrowserOAuthProviderOptions {
203
420
  /** The MCP endpoint this provider authorizes against (the resource server). */
204
421
  serverUrl: string;
@@ -222,9 +439,20 @@ interface BrowserOAuthProviderOptions {
222
439
  * this URL is used as the `client_id` and no dynamic registration is made;
223
440
  * otherwise registration runs as before. A registration already in storage
224
441
  * wins over both. Must be https with a non-root path, and the document served
225
- * there must list the same `redirect_uris` as `redirectUrl`.
442
+ * there must list the same `redirect_uris` as `redirectUrl`. With
443
+ * `registration: 'dcr'` it is never used as the `client_id`.
226
444
  */
227
445
  clientMetadataUrl?: string;
446
+ /**
447
+ * How the client is registered: `'auto'` (default; as described for
448
+ * `clientMetadataUrl`), `'cimd'` (the metadata document only: needs
449
+ * `clientMetadataUrl`, and an authorization server without support is refused
450
+ * before any registration request) or `'dcr'` (dynamic registration only).
451
+ * A stored client of the other kind is not reused: it is forgotten, with the
452
+ * tokens issued to it, and the user signs in again. See
453
+ * {@link McpOAuthRegistration}.
454
+ */
455
+ registration?: McpOAuthRegistration;
228
456
  /** Defaults to the encrypted IndexedDB vault. */
229
457
  storage?: McpOAuthStorage;
230
458
  /** Treat an access token as expired this many seconds early. Default 30. */
@@ -246,7 +474,8 @@ interface BrowserOAuthProviderOptions {
246
474
  * `authorization_response_iss_parameter_supported: true`;
247
475
  * - no stored discovery state (storage written by an older version): `iss` is
248
476
  * compared with the issuer stamped on the stored client information, and with
249
- * nothing to compare against the response is accepted.
477
+ * nothing to compare against the response is accepted. ({@link finishMcpOAuth}
478
+ * does not exchange a code in that case: see there.)
250
479
  *
251
480
  * The Node package carries the same function; change both.
252
481
  */
@@ -264,13 +493,22 @@ declare class BrowserOAuthProvider implements OAuthClientProvider {
264
493
  private readonly _redirectUrl;
265
494
  private readonly _clientMetadata;
266
495
  private readonly _clientMetadataUrl?;
496
+ private readonly _registration;
267
497
  private readonly skewMs;
268
498
  private readonly onRedirect?;
499
+ /** Once per provider: a stored client of the other kind is forgotten (see `settle`). */
500
+ private settled?;
269
501
  constructor(opts: BrowserOAuthProviderOptions);
270
502
  get redirectUrl(): string;
271
503
  get clientMetadata(): OAuthClientMetadata;
272
- /** The client ID metadata document URL (CIMD), when one was configured. */
504
+ /**
505
+ * The client ID metadata document URL (CIMD), when one was configured - and
506
+ * not with `registration: 'dcr'`: the SDK uses this getter to decide, so a
507
+ * URL it cannot see is a URL it never uses as the `client_id`.
508
+ */
273
509
  get clientMetadataUrl(): string | undefined;
510
+ /** How this provider registers its client: `'auto'`, `'cimd'` or `'dcr'`. */
511
+ get registration(): McpOAuthRegistration;
274
512
  private key;
275
513
  private readJSON;
276
514
  state(): Promise<string>;
@@ -279,8 +517,44 @@ declare class BrowserOAuthProvider implements OAuthClientProvider {
279
517
  * whether or not it matched, so a replayed callback can't pass twice.
280
518
  */
281
519
  verifyState(returned: string | undefined): Promise<boolean>;
520
+ /** The stored client, without our stamp, and how it was registered. */
521
+ private readClient;
522
+ private kindOf;
523
+ /**
524
+ * May this provider use the stored client? Under `'auto'` any; under `'cimd'`
525
+ * only the configured document itself; under `'dcr'` only one that was not
526
+ * registered by a document.
527
+ */
528
+ private fits;
529
+ /** The client and the tokens issued to it go together: a token belongs to a client. */
530
+ private forgetClient;
531
+ /**
532
+ * Under `'cimd'` / `'dcr'`, before the first read of the client or a token: a
533
+ * stored client of the other kind (registered under another setting) is
534
+ * forgotten with its tokens, so the setting is never served by the old
535
+ * client - not even by its access token, which the transport would otherwise
536
+ * keep sending until it expires. Once per provider (its setting is fixed); a
537
+ * failure is not remembered.
538
+ */
539
+ private settle;
540
+ /**
541
+ * `'cimd'` with no usable client: the SDK is about to choose between the
542
+ * document and a dynamic registration, by the authorization server metadata
543
+ * it has just saved (`saveDiscoveryState` comes first). Without support it
544
+ * would register - so it is stopped HERE, before any request is made, and
545
+ * what discovery found is forgotten, so the next attempt reads the server's
546
+ * metadata again (a server that starts supporting CIMD is noticed).
547
+ */
548
+ private assertCimdSupported;
282
549
  clientInformation(): Promise<OAuthClientInformationMixed | undefined>;
283
550
  saveClientInformation(info: OAuthClientInformationMixed): Promise<void>;
551
+ /**
552
+ * How the stored client was registered: `'cimd'` (its `client_id` is the
553
+ * client ID metadata document), `'dcr'` (registered dynamically - or saved by
554
+ * the host), or undefined when there is none this provider would use. Read it
555
+ * after a sign-in to show the user which way was taken.
556
+ */
557
+ registrationKind(): Promise<McpOAuthRegistrationKind | undefined>;
284
558
  tokens(): Promise<OAuthTokens | undefined>;
285
559
  saveTokens(tokens: OAuthTokens): Promise<void>;
286
560
  saveCodeVerifier(verifier: string): Promise<void>;
@@ -296,11 +570,13 @@ declare class BrowserOAuthProvider implements OAuthClientProvider {
296
570
  redirectToAuthorization(url: URL): Promise<void>;
297
571
  /**
298
572
  * Called by the SDK when the server rejects what we hold: `'tokens'` after an
299
- * `invalid_grant` (dead refresh token), `'all'` after an `invalid_client`
300
- * (the AS forgot our dynamic registration). `'client'`, `'verifier'` and
301
- * `'discovery'` are in its type and handled the same way: one key each.
302
- * Clearing lets the SDK re-discover, re-register and re-authorize without the
303
- * user clearing site data.
573
+ * `invalid_grant` (dead refresh token); `'client'` and then `'tokens'` after
574
+ * an `invalid_client` (the AS forgot our dynamic registration) - what
575
+ * discovery found is kept on purpose, the SDK checks the next callback
576
+ * against it. `'verifier'` and `'discovery'` are in its type and handled the
577
+ * same way: one key each. `'all'` is what {@link reset} asks for. Clearing
578
+ * lets the SDK re-register and re-authorize without the user clearing site
579
+ * data.
304
580
  */
305
581
  invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier' | 'discovery'): Promise<void>;
306
582
  /** True when there is no access token, or it expires within the skew window. */
@@ -340,6 +616,12 @@ declare const readOAuthCallback: (input?: string | URL) => McpOAuthCallback | un
340
616
  * an error, when `state` doesn't match what we issued, when `iss` names another
341
617
  * authorization server, or when the exchange fails — never resolves on a
342
618
  * half-finished authorization.
619
+ *
620
+ * A flow whose discovery state is not in storage any more (started by a
621
+ * version that did not keep it, or cleared in between) is not completed: the
622
+ * code is bound to the authorization server the user was sent to, and without
623
+ * the record of which one that was the SDK refuses the exchange. Start again
624
+ * with {@link beginMcpOAuth}; stored tokens are not touched.
343
625
  */
344
626
  declare const finishMcpOAuth: (provider: BrowserOAuthProvider, callback: McpOAuthCallback, opts?: McpOAuthRequestOptions) => Promise<void>;
345
627
  /**
@@ -661,5 +943,5 @@ declare class BrowserEnterpriseOAuthProvider implements OAuthClientProvider {
661
943
  /** Convenience factory mirroring the rest of the package's `createX` style. */
662
944
  declare const createEnterpriseOAuthProvider: (opts: EnterpriseOAuthProviderOptions) => BrowserEnterpriseOAuthProvider;
663
945
 
664
- export { BrowserEnterpriseOAuthProvider, BrowserOAuthProvider, ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION, EnterpriseOAuthError, MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER, MCP_INSTRUCTIONS_MAX_CHARS_TOTAL, MemoryOAuthStorage, VaultOAuthStorage, beginMcpOAuth, checkAuthorizationResponseIssuer, connectMcpHttp, createEnterpriseOAuthProvider, diagnoseMcpCors, finishMcpOAuth, flattenContent, readOAuthCallback, renderMcpInstructions };
665
- export type { BrowserOAuthProviderOptions, ConnectMcpOptions, ConnectedMcp, EnterpriseAssertionAlgorithm, EnterpriseAssertionAudience, EnterpriseAssertionType, EnterpriseIdpOptions, EnterpriseOAuthHop, EnterpriseOAuthLog, EnterpriseOAuthProviderOptions, EnterprisePrivateKey, McpCatalogEntry, McpHttpServerConfig, McpOAuthCallback, McpOAuthRequestOptions, McpOAuthStorage, McpServerInstructions, McpServerResult };
946
+ export { BrowserEnterpriseOAuthProvider, BrowserOAuthProvider, ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION, EnterpriseOAuthError, MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER, MCP_INSTRUCTIONS_MAX_CHARS_TOTAL, MCP_MODERN_PROTOCOL_VERSION, MCP_MODERN_REQUEST_HEADERS, McpAppDownloadResource, McpAppResource, McpAppToolResult, McpAppVisibility, McpElicitationHandler, McpElicitationOptions, MemoryOAuthStorage, VaultOAuthStorage, beginMcpOAuth, checkAuthorizationResponseIssuer, connectMcpHttp, createEnterpriseOAuthProvider, diagnoseMcpCors, finishMcpOAuth, flattenContent, readOAuthCallback, renderMcpInstructions };
947
+ export type { BrowserOAuthProviderOptions, ConnectMcpOptions, ConnectedMcp, EnterpriseAssertionAlgorithm, EnterpriseAssertionAudience, EnterpriseAssertionType, EnterpriseIdpOptions, EnterpriseOAuthHop, EnterpriseOAuthLog, EnterpriseOAuthProviderOptions, EnterprisePrivateKey, McpAppTool, McpAppsConnection, McpCatalogEntry, McpHttpServerConfig, McpOAuthCallback, McpOAuthRegistration, McpOAuthRegistrationKind, McpOAuthRequestOptions, McpOAuthStorage, McpProtocolMode, McpServerInstructions, McpServerProtocol, McpServerResult };