@nest-mcp/client 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +845 -69
  3. package/dist/ai-sdk/index.d.mts +14 -0
  4. package/dist/ai-sdk/index.d.mts.map +1 -0
  5. package/dist/ai-sdk/index.mjs +27 -0
  6. package/dist/ai-sdk/index.mjs.map +1 -0
  7. package/dist/bootstrap-BIAcDnHp.d.mts +394 -0
  8. package/dist/bootstrap-BIAcDnHp.d.mts.map +1 -0
  9. package/dist/index.d.mts +480 -0
  10. package/dist/index.d.mts.map +1 -0
  11. package/dist/index.mjs +1960 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/dist/oauth/dynamic-registration.d.mts +92 -0
  14. package/dist/oauth/dynamic-registration.d.mts.map +1 -0
  15. package/dist/oauth/dynamic-registration.mjs +392 -0
  16. package/dist/oauth/dynamic-registration.mjs.map +1 -0
  17. package/dist/oauth/index.d.mts +422 -0
  18. package/dist/oauth/index.d.mts.map +1 -0
  19. package/dist/oauth/index.mjs +3349 -0
  20. package/dist/oauth/index.mjs.map +1 -0
  21. package/dist/scope-CxGBCDdr.mjs +22 -0
  22. package/dist/scope-CxGBCDdr.mjs.map +1 -0
  23. package/package.json +76 -50
  24. package/scripts/external-smoke.mjs +693 -0
  25. package/dist/decorators/inject-mcp-client.decorator.d.ts +0 -3
  26. package/dist/decorators/inject-mcp-client.decorator.js +0 -12
  27. package/dist/decorators/on-notification.decorator.d.ts +0 -7
  28. package/dist/decorators/on-notification.decorator.js +0 -13
  29. package/dist/health/mcp-client.health.d.ts +0 -20
  30. package/dist/health/mcp-client.health.js +0 -42
  31. package/dist/index.d.ts +0 -21
  32. package/dist/index.js +0 -64
  33. package/dist/interfaces/client-options.interface.d.ts +0 -139
  34. package/dist/interfaces/client-options.interface.js +0 -3
  35. package/dist/mcp-client.module.d.ts +0 -20
  36. package/dist/mcp-client.module.js +0 -188
  37. package/dist/mcp-client.service.d.ts +0 -558
  38. package/dist/mcp-client.service.js +0 -532
  39. package/dist/mcp-clients.service.d.ts +0 -39
  40. package/dist/mcp-clients.service.js +0 -104
  41. package/dist/testing/mock-client.d.ts +0 -67
  42. package/dist/testing/mock-client.js +0 -154
  43. package/dist/transport/apply-auth-headers.d.ts +0 -3
  44. package/dist/transport/apply-auth-headers.js +0 -13
  45. package/dist/transport/client-transport.factory.d.ts +0 -4
  46. package/dist/transport/client-transport.factory.js +0 -21
  47. package/dist/transport/sse-client.transport.d.ts +0 -4
  48. package/dist/transport/sse-client.transport.js +0 -15
  49. package/dist/transport/stdio-client.transport.d.ts +0 -4
  50. package/dist/transport/stdio-client.transport.js +0 -14
  51. package/dist/transport/streamable-client.transport.d.ts +0 -4
  52. package/dist/transport/streamable-client.transport.js +0 -17
  53. package/dist/utils/format-error-message.d.ts +0 -2
  54. package/dist/utils/format-error-message.js +0 -7
@@ -0,0 +1,422 @@
1
+ import { $ as parseOAuthCallbackParameters, A as McpClientOAuthProtocolError, B as McpOAuthCallbackError, C as McpClientOAuthClientAuthentication, D as McpClientOAuthEndpointPolicyInput, E as McpClientOAuthEndpointPolicy, F as McpClientOAuthStartAuthorizationResult, G as McpOAuthStateError, H as McpOAuthCallbackParameters, I as parseMcpClientOAuthAuthority, J as McpOAuthStateValidationInput, K as McpOAuthStateErrorCode, L as parseMcpClientOAuthAuthorizationTransaction, M as McpClientOAuthProtocolOptions, N as McpClientOAuthRefreshInput, O as McpClientOAuthExchangeAuthorizationInput, P as McpClientOAuthStartAuthorizationInput, Q as createPkceVerifier, R as McpClientOAuthSnapshotError, S as McpClientOAuthClient, T as McpClientOAuthEndpointKind, U as McpOAuthCallbackSuccess, V as McpOAuthCallbackParameterInput, W as McpOAuthPkceGenerationOptions, X as createOAuthStateLookupDigest, Y as createOAuthState, Z as createPkceS256Challenge, _ as McpClientOAuthStrictCompatibilityIssue, a as McpClientOAuthBootstrapDiscoveryResult, b as McpClientOAuthAuthority, c as McpClientOAuthBootstrapEndpointPolicyInput, d as McpClientOAuthBootstrapIssuerCandidate, et as validateOAuthState, f as McpClientOAuthBootstrapOptions, g as McpClientOAuthBootstrapStrictProtocolUnsupported, h as McpClientOAuthBootstrapSelectionRequired, i as McpClientOAuthBootstrapDiscoveryInput, j as McpClientOAuthProtocolErrorCode, k as McpClientOAuthProtocol, l as McpClientOAuthBootstrapError, m as McpClientOAuthBootstrapResource, n as McpClientOAuthBootstrapCandidate, o as McpClientOAuthBootstrapEndpointKind, p as McpClientOAuthBootstrapReady, q as McpOAuthStateGenerationOptions, r as McpClientOAuthBootstrapChallenge, s as McpClientOAuthBootstrapEndpointPolicy, t as McpClientOAuthBootstrap, u as McpClientOAuthBootstrapErrorCode, v as parseMcpClientOAuthBootstrapChallenge, w as McpClientOAuthDiscoveryInput, x as McpClientOAuthAuthorizationTransaction, y as parseMcpClientOAuthBootstrapDiscoveryResult, z as McpClientOAuthSnapshotOptions } from "../bootstrap-BIAcDnHp.mjs";
2
+ import { AddClientAuthentication, AuthProvider, AuthProvider as AuthProvider$1, AuthorizationServerMetadata, FetchLike, FetchLike as FetchLike$1, OAuthProtectedResourceMetadata, OAuthTokens } from "@modelcontextprotocol/client";
3
+ //#region src/oauth/credential-store.d.ts
4
+ declare const MCP_CLIENT_OAUTH_CREDENTIAL_REVISION: unique symbol;
5
+ /** A database-safe, positive revision used for exact credential-generation CAS. */
6
+ type McpClientOAuthCredentialRevision = number & {
7
+ readonly [MCP_CLIENT_OAUTH_CREDENTIAL_REVISION]: "McpClientOAuthCredentialRevision";
8
+ };
9
+ /** Fresh, opaque ownership proof for one durable pre-dispatch refresh claim. */
10
+ interface McpClientOAuthRefreshClaimId {
11
+ readonly value: string;
12
+ }
13
+ /** Stable reasons used for exact-generation invalidation or disappearance notification. */
14
+ declare const McpClientOAuthCredentialInvalidationReason: {
15
+ readonly Explicit: "explicit";
16
+ readonly InvalidGrant: "invalid-grant";
17
+ /** The exact generation was absent when observed, without a local invalidation mutation. */
18
+ readonly ObservedExternal: "observed-external";
19
+ readonly TerminalRefreshFailure: "terminal-refresh-failure";
20
+ };
21
+ type McpClientOAuthCredentialInvalidationReason = (typeof McpClientOAuthCredentialInvalidationReason)[keyof typeof McpClientOAuthCredentialInvalidationReason];
22
+ /** Terminal refresh reasons accepted from a refresh-failure classifier. */
23
+ type McpClientOAuthTerminalRefreshReason = typeof McpClientOAuthCredentialInvalidationReason.InvalidGrant | typeof McpClientOAuthCredentialInvalidationReason.TerminalRefreshFailure;
24
+ /**
25
+ * One authoritative credential generation.
26
+ *
27
+ * `credential` is the complete replacement set, including a rotated refresh token when one was
28
+ * returned. The wrapper is immutable; credential implementations must likewise treat their value
29
+ * as immutable and replace it atomically instead of editing it in place.
30
+ */
31
+ interface McpClientOAuthCredentialSnapshot<Credential extends object> {
32
+ readonly revision: McpClientOAuthCredentialRevision;
33
+ readonly credential: Readonly<Credential>;
34
+ }
35
+ /** Cancellation owned by the coordinator lifecycle, never by one caller waiting on shared work. */
36
+ interface McpClientOAuthCredentialStoreContext {
37
+ readonly signal: AbortSignal;
38
+ }
39
+ interface McpClientOAuthRefreshClaimed<Credential extends object> {
40
+ readonly status: "claimed";
41
+ /** The exact generation durably fenced for this claim before any refresh request is sent. */
42
+ readonly snapshot: McpClientOAuthCredentialSnapshot<Credential>;
43
+ }
44
+ interface McpClientOAuthRefreshClaimBusy {
45
+ readonly status: "busy";
46
+ }
47
+ interface McpClientOAuthRefreshClaimConflict {
48
+ readonly status: "conflict";
49
+ }
50
+ type McpClientOAuthRefreshClaimResult<Credential extends object> = McpClientOAuthRefreshClaimed<Credential> | McpClientOAuthRefreshClaimBusy | McpClientOAuthRefreshClaimConflict;
51
+ interface McpClientOAuthRefreshCommitApplied<Credential extends object> {
52
+ readonly status: "applied";
53
+ /** The authoritative, complete replacement persisted at exactly the next revision. */
54
+ readonly snapshot: McpClientOAuthCredentialSnapshot<Credential>;
55
+ }
56
+ interface McpClientOAuthRefreshCommitConflict {
57
+ readonly status: "conflict";
58
+ }
59
+ type McpClientOAuthRefreshCommitResult<Credential extends object> = McpClientOAuthRefreshCommitApplied<Credential> | McpClientOAuthRefreshCommitConflict;
60
+ interface McpClientOAuthRefreshClaimReleased {
61
+ readonly status: "released";
62
+ }
63
+ interface McpClientOAuthRefreshClaimReleaseConflict {
64
+ readonly status: "conflict";
65
+ }
66
+ type McpClientOAuthRefreshClaimReleaseResult = McpClientOAuthRefreshClaimReleased | McpClientOAuthRefreshClaimReleaseConflict;
67
+ /** Exact CAS for non-refresh credential writers such as an authorization callback. */
68
+ interface McpClientOAuthCredentialCompareAndSwapApplied<Credential extends object> {
69
+ readonly status: "applied";
70
+ readonly snapshot: McpClientOAuthCredentialSnapshot<Credential>;
71
+ }
72
+ interface McpClientOAuthCredentialCompareAndSwapConflict {
73
+ readonly status: "conflict";
74
+ }
75
+ type McpClientOAuthCredentialCompareAndSwapResult<Credential extends object> = McpClientOAuthCredentialCompareAndSwapApplied<Credential> | McpClientOAuthCredentialCompareAndSwapConflict;
76
+ interface McpClientOAuthCredentialInvalidationApplied {
77
+ readonly status: "applied";
78
+ }
79
+ interface McpClientOAuthCredentialInvalidationConflict {
80
+ readonly status: "conflict";
81
+ }
82
+ type McpClientOAuthCredentialInvalidationResult = McpClientOAuthCredentialInvalidationApplied | McpClientOAuthCredentialInvalidationConflict;
83
+ /**
84
+ * Persistence port for one opaque, non-secret OAuth credential identity.
85
+ *
86
+ * `claimRefresh` must atomically and durably transition the exact active generation to claimed
87
+ * before returning it. Only its fresh `claimId` may commit or explicitly release that claim. A
88
+ * claimed generation must never become active automatically: stale or abandoned claims are
89
+ * terminal and must be invalidated by store policy. Ambiguous claim/commit failures must leave the
90
+ * exact generation claimed or terminal, never active. A successful commit atomically stores the
91
+ * complete credential set at `expectedRevision + 1`. `invalidate` must invalidate the exact
92
+ * revision even while claimed. Conflict results must not mutate a newer generation.
93
+ */
94
+ interface McpClientOAuthCredentialStore<Identity, Credential extends object> {
95
+ /** Returns the authoritative snapshot for active or durably claimed state; absent is terminal. */
96
+ load(identity: Identity, context: McpClientOAuthCredentialStoreContext): Promise<McpClientOAuthCredentialSnapshot<Credential> | undefined>;
97
+ claimRefresh(identity: Identity, expectedRevision: McpClientOAuthCredentialRevision, claimId: McpClientOAuthRefreshClaimId, context: McpClientOAuthCredentialStoreContext): Promise<McpClientOAuthRefreshClaimResult<Credential>>;
98
+ commitRefresh(identity: Identity, expectedRevision: McpClientOAuthCredentialRevision, claimId: McpClientOAuthRefreshClaimId, credential: Readonly<Credential>, context: McpClientOAuthCredentialStoreContext): Promise<McpClientOAuthRefreshCommitResult<Credential>>;
99
+ releaseRefreshClaim(identity: Identity, expectedRevision: McpClientOAuthCredentialRevision, claimId: McpClientOAuthRefreshClaimId, context: McpClientOAuthCredentialStoreContext): Promise<McpClientOAuthRefreshClaimReleaseResult>;
100
+ /** Non-refresh exact writer. It must never reactivate or overwrite a claimed generation. */
101
+ compareAndSwap(identity: Identity, expectedRevision: McpClientOAuthCredentialRevision, credential: Readonly<Credential>, context: McpClientOAuthCredentialStoreContext): Promise<McpClientOAuthCredentialCompareAndSwapResult<Credential>>;
102
+ invalidate(identity: Identity, expectedRevision: McpClientOAuthCredentialRevision, reason: McpClientOAuthCredentialInvalidationReason, context: McpClientOAuthCredentialStoreContext): Promise<McpClientOAuthCredentialInvalidationResult>;
103
+ }
104
+ /** Validates and brands an exact positive credential revision. */
105
+ declare function createMcpClientOAuthCredentialRevision(value: number): McpClientOAuthCredentialRevision;
106
+ /** Runtime predicate for values crossing persistence or serialization boundaries. */
107
+ declare function isMcpClientOAuthCredentialRevision(value: unknown): value is McpClientOAuthCredentialRevision;
108
+ /** Returns the only revision valid for a successful exact compare-and-swap. */
109
+ declare function nextMcpClientOAuthCredentialRevision(revision: McpClientOAuthCredentialRevision): McpClientOAuthCredentialRevision;
110
+ /** Creates the frozen wrapper shared by stores and refresh callers. */
111
+ declare function createMcpClientOAuthCredentialSnapshot<Credential extends object>(revision: number, credential: Readonly<Credential>): McpClientOAuthCredentialSnapshot<Credential>;
112
+ //#endregion
113
+ //#region src/oauth/refresh-coordinator.d.ts
114
+ /** Stable, secret-free refresh-coordinator failures. */
115
+ declare const McpClientOAuthRefreshErrorCode: {
116
+ readonly InvalidOptions: "MCP_CLIENT_OAUTH_REFRESH_INVALID_OPTIONS";
117
+ readonly Closed: "MCP_CLIENT_OAUTH_REFRESH_COORDINATOR_CLOSED";
118
+ readonly CapacityExceeded: "MCP_CLIENT_OAUTH_REFRESH_CAPACITY_EXCEEDED";
119
+ readonly RevisionInFlight: "MCP_CLIENT_OAUTH_REFRESH_REVISION_IN_FLIGHT";
120
+ readonly CredentialMissing: "MCP_CLIENT_OAUTH_CREDENTIAL_MISSING";
121
+ readonly CredentialInvalidated: "MCP_CLIENT_OAUTH_CREDENTIAL_INVALIDATED";
122
+ readonly RevisionMismatch: "MCP_CLIENT_OAUTH_CREDENTIAL_REVISION_MISMATCH";
123
+ readonly RefreshFailed: "MCP_CLIENT_OAUTH_REFRESH_FAILED";
124
+ readonly StoreFailed: "MCP_CLIENT_OAUTH_CREDENTIAL_STORE_FAILED";
125
+ readonly InvalidStoreResult: "MCP_CLIENT_OAUTH_CREDENTIAL_STORE_RESULT_INVALID";
126
+ readonly InvalidationHookFailed: "MCP_CLIENT_OAUTH_INVALIDATION_HOOK_FAILED";
127
+ readonly CallerAborted: "MCP_CLIENT_OAUTH_REFRESH_CALLER_ABORTED";
128
+ readonly InternalFailure: "MCP_CLIENT_OAUTH_REFRESH_INTERNAL_FAILURE";
129
+ };
130
+ type McpClientOAuthRefreshErrorCode = (typeof McpClientOAuthRefreshErrorCode)[keyof typeof McpClientOAuthRefreshErrorCode];
131
+ /**
132
+ * Public coordinator error. Errors emitted across coordinator boundaries are rematerialized by
133
+ * code so their fixed messages never retain identity, credential, or caught error data.
134
+ */
135
+ declare class McpClientOAuthRefreshError extends Error {
136
+ readonly code: McpClientOAuthRefreshErrorCode;
137
+ constructor(code: McpClientOAuthRefreshErrorCode, message: string);
138
+ }
139
+ interface McpClientOAuthRefreshContext {
140
+ /** Shared operation cancellation; never tied to one caller waiting for the result. */
141
+ readonly signal: AbortSignal;
142
+ }
143
+ interface McpClientOAuthRefreshOperationOptions {
144
+ /** Cancels only this caller's wait and never the shared refresh or persistence mutation. */
145
+ readonly signal?: AbortSignal;
146
+ }
147
+ interface McpClientOAuthInvalidateOptions extends McpClientOAuthRefreshOperationOptions {
148
+ readonly reason?: McpClientOAuthCredentialInvalidationReason;
149
+ }
150
+ /** Explicitly states whether a caught refresh failure can safely reuse the exact generation. */
151
+ type McpClientOAuthRefreshFailureDisposition = {
152
+ readonly kind: "retry-safe";
153
+ } | {
154
+ readonly kind: "terminal";
155
+ readonly reason: McpClientOAuthTerminalRefreshReason;
156
+ };
157
+ interface McpClientOAuthInvalidatedContext {
158
+ readonly revision: McpClientOAuthCredentialRevision;
159
+ readonly reason: McpClientOAuthCredentialInvalidationReason;
160
+ }
161
+ interface McpClientOAuthRefreshCoordinatorOptions<Identity, Credential extends object> {
162
+ readonly store: McpClientOAuthCredentialStore<Identity, Credential>;
163
+ /**
164
+ * Exchanges the complete current credential set for one complete replacement set.
165
+ * The identity must be a stable, non-secret binding chosen by the host application.
166
+ * It may perform at most one credentialed token exchange per invocation; neither it nor its
167
+ * fetch middleware may retry a token POST. An ambiguous outcome must be thrown for terminal
168
+ * settlement.
169
+ */
170
+ readonly refresh: (identity: Identity, current: McpClientOAuthCredentialSnapshot<Credential>, context: McpClientOAuthRefreshContext) => Promise<Readonly<Credential>> | Readonly<Credential>;
171
+ /**
172
+ * Classifies a caught refresh failure. Returning `retry-safe` is an assertion that no
173
+ * credentialed refresh request was dispatched; throws and invalid results fail terminally.
174
+ */
175
+ readonly classifyRefreshFailure?: (error: unknown) => McpClientOAuthRefreshFailureDisposition;
176
+ /**
177
+ * Called only when the exact generation is unusable: after durable or observed invalidation,
178
+ * external disappearance, or local fail-closed retirement when durable state is uncertain.
179
+ * Successful local rotation and observation of a newer generation follow that binding without
180
+ * eviction. Delivery is at most once for one in-process coalesced settlement; this is not a
181
+ * durable or cross-process exactly-once guarantee. `ObservedExternal` proves absence; a terminal
182
+ * reason may instead represent durable invalidation or local fail-closed retirement.
183
+ * The hook is awaited and must only initiate lease retirement; it must never await active-lease
184
+ * drain, because refresh may be settling a 401 from that same lease.
185
+ */
186
+ readonly onInvalidated?: (identity: Identity, context: McpClientOAuthInvalidatedContext) => Promise<void> | void;
187
+ /** Hard bound over distinct opaque identities with accepted work or local fail-closed fences. */
188
+ readonly maxInFlightKeys?: number;
189
+ }
190
+ /** Aggregate diagnostics deliberately omit identities, credentials, revisions, and failures. */
191
+ interface McpClientOAuthRefreshCoordinatorSnapshot {
192
+ readonly closed: boolean;
193
+ readonly maxInFlightKeys: number;
194
+ readonly inFlightKeyCount: number;
195
+ readonly refreshCount: number;
196
+ readonly invalidationCount: number;
197
+ readonly waiterCount: number;
198
+ }
199
+ type McpClientOAuthInvalidateResult = {
200
+ readonly status: "invalidated";
201
+ } | {
202
+ readonly status: "superseded";
203
+ } | {
204
+ readonly status: "missing";
205
+ } | {
206
+ readonly status: "conflict";
207
+ };
208
+ /**
209
+ * Bounded, framework-neutral refresh ownership keyed by an opaque, non-secret identity.
210
+ *
211
+ * Calls for the same identity and exact revision share one refresh. A different revision is never
212
+ * joined to existing work. A durable pre-dispatch claim prevents multiple coordinators from
213
+ * sending the same refresh token. Only the holder's exact claim can commit the complete next
214
+ * generation. Commit loss reloads the authoritative winner and never retries the old token.
215
+ * Closing drains accepted mutations; it does not abandon a claimed generation.
216
+ */
217
+ declare class McpClientOAuthRefreshCoordinator<Identity, Credential extends object> implements AsyncDisposable {
218
+ #private;
219
+ constructor(options: McpClientOAuthRefreshCoordinatorOptions<Identity, Credential>);
220
+ get closed(): boolean;
221
+ snapshot(): McpClientOAuthRefreshCoordinatorSnapshot;
222
+ refresh(identity: Identity, expectedRevision: McpClientOAuthCredentialRevision, options?: McpClientOAuthRefreshOperationOptions): Promise<McpClientOAuthCredentialSnapshot<Credential>>;
223
+ invalidate(identity: Identity, expectedRevision: McpClientOAuthCredentialRevision, options?: McpClientOAuthInvalidateOptions): Promise<McpClientOAuthInvalidateResult>;
224
+ close(): Promise<void>;
225
+ [Symbol.asyncDispose](): Promise<void>;
226
+ }
227
+ /**
228
+ * Fails terminally by default. Only internally branded strict-protocol errors with a definitive
229
+ * pre-dispatch outcome are retry-safe; public constructor/code lookalikes are not.
230
+ */
231
+ declare function classifyMcpClientOAuthRefreshFailure(error: unknown): McpClientOAuthRefreshFailureDisposition;
232
+ //#endregion
233
+ //#region src/oauth/auth-provider.d.ts
234
+ type UnauthorizedContext = Parameters<NonNullable<AuthProvider$1["onUnauthorized"]>>[0];
235
+ /** Stable, identity- and secret-free transport-bridge failures. */
236
+ declare const McpClientOAuthAuthProviderErrorCode: {
237
+ readonly InvalidOptions: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_INVALID_OPTIONS";
238
+ readonly Closed: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_CLOSED";
239
+ readonly CredentialMissing: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_CREDENTIAL_MISSING";
240
+ readonly CredentialRevisionChanged: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_CREDENTIAL_REVISION_CHANGED";
241
+ readonly StoreFailed: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_STORE_FAILED";
242
+ readonly InvalidStoreResult: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_STORE_RESULT_INVALID";
243
+ readonly TokenMissing: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_TOKEN_MISSING";
244
+ readonly TokenInvalid: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_TOKEN_INVALID";
245
+ readonly TokenAccessorFailed: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_TOKEN_ACCESSOR_FAILED";
246
+ readonly RefreshFailed: "MCP_CLIENT_OAUTH_AUTH_PROVIDER_REFRESH_FAILED";
247
+ };
248
+ type McpClientOAuthAuthProviderErrorCode = (typeof McpClientOAuthAuthProviderErrorCode)[keyof typeof McpClientOAuthAuthProviderErrorCode];
249
+ /** Error whose public fields and message never contain an identity, token, or upstream response. */
250
+ declare class McpClientOAuthAuthProviderError extends Error {
251
+ readonly code: McpClientOAuthAuthProviderErrorCode;
252
+ constructor(code: McpClientOAuthAuthProviderErrorCode);
253
+ }
254
+ interface McpClientOAuthBearerTokenAccessorContext {
255
+ /** Provider-lifecycle cancellation. Accessors must stop promptly when it aborts. */
256
+ readonly signal: AbortSignal;
257
+ }
258
+ /**
259
+ * Selects the bearer token from one complete, immutable credential generation.
260
+ * Returning `undefined` is a deterministic missing-token failure.
261
+ */
262
+ type McpClientOAuthBearerTokenAccessor<Credential extends object> = (snapshot: McpClientOAuthCredentialSnapshot<Credential>, context: McpClientOAuthBearerTokenAccessorContext) => string | undefined | PromiseLike<string | undefined>;
263
+ interface McpClientOAuthAuthProviderOptions<Identity, Credential extends object> {
264
+ /** One opaque, stable, non-secret credential binding. It is never exposed by the provider. */
265
+ readonly identity: Identity;
266
+ /** Pin one operation to an exact revision. Rotation requires a new provider; delayed 401s cannot refresh its replacement. */
267
+ readonly expectedCredentialRevision?: McpClientOAuthCredentialRevision;
268
+ readonly store: McpClientOAuthCredentialStore<Identity, Credential>;
269
+ readonly refreshCoordinator: McpClientOAuthRefreshCoordinator<Identity, Credential>;
270
+ readonly selectBearerToken: McpClientOAuthBearerTokenAccessor<Credential>;
271
+ }
272
+ /**
273
+ * Per-binding bridge from revisioned OAuth credentials to the SDK's minimal `AuthProvider`.
274
+ *
275
+ * It intentionally has no `tokens()` or `clientInformation()` members, so the official
276
+ * transport cannot classify it as an `OAuthClientProvider` and cannot start interactive or
277
+ * Dynamic Client Registration flows. The store and coordinator are borrowed; closing this
278
+ * bridge never closes either dependency. It follows successful credential revisions within one
279
+ * stable binding by default. Set expectedCredentialRevision for an operation that must close
280
+ * and be reacquired after rotation; its token and refresh paths both enforce the exact revision.
281
+ */
282
+ declare class McpClientOAuthAuthProvider<Identity, Credential extends object> implements AuthProvider$1, AsyncDisposable {
283
+ #private;
284
+ constructor(options: McpClientOAuthAuthProviderOptions<Identity, Credential>);
285
+ get closed(): boolean;
286
+ /** Loads the authoritative generation on every request; no token is cached in the bridge. */
287
+ token(): Promise<string | undefined>;
288
+ /**
289
+ * Refreshes exactly the authoritative revision loaded for this binding. Concurrent 401s join
290
+ * in the coordinator. A process-external claim or winner is accepted only after an authoritative
291
+ * reload; only a strictly newer revision completes this call, and this bridge never retries the
292
+ * stale refresh token. The
293
+ * SDK does not identify the failed request's credential revision in this callback. A delayed 401
294
+ * can therefore arrive after another request published a newer generation and refresh that newer
295
+ * generation. An expectedCredentialRevision fences this reload before refresh: a pinned provider
296
+ * never refreshes or adopts a replacement. Its successful refresh still publishes for a fresh
297
+ * acquisition, while the old operation fails closed. Unpinned hosts need request correlation
298
+ * or conservative close/reacquire; the transport bounds each wire request to one retry.
299
+ */
300
+ onUnauthorized(_context: UnauthorizedContext): Promise<void>;
301
+ /** Fences new work, cancels this provider's waits, and drains all accepted bridge calls. */
302
+ close(): Promise<void>;
303
+ [Symbol.asyncDispose](): Promise<void>;
304
+ }
305
+ //#endregion
306
+ //#region src/oauth/scope.d.ts
307
+ /** Maximum scope-token length accepted by the bounded OAuth client facade. */
308
+ declare const MCP_CLIENT_OAUTH_MAX_SCOPE_LENGTH = 256;
309
+ /**
310
+ * Returns whether `value` is one bounded RFC 6749 scope-token.
311
+ *
312
+ * RFC 6749 section 3.3 defines scope-token as ASCII NQCHAR: `!`, `#` through
313
+ * `[`, or `]` through `~`. In particular, quote, backslash, whitespace, control
314
+ * characters, and non-ASCII characters are not valid scope-token content.
315
+ */
316
+ declare function isMcpClientOAuthScopeToken(value: unknown): value is string;
317
+ //#endregion
318
+ //#region src/oauth/provisioning.d.ts
319
+ /** Public provenance only. Credentials and the identity of the host's record stay with the host. */
320
+ interface McpClientOAuthExistingClient {
321
+ readonly clientId: string;
322
+ readonly serverUrl: string;
323
+ readonly issuer: string;
324
+ readonly resource: string;
325
+ readonly provisioningMethod: "manual" | "client_id_metadata" | "dynamic_registration";
326
+ readonly authenticationMethod: McpClientOAuthClientAuthentication["method"];
327
+ /** Whether the host can supply the secret or signing key required by this method. */
328
+ readonly authenticationAvailable: boolean;
329
+ /** Required for automatic-client reuse; manual clients retain host-managed redirect policy. */
330
+ readonly redirectUri?: string;
331
+ /** Configured manual scopes or the original registered allowance, not a previous access token grant. */
332
+ readonly scopes: readonly string[];
333
+ }
334
+ type McpClientOAuthProvisioningStrategy = "reuse" | "client_id_metadata" | "dynamic_registration";
335
+ type McpClientOAuthExistingClientStatus = "absent" | "incompatible" | "scope_insufficient" | "reusable";
336
+ interface McpClientOAuthProvisioningInput {
337
+ readonly discovery: McpClientOAuthBootstrapReady;
338
+ readonly redirectUri: string;
339
+ readonly clientIdMetadataUrl?: string;
340
+ readonly existingClient?: McpClientOAuthExistingClient;
341
+ /** Explicit host preference order. Omitting a strategy prohibits selecting it. */
342
+ readonly strategies: readonly McpClientOAuthProvisioningStrategy[];
343
+ /** Defaults to false: an insufficient existing registration cannot silently cause another one. */
344
+ readonly allowRegistrationAfterScopeExpansion?: boolean;
345
+ }
346
+ interface McpClientOAuthProvisioningPlan {
347
+ readonly kind: "reuse" | "client_id_metadata" | "dynamic_registration" | "registration_scope_insufficient" | "manual_client_required";
348
+ readonly existingClientStatus: McpClientOAuthExistingClientStatus;
349
+ /** Exact scopes to request. Empty means request no scopes, including after narrower rediscovery. */
350
+ readonly authorizationScopes: readonly string[];
351
+ }
352
+ /**
353
+ * Pure provisioning decision over captured protocol facts and explicit host preferences.
354
+ * Performs no I/O, registration, decryption, authorization or persistence. A registration plan
355
+ * is only a capability result; hosts must obtain consent and fence dispatch independently.
356
+ */
357
+ declare function planMcpClientOAuthProvisioning(input: McpClientOAuthProvisioningInput): McpClientOAuthProvisioningPlan;
358
+ /** Canonical HTTPS web callback or RFC 8252 loopback HTTP native callback; no network admission. */
359
+ declare function getMcpClientOAuthApplicationType(value: string): "web" | "native" | undefined;
360
+ /** Empty or absent discovery asks for no scopes; it never expands a registered allowance. */
361
+ declare function mcpClientOAuthScopesCover(available: readonly string[], requested?: readonly string[]): boolean;
362
+ //#endregion
363
+ //#region src/oauth/challenge-probe.d.ts
364
+ interface McpClientOAuthChallengeProbeInput {
365
+ readonly serverUrl: string;
366
+ /** Already admitted, unauthenticated fetch. The host owns DNS/redirect/response limits and lease cleanup. */
367
+ readonly fetch: FetchLike$1;
368
+ /** Host deadline and cancellation. Fetch must honor it; this helper owns no transport. */
369
+ readonly signal: AbortSignal;
370
+ }
371
+ /** One non-credentialed GET. Pass its bounded raw header to bootstrap.discover({ wwwAuthenticate }). */
372
+ declare function probeMcpClientOAuthChallenge(input: McpClientOAuthChallengeProbeInput): Promise<string | undefined>;
373
+ //#endregion
374
+ //#region src/oauth/authentication-detection.d.ts
375
+ interface McpClientAuthenticationDetectionInput {
376
+ readonly serverUrl: string;
377
+ /** Already admitted, credential-free fetch. The host owns DNS pinning and network policy. */
378
+ readonly fetch: FetchLike$1;
379
+ /** Guarded OAuth metadata fetch; defaults to fetch. Useful with an endpoint-only MCP lease. */
380
+ readonly discoveryFetch?: FetchLike$1;
381
+ /** The same policy used by OAuth bootstrap, including all generated discovery URLs. */
382
+ readonly endpointPolicy: McpClientOAuthBootstrapEndpointPolicy;
383
+ /** Host cancellation/deadline, preserved as a rejection with its original reason. */
384
+ readonly signal: AbortSignal;
385
+ /** Whole detection budget, default 10 seconds, at most 60 seconds. Cleanup adds at most 1 second. */
386
+ readonly timeoutMs?: number;
387
+ /** Aggregate response bytes, including SSE framing and metadata. Default 256 KiB, at most 1 MiB. */
388
+ readonly maxResponseBytes?: number;
389
+ }
390
+ type McpClientAuthenticationDetectionReason = "invalid-options" | "endpoint-rejected" | "network-error" | "invalid-response" | "response-too-large" | "request-limit" | "timeout" | "http-error" | "unsupported-authentication" | "oauth-discovery-failed" | "cleanup-failed";
391
+ type McpClientAuthenticationDetectionResult = {
392
+ /** A credential-free MCP connection succeeded; later operations may still require OAuth. */
393
+ readonly kind: "anonymous";
394
+ readonly protocolVersion: string;
395
+ readonly protocolEra: "modern" | "legacy";
396
+ /** Schema-validated, bounded, self-reported display data; never an identity attestation. */
397
+ readonly serverInfo?: {
398
+ readonly name: string;
399
+ readonly version: string;
400
+ readonly title?: string;
401
+ };
402
+ } | {
403
+ /** Authorization was denied and OAuth bootstrap validated the advertised resource. */
404
+ readonly kind: "oauth-required";
405
+ /** Enrollment, issuer selection, and strict-protocol compatibility remain host decisions. */
406
+ readonly discovery: McpClientOAuthBootstrapDiscoveryResult;
407
+ } | {
408
+ readonly kind: "indeterminate";
409
+ readonly reason: McpClientAuthenticationDetectionReason;
410
+ readonly httpStatus?: number;
411
+ readonly discoveryErrorCode?: McpClientOAuthBootstrapErrorCode;
412
+ };
413
+ /**
414
+ * Passive Streamable HTTP detection using the SDK's modern discovery / legacy handshake.
415
+ * No credentials, registration, browser navigation, token requests, or feature invocation.
416
+ * Never infer anonymous access from a status code or missing OAuth metadata. HTTP+SSE (2024)
417
+ * endpoints are not followed. The caller must always release its admitted network lease.
418
+ */
419
+ declare function detectMcpClientAuthentication(input: McpClientAuthenticationDetectionInput): Promise<McpClientAuthenticationDetectionResult>;
420
+ //#endregion
421
+ export { type AddClientAuthentication, type AuthProvider, type AuthorizationServerMetadata, type FetchLike, MCP_CLIENT_OAUTH_MAX_SCOPE_LENGTH, McpClientAuthenticationDetectionInput, McpClientAuthenticationDetectionReason, McpClientAuthenticationDetectionResult, McpClientOAuthAuthProvider, McpClientOAuthAuthProviderError, McpClientOAuthAuthProviderErrorCode, McpClientOAuthAuthProviderOptions, McpClientOAuthAuthority, McpClientOAuthAuthorizationTransaction, McpClientOAuthBearerTokenAccessor, McpClientOAuthBearerTokenAccessorContext, McpClientOAuthBootstrap, McpClientOAuthBootstrapCandidate, McpClientOAuthBootstrapChallenge, McpClientOAuthBootstrapDiscoveryInput, McpClientOAuthBootstrapDiscoveryResult, McpClientOAuthBootstrapEndpointKind, McpClientOAuthBootstrapEndpointPolicy, McpClientOAuthBootstrapEndpointPolicyInput, McpClientOAuthBootstrapError, McpClientOAuthBootstrapErrorCode, McpClientOAuthBootstrapIssuerCandidate, McpClientOAuthBootstrapOptions, McpClientOAuthBootstrapReady, McpClientOAuthBootstrapResource, McpClientOAuthBootstrapSelectionRequired, McpClientOAuthBootstrapStrictProtocolUnsupported, McpClientOAuthChallengeProbeInput, McpClientOAuthClient, McpClientOAuthClientAuthentication, McpClientOAuthCredentialCompareAndSwapApplied, McpClientOAuthCredentialCompareAndSwapConflict, McpClientOAuthCredentialCompareAndSwapResult, McpClientOAuthCredentialInvalidationApplied, McpClientOAuthCredentialInvalidationConflict, McpClientOAuthCredentialInvalidationReason, McpClientOAuthCredentialInvalidationResult, McpClientOAuthCredentialRevision, McpClientOAuthCredentialSnapshot, McpClientOAuthCredentialStore, McpClientOAuthCredentialStoreContext, McpClientOAuthDiscoveryInput, McpClientOAuthEndpointKind, McpClientOAuthEndpointPolicy, McpClientOAuthEndpointPolicyInput, McpClientOAuthExchangeAuthorizationInput, McpClientOAuthExistingClient, McpClientOAuthExistingClientStatus, McpClientOAuthInvalidateOptions, McpClientOAuthInvalidateResult, McpClientOAuthInvalidatedContext, McpClientOAuthProtocol, McpClientOAuthProtocolError, McpClientOAuthProtocolErrorCode, McpClientOAuthProtocolOptions, McpClientOAuthProvisioningInput, McpClientOAuthProvisioningPlan, McpClientOAuthProvisioningStrategy, McpClientOAuthRefreshClaimBusy, McpClientOAuthRefreshClaimConflict, McpClientOAuthRefreshClaimId, McpClientOAuthRefreshClaimReleaseConflict, McpClientOAuthRefreshClaimReleaseResult, McpClientOAuthRefreshClaimReleased, McpClientOAuthRefreshClaimResult, McpClientOAuthRefreshClaimed, McpClientOAuthRefreshCommitApplied, McpClientOAuthRefreshCommitConflict, McpClientOAuthRefreshCommitResult, McpClientOAuthRefreshContext, McpClientOAuthRefreshCoordinator, McpClientOAuthRefreshCoordinatorOptions, McpClientOAuthRefreshCoordinatorSnapshot, McpClientOAuthRefreshError, McpClientOAuthRefreshErrorCode, McpClientOAuthRefreshFailureDisposition, McpClientOAuthRefreshInput, McpClientOAuthRefreshOperationOptions, McpClientOAuthSnapshotError, type McpClientOAuthSnapshotOptions, McpClientOAuthStartAuthorizationInput, McpClientOAuthStartAuthorizationResult, McpClientOAuthStrictCompatibilityIssue, McpClientOAuthTerminalRefreshReason, McpOAuthCallbackError, McpOAuthCallbackParameterInput, McpOAuthCallbackParameters, McpOAuthCallbackSuccess, McpOAuthPkceGenerationOptions, McpOAuthStateError, McpOAuthStateErrorCode, McpOAuthStateGenerationOptions, McpOAuthStateValidationInput, type OAuthProtectedResourceMetadata, type OAuthTokens, classifyMcpClientOAuthRefreshFailure, createMcpClientOAuthCredentialRevision, createMcpClientOAuthCredentialSnapshot, createOAuthState, createOAuthStateLookupDigest, createPkceS256Challenge, createPkceVerifier, detectMcpClientAuthentication, getMcpClientOAuthApplicationType, isMcpClientOAuthCredentialRevision, isMcpClientOAuthScopeToken, mcpClientOAuthScopesCover, nextMcpClientOAuthCredentialRevision, parseMcpClientOAuthAuthority, parseMcpClientOAuthAuthorizationTransaction, parseMcpClientOAuthBootstrapChallenge, parseMcpClientOAuthBootstrapDiscoveryResult, parseOAuthCallbackParameters, planMcpClientOAuthProvisioning, probeMcpClientOAuthChallenge, validateOAuthState };
422
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/oauth/credential-store.ts","../../src/oauth/refresh-coordinator.ts","../../src/oauth/auth-provider.ts","../../src/oauth/scope.ts","../../src/oauth/provisioning.ts","../../src/oauth/challenge-probe.ts","../../src/oauth/authentication-detection.ts"],"mappings":";;;cAAc;;KAGF;YACD;;;UAIM;WACP;;;cAIG;WACZ;WACA;;WAEA;WACA;;KAGW,qDACH,yDAAyD;;KAGtD,6CACF,2CAA2C,sBAC3C,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