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