@nest-mcp/client 1.0.1 → 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,14 @@
1
+ import { Tool, jsonSchema } from "ai";
2
+ //#region src/ai-sdk/index.d.ts
3
+ interface AiSdkMcpToolDescriptor {
4
+ /** Already selected and named by the host. Names must be unique. */
5
+ readonly name: string;
6
+ readonly description?: string;
7
+ readonly inputSchema: Parameters<typeof jsonSchema<Record<string, unknown>>>[0];
8
+ }
9
+ type AiSdkMcpToolInvocation = (name: string, input: Record<string, unknown>, signal?: AbortSignal) => unknown;
10
+ /** Adapts sanitized descriptors; every execution remains behind the supplied protected delegate. */
11
+ declare function createAiSdkMcpTools(descriptors: readonly AiSdkMcpToolDescriptor[], invoke: AiSdkMcpToolInvocation): Record<string, Tool<Record<string, unknown>, unknown>>;
12
+ //#endregion
13
+ export { AiSdkMcpToolDescriptor, AiSdkMcpToolInvocation, createAiSdkMcpTools };
14
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/ai-sdk/index.ts"],"mappings":";;UAEiB;;WAEP;WACA;WACA,aAAa,kBAAkB,WAAW;;KAExC,0BACX,cACA,OAAO,yBACP,SAAS;;iBAIM,oBACf,sBAAsB,0BACtB,QAAQ,yBACN,eAAe,KAAK"}
@@ -0,0 +1,27 @@
1
+ import { jsonSchema, tool } from "ai";
2
+ //#region src/ai-sdk/index.ts
3
+ /** Adapts sanitized descriptors; every execution remains behind the supplied protected delegate. */
4
+ function createAiSdkMcpTools(descriptors, invoke) {
5
+ const names = /* @__PURE__ */ new Set();
6
+ return Object.fromEntries(descriptors.map((descriptor) => {
7
+ const { name, description } = descriptor;
8
+ if (name.length === 0 || names.has(name)) throw new TypeError("MCP tool names must be nonempty and unique.");
9
+ names.add(name);
10
+ const inputSchema = structuredClone(descriptor.inputSchema);
11
+ return [name, tool({
12
+ strict: false,
13
+ ...description === void 0 ? {} : { description },
14
+ inputSchema: jsonSchema(inputSchema),
15
+ execute: async (input, options) => {
16
+ options.abortSignal?.throwIfAborted();
17
+ const result = await invoke(name, input, options.abortSignal);
18
+ options.abortSignal?.throwIfAborted();
19
+ return result;
20
+ }
21
+ })];
22
+ }));
23
+ }
24
+ //#endregion
25
+ export { createAiSdkMcpTools };
26
+
27
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/ai-sdk/index.ts"],"sourcesContent":["import { jsonSchema, tool, type Tool } from \"ai\";\n\nexport interface AiSdkMcpToolDescriptor {\n\t/** Already selected and named by the host. Names must be unique. */\n\treadonly name: string;\n\treadonly description?: string;\n\treadonly inputSchema: Parameters<typeof jsonSchema<Record<string, unknown>>>[0];\n}\nexport type AiSdkMcpToolInvocation = (\n\tname: string,\n\tinput: Record<string, unknown>,\n\tsignal?: AbortSignal,\n) => unknown;\n\n/** Adapts sanitized descriptors; every execution remains behind the supplied protected delegate. */\nexport function createAiSdkMcpTools(\n\tdescriptors: readonly AiSdkMcpToolDescriptor[],\n\tinvoke: AiSdkMcpToolInvocation,\n): Record<string, Tool<Record<string, unknown>, unknown>> {\n\tconst names = new Set<string>();\n\treturn Object.fromEntries(\n\t\tdescriptors.map((descriptor) => {\n\t\t\tconst { name, description } = descriptor;\n\t\t\tif (name.length === 0 || names.has(name))\n\t\t\t\tthrow new TypeError(\"MCP tool names must be nonempty and unique.\");\n\t\t\tnames.add(name);\n\t\t\tconst inputSchema = structuredClone(descriptor.inputSchema);\n\t\t\treturn [\n\t\t\t\tname,\n\t\t\t\ttool({\n\t\t\t\t\t// MCP optional fields may be mutually exclusive or distinguish absence from null.\n\t\t\t\t\t// Provider strict normalization must not change that source contract.\n\t\t\t\t\tstrict: false,\n\t\t\t\t\t...(description === undefined ? {} : { description }),\n\t\t\t\t\tinputSchema: jsonSchema<Record<string, unknown>>(inputSchema),\n\t\t\t\t\texecute: async (input, options) => {\n\t\t\t\t\t\toptions.abortSignal?.throwIfAborted();\n\t\t\t\t\t\tconst result = await invoke(name, input, options.abortSignal);\n\t\t\t\t\t\toptions.abortSignal?.throwIfAborted();\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t];\n\t\t}),\n\t);\n}\n"],"mappings":";;;AAeA,SAAgB,oBACf,aACA,QACyD;CACzD,MAAM,wBAAQ,IAAI,IAAY;CAC9B,OAAO,OAAO,YACb,YAAY,KAAK,eAAe;EAC/B,MAAM,EAAE,MAAM,gBAAgB;EAC9B,IAAI,KAAK,WAAW,KAAK,MAAM,IAAI,IAAI,GACtC,MAAM,IAAI,UAAU,6CAA6C;EAClE,MAAM,IAAI,IAAI;EACd,MAAM,cAAc,gBAAgB,WAAW,WAAW;EAC1D,OAAO,CACN,MACA,KAAK;GAGJ,QAAQ;GACR,GAAI,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY;GACnD,aAAa,WAAoC,WAAW;GAC5D,SAAS,OAAO,OAAO,YAAY;IAClC,QAAQ,aAAa,eAAe;IACpC,MAAM,SAAS,MAAM,OAAO,MAAM,OAAO,QAAQ,WAAW;IAC5D,QAAQ,aAAa,eAAe;IACpC,OAAO;GACR;EACD,CAAC,CACF;CACD,CAAC,CACF;AACD"}
@@ -0,0 +1,394 @@
1
+ import { AddClientAuthentication, FetchLike, OAuthTokens } from "@modelcontextprotocol/client";
2
+ //#region src/oauth/state.d.ts
3
+ /** Stable, secret-free failure categories for OAuth state and callback handling. */
4
+ declare const McpOAuthStateErrorCode: {
5
+ readonly InvalidOptions: "MCP_OAUTH_STATE_INVALID_OPTIONS";
6
+ readonly InvalidCallback: "MCP_OAUTH_CALLBACK_INVALID";
7
+ readonly InvalidDigest: "MCP_OAUTH_STATE_DIGEST_INVALID";
8
+ readonly StateMismatch: "MCP_OAUTH_STATE_MISMATCH";
9
+ readonly StateExpired: "MCP_OAUTH_STATE_EXPIRED";
10
+ readonly StateNotYetValid: "MCP_OAUTH_STATE_NOT_YET_VALID";
11
+ readonly InvalidPkceVerifier: "MCP_OAUTH_PKCE_VERIFIER_INVALID";
12
+ };
13
+ type McpOAuthStateErrorCode = (typeof McpOAuthStateErrorCode)[keyof typeof McpOAuthStateErrorCode];
14
+ /** An OAuth state/protocol error whose message never includes callback or secret material. */
15
+ declare class McpOAuthStateError extends Error {
16
+ readonly code: McpOAuthStateErrorCode;
17
+ constructor(code: McpOAuthStateErrorCode);
18
+ }
19
+ interface McpOAuthStateGenerationOptions {
20
+ /** CSPRNG bytes. The resulting base64url state is always between 22 and 86 characters. */
21
+ readonly entropyBytes?: number;
22
+ }
23
+ interface McpOAuthPkceGenerationOptions {
24
+ /** CSPRNG bytes. The resulting verifier is always within RFC 7636's 43-128 character bound. */
25
+ readonly entropyBytes?: number;
26
+ }
27
+ interface McpOAuthStateValidationInput {
28
+ /** State received from the authorization callback. */
29
+ readonly actualState: string;
30
+ /** Domain-separated SHA-256 digest retained with the transaction; never the plaintext state. */
31
+ readonly expectedDigest: string;
32
+ /** Transaction creation time as Unix epoch milliseconds. */
33
+ readonly createdAtMs: number;
34
+ /** Positive transaction lifetime in milliseconds. */
35
+ readonly ttlMs: number;
36
+ /** Injectable clock for deterministic validation. Defaults to `Date.now()`. */
37
+ readonly nowMs?: number;
38
+ }
39
+ interface McpOAuthCallbackSuccess {
40
+ readonly kind: "success";
41
+ readonly code: string;
42
+ readonly state: string;
43
+ readonly issuer?: string;
44
+ }
45
+ interface McpOAuthCallbackError {
46
+ readonly kind: "error";
47
+ readonly error: string;
48
+ readonly state: string;
49
+ readonly issuer?: string;
50
+ }
51
+ type McpOAuthCallbackParameters = McpOAuthCallbackSuccess | McpOAuthCallbackError;
52
+ type McpOAuthCallbackParameterInput = URL | URLSearchParams;
53
+ /** Generates an unpredictable OAuth state value using Node's CSPRNG. */
54
+ declare function createOAuthState(options?: McpOAuthStateGenerationOptions): string;
55
+ /**
56
+ * Derives the opaque key used to look up an authorization transaction.
57
+ * The domain prefix prevents the digest from being reused as an unscoped SHA-256 identifier.
58
+ */
59
+ declare function createOAuthStateLookupDigest(state: string): string;
60
+ /**
61
+ * Validates a callback state against a digest-only transaction record and its lifetime.
62
+ * Both valid digests are decoded to fixed-size byte arrays before constant-time comparison.
63
+ */
64
+ declare function validateOAuthState(input: McpOAuthStateValidationInput): void;
65
+ /**
66
+ * Parses an authorization callback query without normalizing opaque values.
67
+ * Unknown extension parameters are ignored as required by OAuth; reserved parameters are strict.
68
+ */
69
+ declare function parseOAuthCallbackParameters(input: McpOAuthCallbackParameterInput): McpOAuthCallbackParameters;
70
+ /** Generates an RFC 7636 code verifier using Node's CSPRNG. */
71
+ declare function createPkceVerifier(options?: McpOAuthPkceGenerationOptions): string;
72
+ /** Derives the RFC 7636 `S256` code challenge for a validated verifier. */
73
+ declare function createPkceS256Challenge(verifier: string): string;
74
+ //#endregion
75
+ //#region src/oauth/snapshot-data.d.ts
76
+ /** Optional stricter storage bounds; they cannot widen the protocol's fixed ceilings. */
77
+ interface McpClientOAuthSnapshotOptions {
78
+ readonly maxBytes?: number;
79
+ readonly maxUrlLength?: number;
80
+ }
81
+ /** Never retains the decoded value, a validation cause, URLs, or secret material. */
82
+ declare class McpClientOAuthSnapshotError extends Error {
83
+ readonly code: "MCP_CLIENT_OAUTH_SNAPSHOT_INVALID";
84
+ constructor();
85
+ }
86
+ //#endregion
87
+ //#region src/oauth/protocol.d.ts
88
+ /** Stable, secret-free failure categories for the strict outbound OAuth facade. */
89
+ declare const McpClientOAuthProtocolErrorCode: {
90
+ readonly InvalidOptions: "MCP_CLIENT_OAUTH_INVALID_OPTIONS";
91
+ readonly EndpointRejected: "MCP_CLIENT_OAUTH_ENDPOINT_REJECTED";
92
+ readonly DiscoveryFailed: "MCP_CLIENT_OAUTH_DISCOVERY_FAILED";
93
+ readonly AuthorityInvalid: "MCP_CLIENT_OAUTH_AUTHORITY_INVALID";
94
+ readonly ClientUnsupported: "MCP_CLIENT_OAUTH_CLIENT_UNSUPPORTED";
95
+ readonly TransactionInvalid: "MCP_CLIENT_OAUTH_TRANSACTION_INVALID";
96
+ readonly AuthorizationDenied: "MCP_CLIENT_OAUTH_AUTHORIZATION_DENIED";
97
+ readonly AuthorizationFailed: "MCP_CLIENT_OAUTH_AUTHORIZATION_FAILED";
98
+ readonly InvalidGrant: "MCP_CLIENT_OAUTH_INVALID_GRANT";
99
+ readonly InvalidClient: "MCP_CLIENT_OAUTH_INVALID_CLIENT";
100
+ readonly TokenExchangeFailed: "MCP_CLIENT_OAUTH_TOKEN_EXCHANGE_FAILED";
101
+ readonly TokenRefreshFailed: "MCP_CLIENT_OAUTH_TOKEN_REFRESH_FAILED";
102
+ readonly RefreshOutcomeUnknown: "MCP_CLIENT_OAUTH_REFRESH_OUTCOME_UNKNOWN";
103
+ };
104
+ type McpClientOAuthProtocolErrorCode = (typeof McpClientOAuthProtocolErrorCode)[keyof typeof McpClientOAuthProtocolErrorCode];
105
+ /**
106
+ * Public protocol-error shape. Library-emitted instances use fixed, secret-free messages; callers
107
+ * constructing this class directly remain responsible for their message and receive no internal
108
+ * authenticity brand.
109
+ */
110
+ declare class McpClientOAuthProtocolError extends Error {
111
+ readonly code: McpClientOAuthProtocolErrorCode;
112
+ constructor(code: McpClientOAuthProtocolErrorCode, message: string);
113
+ }
114
+ type McpClientOAuthEndpointKind = "resource-metadata" | "authorization-server-metadata" | "authorization" | "token";
115
+ interface McpClientOAuthEndpointPolicyInput {
116
+ /** A disposable URL copy. Mutating it never changes the destination used by the facade. */
117
+ readonly endpoint: URL;
118
+ readonly kind: McpClientOAuthEndpointKind;
119
+ readonly credentialed: boolean;
120
+ readonly exactResource: string;
121
+ readonly exactIssuer: string;
122
+ readonly resource: URL;
123
+ readonly issuer: URL;
124
+ readonly signal?: AbortSignal;
125
+ }
126
+ /** Only literal `true` admits an endpoint; false, undefined, or an exception fails closed. */
127
+ type McpClientOAuthEndpointPolicy = (input: McpClientOAuthEndpointPolicyInput) => boolean | PromiseLike<boolean>;
128
+ interface McpClientOAuthProtocolOptions {
129
+ /**
130
+ * A host-owned SSRF-hardened fetch. It must pin DNS, reject redirects, and bound bodies/time.
131
+ * It must never automatically retry credentialed token POSTs: the facade invokes the host fetch
132
+ * once and must receive ambiguous failures unchanged. The facade also forces `redirect: "error"`
133
+ * and applies `endpointPolicy` before each call.
134
+ */
135
+ readonly fetch: FetchLike;
136
+ readonly endpointPolicy: McpClientOAuthEndpointPolicy;
137
+ readonly authorizationTransactionTtlMs?: number;
138
+ readonly now?: () => number;
139
+ }
140
+ interface McpClientOAuthDiscoveryInput {
141
+ /** MCP HTTP endpoint used to derive RFC 9728 discovery locations. */
142
+ readonly serverUrl: string;
143
+ /** Exact RFC 8707 resource indicator expected in RFC 9728 metadata. */
144
+ readonly resource: string;
145
+ /** Exact authorization-server issuer selected by application policy. */
146
+ readonly issuer: string;
147
+ readonly resourceMetadataUrl?: string;
148
+ readonly signal?: AbortSignal;
149
+ }
150
+ /**
151
+ * A bounded, serializable authority snapshot. It intentionally excludes registration endpoints
152
+ * and unknown metadata so it cannot enable Dynamic Client Registration.
153
+ */
154
+ interface McpClientOAuthAuthority {
155
+ readonly serverUrl: string;
156
+ readonly resource: string;
157
+ readonly issuer: string;
158
+ readonly authorizationEndpoint: string;
159
+ readonly tokenEndpoint: string;
160
+ readonly responseTypesSupported: readonly string[];
161
+ readonly codeChallengeMethodsSupported: readonly string[];
162
+ readonly tokenEndpointAuthMethodsSupported: readonly string[];
163
+ readonly grantTypesSupported?: readonly string[];
164
+ readonly resourceScopesSupported?: readonly string[];
165
+ readonly authorizationScopesSupported?: readonly string[];
166
+ /** Whether RFC 9207 requires an `iss` parameter in the authorization response. */
167
+ readonly authorizationResponseIssuerParameterSupported: boolean;
168
+ }
169
+ type McpClientOAuthClientAuthentication = {
170
+ readonly method: "none";
171
+ } | {
172
+ readonly method: "client_secret_basic";
173
+ readonly clientSecret: string;
174
+ } | {
175
+ readonly method: "client_secret_post";
176
+ readonly clientSecret: string;
177
+ } | {
178
+ readonly method: "private_key_jwt";
179
+ readonly addClientAuthentication: AddClientAuthentication;
180
+ };
181
+ /** Client information must be provisioned out of band; this API has no registration operation. */
182
+ interface McpClientOAuthClient {
183
+ readonly clientId: string;
184
+ readonly authentication: McpClientOAuthClientAuthentication;
185
+ }
186
+ interface McpClientOAuthStartAuthorizationInput {
187
+ readonly authority: McpClientOAuthAuthority;
188
+ readonly client: McpClientOAuthClient;
189
+ readonly redirectUri: string;
190
+ readonly scopes?: readonly string[];
191
+ readonly signal?: AbortSignal;
192
+ }
193
+ /**
194
+ * Secret-bearing redirect transaction. Persist it encrypted and bind it to the browser session.
195
+ * `stateDigest` is suitable for lookup; plaintext state is intentionally not retained here.
196
+ */
197
+ interface McpClientOAuthAuthorizationTransaction {
198
+ readonly authority: McpClientOAuthAuthority;
199
+ /** Non-secret corruption/swap coordinate; authenticated host storage remains mandatory. */
200
+ readonly authorityDigest: string;
201
+ readonly stateDigest: string;
202
+ readonly codeVerifier: string;
203
+ readonly redirectUri: string;
204
+ readonly clientId: string;
205
+ readonly clientAuthenticationMethod: McpClientOAuthClientAuthentication["method"];
206
+ readonly scope?: string;
207
+ readonly createdAtMs: number;
208
+ }
209
+ interface McpClientOAuthStartAuthorizationResult {
210
+ readonly authorizationUrl: string;
211
+ readonly transaction: McpClientOAuthAuthorizationTransaction;
212
+ }
213
+ interface McpClientOAuthExchangeAuthorizationInput {
214
+ /**
215
+ * The host must first parse state, atomically take the transaction by its digest, and then call
216
+ * this method exactly once. A network-ambiguous exchange must never make the code replayable.
217
+ */
218
+ readonly transaction: McpClientOAuthAuthorizationTransaction;
219
+ readonly client: McpClientOAuthClient;
220
+ readonly callback: McpOAuthCallbackParameterInput;
221
+ readonly signal?: AbortSignal;
222
+ }
223
+ interface McpClientOAuthRefreshInput {
224
+ readonly authority: McpClientOAuthAuthority;
225
+ readonly client: McpClientOAuthClient;
226
+ /** Current effective grant, retained when a conforming refresh response omits `scope`. */
227
+ readonly currentScope?: string;
228
+ readonly refreshToken: string;
229
+ readonly signal?: AbortSignal;
230
+ }
231
+ /**
232
+ * Strict, framework-neutral OAuth protocol facade for outbound MCP clients.
233
+ *
234
+ * It deliberately exposes no dynamic registration and never constructs an OAuthClientProvider,
235
+ * preventing the MCP transport from launching interactive or DCR flows implicitly.
236
+ */
237
+ declare class McpClientOAuthProtocol {
238
+ #private;
239
+ constructor(options: McpClientOAuthProtocolOptions);
240
+ /** Resolves and freezes exact RFC 9728/RFC 8414 authority without following DCR. */
241
+ discover(input: McpClientOAuthDiscoveryInput): Promise<McpClientOAuthAuthority>;
242
+ /** Starts a PKCE S256 authorization request and returns an endpoint-pinned transaction. */
243
+ startAuthorization(input: McpClientOAuthStartAuthorizationInput): Promise<McpClientOAuthStartAuthorizationResult>;
244
+ /** Redeems a callback against the originally pinned authority exactly once. */
245
+ exchangeAuthorization(input: McpClientOAuthExchangeAuthorizationInput): Promise<OAuthTokens>;
246
+ /** Refreshes with the same exact authority and configured authentication method. */
247
+ refreshAuthorization(input: McpClientOAuthRefreshInput): Promise<OAuthTokens>;
248
+ }
249
+ /** Decode authenticated host storage; this does not admit endpoints or authorize execution. */
250
+ declare function parseMcpClientOAuthAuthority(value: unknown, options?: McpClientOAuthSnapshotOptions): McpClientOAuthAuthority;
251
+ /** Pure decoding and authority-digest verification; host session binding and atomic take remain required. */
252
+ declare function parseMcpClientOAuthAuthorizationTransaction(value: unknown, options?: McpClientOAuthSnapshotOptions): McpClientOAuthAuthorizationTransaction;
253
+ //#endregion
254
+ //#region src/oauth/bootstrap.d.ts
255
+ /** Stable, secret-free failure categories for OAuth bootstrap discovery. */
256
+ declare const McpClientOAuthBootstrapErrorCode: {
257
+ readonly InvalidOptions: "MCP_CLIENT_OAUTH_BOOTSTRAP_INVALID_OPTIONS";
258
+ readonly EndpointRejected: "MCP_CLIENT_OAUTH_BOOTSTRAP_ENDPOINT_REJECTED";
259
+ readonly DiscoveryFailed: "MCP_CLIENT_OAUTH_BOOTSTRAP_DISCOVERY_FAILED";
260
+ readonly ProtectedResourceInvalid: "MCP_CLIENT_OAUTH_BOOTSTRAP_PROTECTED_RESOURCE_INVALID";
261
+ readonly AuthorityInvalid: "MCP_CLIENT_OAUTH_BOOTSTRAP_AUTHORITY_INVALID";
262
+ };
263
+ type McpClientOAuthBootstrapErrorCode = (typeof McpClientOAuthBootstrapErrorCode)[keyof typeof McpClientOAuthBootstrapErrorCode];
264
+ /** A bounded public error. Its message never contains remote response data or URLs. */
265
+ declare class McpClientOAuthBootstrapError extends Error {
266
+ readonly code: McpClientOAuthBootstrapErrorCode;
267
+ constructor(code: McpClientOAuthBootstrapErrorCode);
268
+ }
269
+ type McpClientOAuthBootstrapEndpointKind = "resource-metadata" | "authorization-server-metadata" | "authorization" | "token";
270
+ interface McpClientOAuthBootstrapEndpointPolicyInput {
271
+ /** A disposable copy. Mutating it never changes the endpoint used by the bootstrap. */
272
+ readonly endpoint: URL;
273
+ readonly kind: McpClientOAuthBootstrapEndpointKind;
274
+ readonly credentialed: boolean;
275
+ readonly serverUrl: URL;
276
+ /** Present only after protected-resource metadata has been validated. */
277
+ readonly resource?: URL;
278
+ /** Exact, non-normalized RFC 8707 resource string corresponding to `resource`. */
279
+ readonly exactResource?: string;
280
+ /** Present only after an advertised authorization server has been selected. */
281
+ readonly issuer?: URL;
282
+ /** Exact, non-normalized issuer identifier corresponding to `issuer`. */
283
+ readonly exactIssuer?: string;
284
+ readonly signal?: AbortSignal;
285
+ }
286
+ /** Only literal `true` admits an endpoint; every other result fails closed. */
287
+ type McpClientOAuthBootstrapEndpointPolicy = (input: McpClientOAuthBootstrapEndpointPolicyInput) => boolean | PromiseLike<boolean>;
288
+ interface McpClientOAuthBootstrapOptions {
289
+ /**
290
+ * A host-owned SSRF-hardened fetch. It must pin DNS, reject redirects, and bound response
291
+ * bodies and time. The bootstrap additionally forces `redirect: "error"` and calls the
292
+ * endpoint policy before every generated discovery request.
293
+ */
294
+ readonly fetch: FetchLike;
295
+ readonly endpointPolicy: McpClientOAuthBootstrapEndpointPolicy;
296
+ readonly protocolVersion?: string;
297
+ }
298
+ /** Values extracted by the host from the MCP server's `WWW-Authenticate: Bearer` challenge. */
299
+ interface McpClientOAuthBootstrapChallenge {
300
+ readonly resourceMetadataUrl?: string;
301
+ readonly scope?: string;
302
+ }
303
+ interface McpClientOAuthBootstrapDiscoveryInput {
304
+ readonly serverUrl: string;
305
+ /**
306
+ * Challenge values take priority over constructed well-known locations and resource metadata
307
+ * scopes, as required by the MCP authorization specification.
308
+ */
309
+ readonly challenge?: McpClientOAuthBootstrapChallenge;
310
+ /**
311
+ * Raw response header from the initial `401`. The bootstrap extracts a bounded Bearer
312
+ * `resource_metadata` and `scope`; it is mutually exclusive with `challenge`.
313
+ */
314
+ readonly wwwAuthenticate?: string;
315
+ /** Exact issuer previously selected by host policy from a selection-required result. */
316
+ readonly issuer?: string;
317
+ readonly signal?: AbortSignal;
318
+ }
319
+ /** Bounded protected-resource discovery material that a host may persist. */
320
+ interface McpClientOAuthBootstrapResource {
321
+ readonly serverUrl: string;
322
+ readonly resource: string;
323
+ readonly resourceMetadataUrl: string;
324
+ readonly scopesSupported?: readonly string[];
325
+ }
326
+ interface McpClientOAuthBootstrapIssuerCandidate {
327
+ readonly issuer: string;
328
+ }
329
+ /**
330
+ * Reasons a current-spec authority cannot be handed to the intentionally stricter runtime
331
+ * protocol. These are compatibility facts, not a reason to trust or expose its endpoints.
332
+ */
333
+ declare const McpClientOAuthStrictCompatibilityIssue: {
334
+ readonly AuthorizationCodeResponseUnsupported: "authorization_code_response_unsupported";
335
+ readonly PkceS256Unsupported: "pkce_s256_unsupported";
336
+ readonly TokenEndpointAuthenticationUnsupported: "token_endpoint_authentication_unsupported";
337
+ readonly AuthorizationCodeGrantUnsupported: "authorization_code_grant_unsupported";
338
+ readonly QueryResponseModeUnsupported: "query_response_mode_unsupported";
339
+ /** @deprecated RFC 9207 support is optional and this issue is no longer emitted. */
340
+ readonly AuthorizationResponseIssuerUnsupported: "authorization_response_issuer_unsupported";
341
+ };
342
+ type McpClientOAuthStrictCompatibilityIssue = (typeof McpClientOAuthStrictCompatibilityIssue)[keyof typeof McpClientOAuthStrictCompatibilityIssue];
343
+ /** A selected authority that composes directly with `McpClientOAuthProtocol.startAuthorization`. */
344
+ interface McpClientOAuthBootstrapCandidate {
345
+ readonly authority: McpClientOAuthAuthority;
346
+ readonly clientIdMetadataDocumentSupported: boolean;
347
+ /**
348
+ * A validated, bounded legacy capability only. Discovery never invokes Dynamic Client
349
+ * Registration; a host must opt into any future registration operation separately.
350
+ */
351
+ readonly legacyDynamicRegistrationEndpoint?: string;
352
+ }
353
+ interface McpClientOAuthBootstrapSelectionRequired {
354
+ readonly kind: "authorization-server-selection-required";
355
+ readonly resource: McpClientOAuthBootstrapResource;
356
+ readonly scopes?: readonly string[];
357
+ readonly candidates: readonly McpClientOAuthBootstrapIssuerCandidate[];
358
+ }
359
+ interface McpClientOAuthBootstrapReady {
360
+ readonly kind: "ready";
361
+ readonly resource: McpClientOAuthBootstrapResource;
362
+ readonly scopes?: readonly string[];
363
+ readonly candidate: McpClientOAuthBootstrapCandidate;
364
+ }
365
+ interface McpClientOAuthBootstrapStrictProtocolUnsupported {
366
+ readonly kind: "strict-protocol-unsupported";
367
+ readonly resource: McpClientOAuthBootstrapResource;
368
+ readonly scopes?: readonly string[];
369
+ /** Validated RFC 8414/OIDC issuer; no unadmitted endpoint metadata is exposed. */
370
+ readonly issuer: string;
371
+ readonly issues: readonly McpClientOAuthStrictCompatibilityIssue[];
372
+ }
373
+ type McpClientOAuthBootstrapDiscoveryResult = McpClientOAuthBootstrapSelectionRequired | McpClientOAuthBootstrapReady | McpClientOAuthBootstrapStrictProtocolUnsupported;
374
+ /** Decode bounded host-persisted discovery without fetching, admitting endpoints, or registering clients. */
375
+ declare function parseMcpClientOAuthBootstrapDiscoveryResult(value: unknown, options?: McpClientOAuthSnapshotOptions): McpClientOAuthBootstrapDiscoveryResult;
376
+ /**
377
+ * Parses the bounded fields needed from a raw `WWW-Authenticate` header. It deliberately drops
378
+ * attacker-controlled OAuth error text and returns `undefined` when no Bearer challenge exists.
379
+ */
380
+ declare function parseMcpClientOAuthBootstrapChallenge(wwwAuthenticate: string): McpClientOAuthBootstrapChallenge | undefined;
381
+ /**
382
+ * Framework-neutral discovery bootstrap for an application-owned interactive OAuth flow.
383
+ *
384
+ * It owns no persistence, tenant policy, browser redirect, client registration, or token state.
385
+ * Hosts retain those responsibilities and pass a ready authority to `McpClientOAuthProtocol`.
386
+ */
387
+ declare class McpClientOAuthBootstrap {
388
+ #private;
389
+ constructor(options: McpClientOAuthBootstrapOptions);
390
+ discover(input: McpClientOAuthBootstrapDiscoveryInput): Promise<McpClientOAuthBootstrapDiscoveryResult>;
391
+ }
392
+ //#endregion
393
+ export { parseOAuthCallbackParameters as $, McpClientOAuthProtocolError as A, McpOAuthCallbackError as B, McpClientOAuthClientAuthentication as C, McpClientOAuthEndpointPolicyInput as D, McpClientOAuthEndpointPolicy as E, McpClientOAuthStartAuthorizationResult as F, McpOAuthStateError as G, McpOAuthCallbackParameters as H, parseMcpClientOAuthAuthority as I, McpOAuthStateValidationInput as J, McpOAuthStateErrorCode as K, parseMcpClientOAuthAuthorizationTransaction as L, McpClientOAuthProtocolOptions as M, McpClientOAuthRefreshInput as N, McpClientOAuthExchangeAuthorizationInput as O, McpClientOAuthStartAuthorizationInput as P, createPkceVerifier as Q, McpClientOAuthSnapshotError as R, McpClientOAuthClient as S, McpClientOAuthEndpointKind as T, McpOAuthCallbackSuccess as U, McpOAuthCallbackParameterInput as V, McpOAuthPkceGenerationOptions as W, createOAuthStateLookupDigest as X, createOAuthState as Y, createPkceS256Challenge as Z, McpClientOAuthStrictCompatibilityIssue as _, McpClientOAuthBootstrapDiscoveryResult as a, McpClientOAuthAuthority as b, McpClientOAuthBootstrapEndpointPolicyInput as c, McpClientOAuthBootstrapIssuerCandidate as d, validateOAuthState as et, McpClientOAuthBootstrapOptions as f, McpClientOAuthBootstrapStrictProtocolUnsupported as g, McpClientOAuthBootstrapSelectionRequired as h, McpClientOAuthBootstrapDiscoveryInput as i, McpClientOAuthProtocolErrorCode as j, McpClientOAuthProtocol as k, McpClientOAuthBootstrapError as l, McpClientOAuthBootstrapResource as m, McpClientOAuthBootstrapCandidate as n, McpClientOAuthBootstrapEndpointKind as o, McpClientOAuthBootstrapReady as p, McpOAuthStateGenerationOptions as q, McpClientOAuthBootstrapChallenge as r, McpClientOAuthBootstrapEndpointPolicy as s, McpClientOAuthBootstrap as t, McpClientOAuthBootstrapErrorCode as u, parseMcpClientOAuthBootstrapChallenge as v, McpClientOAuthDiscoveryInput as w, McpClientOAuthAuthorizationTransaction as x, parseMcpClientOAuthBootstrapDiscoveryResult as y, McpClientOAuthSnapshotOptions as z };
394
+ //# sourceMappingURL=bootstrap-BIAcDnHp.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-BIAcDnHp.d.mts","names":[],"sources":["../src/oauth/state.ts","../src/oauth/snapshot-data.ts","../src/oauth/protocol.ts","../src/oauth/bootstrap.ts"],"mappings":";;;cAmCa;WACZ;WACA;WACA;WACA;WACA;WACA;WACA;;KAGW,iCACH,qCAAq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