@dudko.dev/agent-web 0.0.37 → 0.0.39

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 (39) hide show
  1. package/README.md +179 -7
  2. package/dist/agent-web.js +315 -125
  3. package/dist/agent-web.js.map +1 -1
  4. package/dist/{chunk-Y7OGKYE5.js → chunk-3V27UZT6.js} +35 -9
  5. package/dist/chunk-3V27UZT6.js.map +1 -0
  6. package/dist/chunk-A6ZJALLU.js +254 -0
  7. package/dist/chunk-A6ZJALLU.js.map +1 -0
  8. package/dist/chunk-CTXDKSDD.js +39 -0
  9. package/dist/chunk-CTXDKSDD.js.map +1 -0
  10. package/dist/chunk-TZITKUFW.js +800 -0
  11. package/dist/chunk-TZITKUFW.js.map +1 -0
  12. package/dist/chunk-V3JOK7EW.js +929 -0
  13. package/dist/chunk-V3JOK7EW.js.map +1 -0
  14. package/dist/index.cjs +7253 -2159
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +1714 -324
  17. package/dist/index.d.ts +1714 -324
  18. package/dist/index.js +3832 -862
  19. package/dist/index.js.map +1 -1
  20. package/dist/mcp.cjs +1031 -24
  21. package/dist/mcp.cjs.map +1 -1
  22. package/dist/mcp.d.cts +409 -13
  23. package/dist/mcp.d.ts +409 -13
  24. package/dist/mcp.js +918 -26
  25. package/dist/mcp.js.map +1 -1
  26. package/dist/sandbox-KG6OUG24.js +269 -0
  27. package/dist/sandbox-KG6OUG24.js.map +1 -0
  28. package/dist/sandbox-worker.cjs +745 -0
  29. package/dist/sandbox-worker.cjs.map +1 -0
  30. package/dist/sandbox-worker.d.cts +37 -0
  31. package/dist/sandbox-worker.d.ts +37 -0
  32. package/dist/sandbox-worker.js +27 -0
  33. package/dist/sandbox-worker.js.map +1 -0
  34. package/dist/{webllm-PCPDLDQA.js → webllm-BEL5A4OF.js} +2 -2
  35. package/package.json +23 -4
  36. package/dist/chunk-CPSDKXO6.js +0 -132
  37. package/dist/chunk-CPSDKXO6.js.map +0 -1
  38. package/dist/chunk-Y7OGKYE5.js.map +0 -1
  39. /package/dist/{webllm-PCPDLDQA.js.map → webllm-BEL5A4OF.js.map} +0 -0
package/dist/mcp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
1
+ import { OAuthClientProvider, OAuthDiscoveryState } from '@modelcontextprotocol/sdk/client/auth.js';
2
2
  export { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js';
3
3
  import { StreamableHTTPReconnectionOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
4
4
  import { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
@@ -6,6 +6,34 @@ import { ToolSet } from 'ai';
6
6
  import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
7
7
  import { VaultOptions } from './index.js';
8
8
 
9
+ /**
10
+ * 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.
12
+ *
13
+ * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-shared.ts`) and
14
+ * `@dudko.dev/agent-web` (`src/mcp/shared.ts`): change both. The Node package's
15
+ * `tests/mcp-shared.test.ts` compares the two files and tests every cap and guard here.
16
+ */
17
+ /** The `instructions` one connected MCP server returned in its `initialize` result. */
18
+ interface McpServerInstructions {
19
+ /** The server's name: its key in the host's configuration. */
20
+ server: string;
21
+ instructions: string;
22
+ }
23
+ /** The most one server's instructions take in a system prompt, in characters. */
24
+ declare const MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER = 2000;
25
+ /** The most all servers' instructions take together, in characters. */
26
+ declare const MCP_INSTRUCTIONS_MAX_CHARS_TOTAL = 8000;
27
+ /**
28
+ * The system-prompt section for the servers' instructions, or '' when no server sent any (the
29
+ * prompt is then exactly what it was). Each server's text is capped
30
+ * (MCP_INSTRUCTIONS_MAX_CHARS_PER_SERVER), so is the sum (MCP_INSTRUCTIONS_MAX_CHARS_TOTAL, in
31
+ * the order given: a server past the total is named as omitted), and every line of it is
32
+ * prefixed with "| ", so a server cannot write something that reads as a heading of this prompt
33
+ * or as another server's note.
34
+ */
35
+ declare const renderMcpInstructions: (list: readonly McpServerInstructions[] | undefined) => string;
36
+
9
37
  /**
10
38
  * A remote MCP server reached over StreamableHTTP. Browsers can ONLY speak the
11
39
  * HTTP transport — stdio (child processes) is Node-only and intentionally
@@ -63,6 +91,15 @@ interface ConnectedMcp {
63
91
  catalog: McpCatalogEntry[];
64
92
  /** Per-server connect outcome. */
65
93
  results: McpServerResult[];
94
+ /**
95
+ * The `instructions` each connected server returned in its `initialize`
96
+ * result, in declaration order; servers that sent none are absent. Read once
97
+ * per connection. Third-party text: the agent shows it to the model under a
98
+ * preamble that says so (`config.mcpInstructions`, on by default) — each
99
+ * mounted tool carries its server's instructions, so merging `tools` into
100
+ * the agent's config is all a host does.
101
+ */
102
+ instructions: McpServerInstructions[];
66
103
  /**
67
104
  * Re-list one server's tools and rewrite its entries in `tools`/`catalog`.
68
105
  * Both are mutated in place, so anything holding a reference (including a
@@ -119,7 +156,8 @@ declare const connectMcpHttp: (servers: Record<string, McpHttpServerConfig>, opt
119
156
 
120
157
  /**
121
158
  * Browser-side OAuth 2.1 for remote MCP servers: Dynamic Client Registration
122
- * (RFC 7591), PKCE authorization-code flow, and refresh-token rotation.
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).
123
161
  *
124
162
  * The heavy lifting lives in the MCP SDK — `auth()` discovers the protected
125
163
  * resource (RFC 9728), registers the client if we have no client_id yet,
@@ -174,8 +212,19 @@ interface BrowserOAuthProviderOptions {
174
212
  clientName?: string;
175
213
  /** Fallback scope when the server's metadata advertises none. */
176
214
  scope?: string;
177
- /** Merged over the defaults; use it for `software_id`, `contacts`, … */
178
- clientMetadata?: Partial<OAuthClientMetadata>;
215
+ /** Merged over the defaults; use it for `software_id`, `contacts`, `application_type`, … */
216
+ clientMetadata?: Partial<OAuthClientMetadata> & {
217
+ application_type?: string;
218
+ };
219
+ /**
220
+ * URL of a client ID metadata document (CIMD) you host. When the
221
+ * authorization server advertises `client_id_metadata_document_supported`,
222
+ * this URL is used as the `client_id` and no dynamic registration is made;
223
+ * otherwise registration runs as before. A registration already in storage
224
+ * 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`.
226
+ */
227
+ clientMetadataUrl?: string;
179
228
  /** Defaults to the encrypted IndexedDB vault. */
180
229
  storage?: McpOAuthStorage;
181
230
  /** Treat an access token as expired this many seconds early. Default 30. */
@@ -183,6 +232,25 @@ interface BrowserOAuthProviderOptions {
183
232
  /** Called when the SDK wants the user at the authorization server. */
184
233
  onRedirect?: (url: URL) => void | Promise<void>;
185
234
  }
235
+ /**
236
+ * RFC 9207: is the `iss` parameter of an authorization response the
237
+ * authorization server this flow was started with? Throws when it is not; the
238
+ * caller must not exchange the code then (a mix-up attack hands the code of an
239
+ * honest server to another one's token endpoint).
240
+ *
241
+ * - expected issuer: the `issuer` of the stored authorization server metadata,
242
+ * else the authorization server URL discovery used;
243
+ * - `iss` present: it must equal the expected issuer, compared as plain strings
244
+ * (RFC 9207 section 2.4: no normalization);
245
+ * - `iss` absent: refused when the metadata says
246
+ * `authorization_response_iss_parameter_supported: true`;
247
+ * - no stored discovery state (storage written by an older version): `iss` is
248
+ * compared with the issuer stamped on the stored client information, and with
249
+ * nothing to compare against the response is accepted.
250
+ *
251
+ * The Node package carries the same function; change both.
252
+ */
253
+ declare const checkAuthorizationResponseIssuer: (iss: string | undefined, discoveryState: OAuthDiscoveryState | undefined, clientIssuer?: string) => void;
186
254
  /**
187
255
  * An `OAuthClientProvider` (MCP SDK) that persists everything it is handed and
188
256
  * never navigates behind your back. One instance per MCP server.
@@ -195,11 +263,14 @@ declare class BrowserOAuthProvider implements OAuthClientProvider {
195
263
  private readonly ns;
196
264
  private readonly _redirectUrl;
197
265
  private readonly _clientMetadata;
266
+ private readonly _clientMetadataUrl?;
198
267
  private readonly skewMs;
199
268
  private readonly onRedirect?;
200
269
  constructor(opts: BrowserOAuthProviderOptions);
201
270
  get redirectUrl(): string;
202
271
  get clientMetadata(): OAuthClientMetadata;
272
+ /** The client ID metadata document URL (CIMD), when one was configured. */
273
+ get clientMetadataUrl(): string | undefined;
203
274
  private key;
204
275
  private readJSON;
205
276
  state(): Promise<string>;
@@ -214,19 +285,29 @@ declare class BrowserOAuthProvider implements OAuthClientProvider {
214
285
  saveTokens(tokens: OAuthTokens): Promise<void>;
215
286
  saveCodeVerifier(verifier: string): Promise<void>;
216
287
  codeVerifier(): Promise<string>;
288
+ /**
289
+ * What discovery found (the authorization server, its metadata, the resource
290
+ * metadata). The SDK reuses it instead of discovering again - after the
291
+ * redirect back too - and {@link finishMcpOAuth} reads the expected issuer
292
+ * from it.
293
+ */
294
+ saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
295
+ discoveryState(): Promise<OAuthDiscoveryState | undefined>;
217
296
  redirectToAuthorization(url: URL): Promise<void>;
218
297
  /**
219
298
  * Called by the SDK when the server rejects what we hold: `'tokens'` after an
220
- * `invalid_grant` (dead refresh token), `'client'` / `'all'` after an
221
- * `invalid_client` (the AS forgot our dynamic registration). Clearing lets
222
- * the SDK re-register and re-authorize without the user clearing site data.
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.
223
304
  */
224
305
  invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier' | 'discovery'): Promise<void>;
225
306
  /** True when there is no access token, or it expires within the skew window. */
226
307
  isAccessTokenExpired(): Promise<boolean>;
227
308
  /** True once an authorization has completed for this server. */
228
309
  isAuthorized(): Promise<boolean>;
229
- /** Forget tokens, registration, verifier and state for this server. */
310
+ /** Forget tokens, registration, verifier, state and discovery for this server. */
230
311
  reset(): Promise<void>;
231
312
  }
232
313
  interface McpOAuthRequestOptions {
@@ -240,6 +321,8 @@ interface McpOAuthRequestOptions {
240
321
  interface McpOAuthCallback {
241
322
  code?: string;
242
323
  state?: string;
324
+ /** The `iss` parameter of the response (RFC 9207), when the server sent one. */
325
+ iss?: string;
243
326
  error?: string;
244
327
  errorDescription?: string;
245
328
  }
@@ -252,9 +335,11 @@ interface McpOAuthCallback {
252
335
  declare const readOAuthCallback: (input?: string | URL) => McpOAuthCallback | undefined;
253
336
  /**
254
337
  * Finish the flow after the authorization server redirected back: verify the
255
- * `state`, exchange the code (PKCE) and persist the tokens. Throws when the AS
256
- * returned an error, when `state` doesn't match what we issued, or when the
257
- * exchange fails — never resolves on a half-finished authorization.
338
+ * `state`, then the issuer (RFC 9207, {@link checkAuthorizationResponseIssuer}),
339
+ * exchange the code (PKCE) and persist the tokens. Throws when the AS returned
340
+ * an error, when `state` doesn't match what we issued, when `iss` names another
341
+ * authorization server, or when the exchange fails — never resolves on a
342
+ * half-finished authorization.
258
343
  */
259
344
  declare const finishMcpOAuth: (provider: BrowserOAuthProvider, callback: McpOAuthCallback, opts?: McpOAuthRequestOptions) => Promise<void>;
260
345
  /**
@@ -265,5 +350,316 @@ declare const finishMcpOAuth: (provider: BrowserOAuthProvider, callback: McpOAut
265
350
  */
266
351
  declare const beginMcpOAuth: (provider: BrowserOAuthProvider, opts?: McpOAuthRequestOptions) => Promise<"AUTHORIZED" | "REDIRECT">;
267
352
 
268
- export { BrowserOAuthProvider, MemoryOAuthStorage, VaultOAuthStorage, beginMcpOAuth, connectMcpHttp, diagnoseMcpCors, finishMcpOAuth, flattenContent, readOAuthCallback };
269
- export type { BrowserOAuthProviderOptions, ConnectMcpOptions, ConnectedMcp, McpCatalogEntry, McpHttpServerConfig, McpOAuthCallback, McpOAuthRequestOptions, McpOAuthStorage, McpServerResult };
353
+ /**
354
+ * Enterprise-Managed Authorization for remote MCP servers (the MCP extension
355
+ * `io.modelcontextprotocol/enterprise-managed-authorization`, also called Cross
356
+ * App Access): the organization's identity provider decides which MCP servers
357
+ * a user's client may reach, and no one is sent to a consent page.
358
+ *
359
+ * Two hops, both plain HTTP POSTs:
360
+ *
361
+ * 1. at the IdP - an RFC 8693 token exchange turns the user's ID token into an
362
+ * Identity Assertion JWT Authorization Grant (ID-JAG) addressed to the MCP
363
+ * server's authorization server;
364
+ * 2. at the MCP authorization server - an RFC 7523 `jwt-bearer` grant turns the
365
+ * ID-JAG into an ordinary access token.
366
+ *
367
+ * The MCP SDK owns discovery (RFC 9728 / RFC 8414), the second hop and the
368
+ * retry on a 401; this module supplies the first hop and the checks around it.
369
+ * Only the resulting access token is stored. The ID token, the ID-JAG and the
370
+ * client assertions pass through memory and are never written, logged or put
371
+ * in an error.
372
+ *
373
+ * The client authenticates on each hop with a secret or with a signed
374
+ * assertion (`private_key_jwt`, RFC 7523 section 2.2). By default the audience
375
+ * of that assertion is the issuer identifier of the server it is for and
376
+ * nothing else, as draft-ietf-oauth-rfc7523bis requires: an assertion made for
377
+ * the IdP is of no use at the authorization server, and the other way round.
378
+ * For a server built to RFC 7523 as published, `assertionAudience:
379
+ * 'token-endpoint'` and `assertionType: 'JWT'` produce the older form - see
380
+ * `EnterpriseAssertionAudience` for what that gives up.
381
+ *
382
+ * Follows draft-ietf-oauth-identity-assertion-authz-grant and the extension's
383
+ * 2026-07-28 revision. The Node package carries the same provider; change both.
384
+ *
385
+ * In a browser the IdP's token endpoint must allow this page's origin (CORS),
386
+ * and a `clientSecret` in a page is readable by anyone who can open the page:
387
+ * see docs/security.md before using one here.
388
+ *
389
+ * Pass the result to `connectMcpHttp`'s `servers[name].authProvider`.
390
+ */
391
+ /** The extension identifier a client declares in its capabilities. */
392
+ declare const ENTERPRISE_MANAGED_AUTHORIZATION_EXTENSION = "io.modelcontextprotocol/enterprise-managed-authorization";
393
+ /** Which part of the flow refused. */
394
+ type EnterpriseOAuthHop = 'discovery' | 'idp' | 'authorization-server';
395
+ /**
396
+ * A failure of the enterprise flow, with the hop that refused: `'discovery'`
397
+ * (what the MCP server published cannot be trusted or used), `'idp'` (the token
398
+ * exchange) or `'authorization-server'` (the `jwt-bearer` grant). The message
399
+ * is short and safe to show: never a request body, a token, an assertion, a
400
+ * secret or a key. What the authorization server said in full goes to the log
401
+ * (`onLog`), redacted the same way.
402
+ */
403
+ declare class EnterpriseOAuthError extends Error {
404
+ readonly hop: EnterpriseOAuthHop;
405
+ /** The OAuth `error` code the server answered with, when it sent one. */
406
+ readonly code?: string;
407
+ constructor(hop: EnterpriseOAuthHop, message: string, code?: string);
408
+ }
409
+ /** Signature algorithms for a `private_key_jwt` client assertion. */
410
+ type EnterpriseAssertionAlgorithm = 'ES256' | 'ES384' | 'ES512' | 'RS256' | 'RS384' | 'RS512' | 'PS256' | 'PS384' | 'PS512';
411
+ /**
412
+ * The private key that signs a client assertion: a `CryptoKey` (best: import
413
+ * or generate it as non-extractable, so page script can use it but not read
414
+ * it) or a JWK object. It must be a key for the chosen `algorithm` (an ECDSA
415
+ * P-256 key for ES256, an RSASSA-PKCS1-v1_5 key for RS256, RSA-PSS for PS256...).
416
+ */
417
+ type EnterprisePrivateKey = JsonWebKey | CryptoKey;
418
+ /**
419
+ * What a `private_key_jwt` client assertion names as its audience (`aud`).
420
+ *
421
+ * - `'issuer'` (the default): the issuer identifier of the server the
422
+ * assertion is for, as draft-ietf-oauth-rfc7523bis requires.
423
+ * - `'token-endpoint'`: the URL of that server's token endpoint, which is what
424
+ * RFC 7523 as published describes and what many deployed identity providers
425
+ * check for.
426
+ *
427
+ * The default is the issuer because an assertion addressed to a token endpoint
428
+ * URL is exactly what the bis draft forbids. The token endpoint is one field of
429
+ * a metadata document; a client that reads its audience from metadata can be
430
+ * handed a document that names an honest server's endpoint (audience
431
+ * injection), and then signs an assertion the party that served the document
432
+ * can replay at that honest server. The issuer identifier is the one value a
433
+ * client checks before it trusts the rest of the document. This provider never
434
+ * takes either value from the MCP server alone - the IdP's endpoint is
435
+ * configuration, and the authorization server's is used only after its
436
+ * metadata matched `expectedIssuer` - so `'token-endpoint'` here costs the
437
+ * defence in depth, not the check itself. Use it only for a server that
438
+ * refuses the issuer form.
439
+ */
440
+ type EnterpriseAssertionAudience = 'issuer' | 'token-endpoint';
441
+ /**
442
+ * The `typ` header of a client assertion: `client-authentication+jwt` (the
443
+ * default, from draft-ietf-oauth-rfc7523bis: a token typed this way cannot be
444
+ * mistaken for another kind of JWT) or `JWT`, for a server that refuses a
445
+ * `typ` it does not know.
446
+ */
447
+ type EnterpriseAssertionType = 'client-authentication+jwt' | 'JWT';
448
+ /** Where the provider reports what it will not put in an error. */
449
+ type EnterpriseOAuthLog = (level: 'info' | 'warn' | 'error', message: string) => void;
450
+ interface EnterpriseIdpOptions {
451
+ /**
452
+ * The IdP's token endpoint, where the token exchange is posted. Configured,
453
+ * not discovered: it is where the user's ID token and the client's IdP
454
+ * credentials go, so nothing fetched at run time may choose it.
455
+ */
456
+ tokenEndpoint: string;
457
+ /**
458
+ * The IdP's issuer identifier. REQUIRED with `private_key_jwt`, where it is
459
+ * the audience of the client assertion - unless `assertionAudience` is
460
+ * `'token-endpoint'`, which addresses the assertion to `tokenEndpoint`.
461
+ */
462
+ issuer?: string;
463
+ /** This client's `client_id` at the IdP (the audience of the ID token). */
464
+ clientId: string;
465
+ /**
466
+ * This client's secret at the IdP. Omit for a client the IdP treats as
467
+ * public. In a browser it is readable by anyone who can open the page: leave
468
+ * it out and pass a `fetch` that sends this request through your backend.
469
+ */
470
+ clientSecret?: string;
471
+ /**
472
+ * How the client authenticates at the IdP. With a secret: in an
473
+ * `Authorization: Basic` header (the default, which every OAuth server must
474
+ * accept) or in the form body. `'private_key_jwt'`: a signed assertion, which
475
+ * needs `privateKey`, `algorithm` and `issuer` (or `assertionAudience:
476
+ * 'token-endpoint'`).
477
+ */
478
+ clientAuthMethod?: 'client_secret_basic' | 'client_secret_post' | 'private_key_jwt';
479
+ /** The key for `private_key_jwt`. Never stored, logged or put in an error. */
480
+ privateKey?: EnterprisePrivateKey;
481
+ /** `kid` header of the assertion: the key's id in the JWKS the IdP holds. */
482
+ keyId?: string;
483
+ /** Signature algorithm of the assertion. */
484
+ algorithm?: EnterpriseAssertionAlgorithm;
485
+ /**
486
+ * The audience of the assertion: `'issuer'` (the default: `issuer`) or
487
+ * `'token-endpoint'` (`tokenEndpoint`, for an IdP built to RFC 7523 - the
488
+ * weaker form, see `EnterpriseAssertionAudience`). Only with `private_key_jwt`.
489
+ */
490
+ assertionAudience?: EnterpriseAssertionAudience;
491
+ /**
492
+ * The `typ` header of the assertion: `'client-authentication+jwt'` (the
493
+ * default) or `'JWT'` for an IdP that refuses the new one. Only with
494
+ * `private_key_jwt`.
495
+ */
496
+ assertionType?: EnterpriseAssertionType;
497
+ }
498
+ interface EnterpriseOAuthProviderOptions {
499
+ /** The MCP endpoint being authorized. */
500
+ serverUrl: string;
501
+ /**
502
+ * This client's `client_id` at the MCP server's authorization server: a
503
+ * pre-registered identifier, or the https URL of a client ID metadata
504
+ * document (CIMD) you host. A URL must be https with a path of its own, and
505
+ * cannot be used with `clientSecret`: a document anyone can read establishes
506
+ * no shared secret, so such a client is public or uses `private_key_jwt`
507
+ * with the keys the document lists (`jwks` / `jwks_uri`).
508
+ */
509
+ clientId: string;
510
+ /**
511
+ * Its secret there. The grant is meant for confidential clients. A secret
512
+ * needs `expectedIssuer`: without it the MCP server's metadata would choose
513
+ * who receives the secret, and the constructor throws.
514
+ *
515
+ * In a browser a secret is readable by anyone who can open the page. This
516
+ * provider is for public clients there, or for a `fetch` that routes the IdP
517
+ * call through your backend, which holds the secret.
518
+ */
519
+ clientSecret?: string;
520
+ /**
521
+ * How the client authenticates at the authorization server. Left out, the
522
+ * SDK decides: a secret is sent the way the server's metadata allows (Basic
523
+ * first), no secret means `client_id` alone. `'private_key_jwt'` signs an
524
+ * assertion and needs `privateKey`, `algorithm` and `expectedIssuer`.
525
+ */
526
+ clientAuthMethod?: 'client_secret_basic' | 'client_secret_post' | 'private_key_jwt' | 'none';
527
+ /** The key for `private_key_jwt`. Never stored, logged or put in an error. */
528
+ privateKey?: EnterprisePrivateKey;
529
+ /** `kid` header of the assertion: the key's id in the JWKS the server holds. */
530
+ keyId?: string;
531
+ /** Signature algorithm of the assertion. */
532
+ algorithm?: EnterpriseAssertionAlgorithm;
533
+ /**
534
+ * The audience of the assertion for the authorization server: `'issuer'`
535
+ * (the default: the issuer discovery found, once it matched
536
+ * `expectedIssuer`) or `'token-endpoint'` (the token endpoint from that same
537
+ * metadata, for a server built to RFC 7523 - the weaker form, see
538
+ * `EnterpriseAssertionAudience`). The endpoint is read only from metadata
539
+ * whose issuer is `expectedIssuer`, and must be https or loopback. Only with
540
+ * `private_key_jwt`.
541
+ */
542
+ assertionAudience?: EnterpriseAssertionAudience;
543
+ /**
544
+ * The `typ` header of the assertion: `'client-authentication+jwt'` (the
545
+ * default) or `'JWT'` for a server that refuses the new one. Only with
546
+ * `private_key_jwt`.
547
+ */
548
+ assertionType?: EnterpriseAssertionType;
549
+ /**
550
+ * The issuer of the MCP server's authorization server. Anything else the MCP
551
+ * server points at is refused before a credential leaves the process.
552
+ * REQUIRED with `clientSecret` and with `private_key_jwt`: neither the
553
+ * receiver of a secret nor the audience of a signed assertion may come from
554
+ * the MCP server's metadata alone. A client with no credential at the
555
+ * authorization server may omit it: then the only thing sent there is the
556
+ * ID-JAG, which the IdP addressed to that one server and which is of no use
557
+ * to any other.
558
+ */
559
+ expectedIssuer?: string;
560
+ /** The enterprise identity provider. */
561
+ idp: EnterpriseIdpOptions;
562
+ /**
563
+ * The user's OpenID Connect ID token from the IdP. How it was obtained (the
564
+ * single sign-on of your application) is yours; it is called each time a new
565
+ * ID-JAG is needed, so return a current one. The value is never stored.
566
+ */
567
+ getIdToken: () => string | Promise<string>;
568
+ /** Scopes to ask the IdP for (space-separated). */
569
+ scope?: string;
570
+ /** Defaults to the encrypted IndexedDB vault. Holds the access token only. */
571
+ storage?: McpOAuthStorage;
572
+ /** Treat the access token as expired this many seconds early. Default 30. */
573
+ expirySkewSeconds?: number;
574
+ /** Custom fetch for the request to the IdP. */
575
+ fetch?: FetchLike;
576
+ /**
577
+ * Receives the detail a refusal's error leaves out (what the authorization
578
+ * server answered), redacted. `connectMcpHttp` passes its `onLog`; this is
579
+ * for a provider used without it. With neither, it goes to the package's
580
+ * logger at `warn` (`[agent-web]` on the console).
581
+ */
582
+ onLog?: EnterpriseOAuthLog;
583
+ }
584
+ /**
585
+ * A non-interactive `OAuthClientProvider`: no redirect, no browser, no human.
586
+ * On first use, and whenever the access token is missing, expired or rejected,
587
+ * the SDK asks it for a token request and it answers with a fresh ID-JAG.
588
+ */
589
+ declare class BrowserEnterpriseOAuthProvider implements OAuthClientProvider {
590
+ #private;
591
+ readonly serverUrl: string;
592
+ /** The MCP extension this provider implements; the connector declares it. */
593
+ readonly extension = "io.modelcontextprotocol/enterprise-managed-authorization";
594
+ /**
595
+ * Present only with an explicit `clientAuthMethod`: the SDK then leaves the
596
+ * client authentication of the grant to it (a `private_key_jwt` assertion is
597
+ * signed here, for the issuer discovery found and `expectedIssuer` confirmed).
598
+ */
599
+ addClientAuthentication?: OAuthClientProvider['addClientAuthentication'];
600
+ constructor(opts: EnterpriseOAuthProviderOptions);
601
+ /** Never set: this is what tells the SDK the flow has no human step. */
602
+ get redirectUrl(): undefined;
603
+ get clientMetadata(): OAuthClientMetadata;
604
+ /**
605
+ * The pre-registered client, from configuration and never from storage.
606
+ * With `expectedIssuer` it carries that stamp, and the SDK then refuses to
607
+ * present it to any other authorization server.
608
+ */
609
+ clientInformation(): OAuthClientInformationMixed;
610
+ tokens(): Promise<OAuthTokens | undefined>;
611
+ saveTokens(tokens: OAuthTokens): Promise<void>;
612
+ saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>;
613
+ discoveryState(): Promise<OAuthDiscoveryState | undefined>;
614
+ /**
615
+ * Called by the SDK inside `auth()`, after discovery and before the token
616
+ * request to the MCP authorization server: get an ID token from the host,
617
+ * exchange it at the IdP for an ID-JAG addressed to exactly the authorization
618
+ * server and resource discovery found for this server, and hand the SDK the
619
+ * `jwt-bearer` request. Throws before anything reaches the authorization
620
+ * server when discovery cannot be trusted or the IdP's answer is not an ID-JAG.
621
+ */
622
+ prepareTokenRequest(scope?: string): Promise<URLSearchParams>;
623
+ /** The codes of the interactive flow: this provider has none. */
624
+ redirectToAuthorization(): never;
625
+ saveCodeVerifier(): never;
626
+ codeVerifier(): never;
627
+ /**
628
+ * Called by the SDK when the authorization server rejects what it was sent.
629
+ * The client is configuration, so there is nothing of it to forget; tokens
630
+ * and discovery are dropped as asked.
631
+ */
632
+ invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier' | 'discovery'): Promise<void>;
633
+ /** True when there is no access token, or it expires within the skew window. */
634
+ isAccessTokenExpired(): Promise<boolean>;
635
+ isAuthorized(): Promise<boolean>;
636
+ /**
637
+ * The fetch to give the transport that carries this provider (the connector
638
+ * does). It changes one thing: when the request that carries the ID-JAG is
639
+ * refused, the caller gets an `EnterpriseOAuthError` (`hop:
640
+ * 'authorization-server'`) with a short message - the OAuth error code and
641
+ * the status - and what the server said in full goes to `log`, redacted.
642
+ * That holds whenever the SDK asks for a token, at connect or in the middle
643
+ * of a session, so an application never has the server's raw words to show.
644
+ * A refusal is final: every grant is already a fresh one, so the SDK's
645
+ * "drop the token and try again" would only repeat the IdP exchange.
646
+ */
647
+ transportFetch(base?: FetchLike, log?: EnterpriseOAuthLog): FetchLike;
648
+ /**
649
+ * Run the whole flow now (discovery, IdP exchange, grant) and store the
650
+ * access token. `connectMcpHttp` calls it before connecting when there is
651
+ * no usable token; call it yourself to fail early. A refusal is an
652
+ * `EnterpriseOAuthError` whose `hop` says who refused.
653
+ */
654
+ authorize(opts?: {
655
+ fetch?: FetchLike;
656
+ onLog?: EnterpriseOAuthLog;
657
+ }): Promise<void>;
658
+ /** Forget the access token and what discovery found for this server. */
659
+ reset(): Promise<void>;
660
+ }
661
+ /** Convenience factory mirroring the rest of the package's `createX` style. */
662
+ declare const createEnterpriseOAuthProvider: (opts: EnterpriseOAuthProviderOptions) => BrowserEnterpriseOAuthProvider;
663
+
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 };