@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.
- package/CHANGELOG.md +139 -0
- package/README.md +845 -69
- package/dist/ai-sdk/index.d.mts +14 -0
- package/dist/ai-sdk/index.d.mts.map +1 -0
- package/dist/ai-sdk/index.mjs +27 -0
- package/dist/ai-sdk/index.mjs.map +1 -0
- package/dist/bootstrap-BIAcDnHp.d.mts +394 -0
- package/dist/bootstrap-BIAcDnHp.d.mts.map +1 -0
- package/dist/index.d.mts +480 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1960 -0
- package/dist/index.mjs.map +1 -0
- package/dist/oauth/dynamic-registration.d.mts +92 -0
- package/dist/oauth/dynamic-registration.d.mts.map +1 -0
- package/dist/oauth/dynamic-registration.mjs +392 -0
- package/dist/oauth/dynamic-registration.mjs.map +1 -0
- package/dist/oauth/index.d.mts +422 -0
- package/dist/oauth/index.d.mts.map +1 -0
- package/dist/oauth/index.mjs +3349 -0
- package/dist/oauth/index.mjs.map +1 -0
- package/dist/scope-CxGBCDdr.mjs +22 -0
- package/dist/scope-CxGBCDdr.mjs.map +1 -0
- package/package.json +76 -50
- package/scripts/external-smoke.mjs +693 -0
- package/dist/decorators/inject-mcp-client.decorator.d.ts +0 -3
- package/dist/decorators/inject-mcp-client.decorator.js +0 -12
- package/dist/decorators/on-notification.decorator.d.ts +0 -7
- package/dist/decorators/on-notification.decorator.js +0 -13
- package/dist/health/mcp-client.health.d.ts +0 -20
- package/dist/health/mcp-client.health.js +0 -42
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -64
- package/dist/interfaces/client-options.interface.d.ts +0 -139
- package/dist/interfaces/client-options.interface.js +0 -3
- package/dist/mcp-client.module.d.ts +0 -20
- package/dist/mcp-client.module.js +0 -188
- package/dist/mcp-client.service.d.ts +0 -558
- package/dist/mcp-client.service.js +0 -532
- package/dist/mcp-clients.service.d.ts +0 -39
- package/dist/mcp-clients.service.js +0 -104
- package/dist/testing/mock-client.d.ts +0 -67
- package/dist/testing/mock-client.js +0 -154
- package/dist/transport/apply-auth-headers.d.ts +0 -3
- package/dist/transport/apply-auth-headers.js +0 -13
- package/dist/transport/client-transport.factory.d.ts +0 -4
- package/dist/transport/client-transport.factory.js +0 -21
- package/dist/transport/sse-client.transport.d.ts +0 -4
- package/dist/transport/sse-client.transport.js +0 -15
- package/dist/transport/stdio-client.transport.d.ts +0 -4
- package/dist/transport/stdio-client.transport.js +0 -14
- package/dist/transport/streamable-client.transport.d.ts +0 -4
- package/dist/transport/streamable-client.transport.js +0 -17
- package/dist/utils/format-error-message.d.ts +0 -2
- package/dist/utils/format-error-message.js +0 -7
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { n as isMcpClientOAuthScopeToken } from "../scope-CxGBCDdr.mjs";
|
|
2
|
+
//#region src/oauth/dynamic-registration.ts
|
|
3
|
+
const MAX_URL_LENGTH = 4096;
|
|
4
|
+
const MAX_CLIENT_NAME_LENGTH = 256;
|
|
5
|
+
const MAX_CLIENT_ID_LENGTH = 2048;
|
|
6
|
+
const MAX_CLIENT_SECRET_LENGTH = 8192;
|
|
7
|
+
const MAX_REDIRECT_URI_COUNT = 16;
|
|
8
|
+
const MAX_CONTACT_COUNT = 16;
|
|
9
|
+
const MAX_METADATA_VALUE_LENGTH = 512;
|
|
10
|
+
const MAX_SCOPE_COUNT = 128;
|
|
11
|
+
const MAX_SCOPE_STRING_LENGTH = 4096;
|
|
12
|
+
const MAX_RESPONSE_BODY_BYTES = 65536;
|
|
13
|
+
/** Stable, secret-free failure categories for explicitly enabled legacy DCR. */
|
|
14
|
+
const McpClientOAuthDynamicRegistrationErrorCode = {
|
|
15
|
+
InvalidOptions: "MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_INVALID_OPTIONS",
|
|
16
|
+
Unsupported: "MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_UNSUPPORTED",
|
|
17
|
+
EndpointRejected: "MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_ENDPOINT_REJECTED",
|
|
18
|
+
RegistrationRejected: "MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_REJECTED",
|
|
19
|
+
ResponseInvalid: "MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_RESPONSE_INVALID",
|
|
20
|
+
OutcomeUnknown: "MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_OUTCOME_UNKNOWN"
|
|
21
|
+
};
|
|
22
|
+
/** Public errors contain no remote body, URL, client identifier, or host exception text. */
|
|
23
|
+
var McpClientOAuthDynamicRegistrationError = class extends Error {
|
|
24
|
+
code;
|
|
25
|
+
/** Whether the registration POST was handed to the host fetch. */
|
|
26
|
+
requestDispatched;
|
|
27
|
+
/** False after dispatch: retrying could create a second client registration. */
|
|
28
|
+
retrySafe;
|
|
29
|
+
constructor(code, requestDispatched = false) {
|
|
30
|
+
super(dynamicRegistrationErrorMessage(code));
|
|
31
|
+
this.name = "McpClientOAuthDynamicRegistrationError";
|
|
32
|
+
this.code = code;
|
|
33
|
+
this.requestDispatched = requestDispatched;
|
|
34
|
+
this.retrySafe = !requestDispatched;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Explicit compatibility primitive for deprecated Dynamic Client Registration.
|
|
39
|
+
*
|
|
40
|
+
* It is intentionally exported only from `@nest-mcp/client/oauth/dynamic-registration`; normal
|
|
41
|
+
* strict OAuth imports cannot invoke it. The host owns persistence, encryption, tenant policy,
|
|
42
|
+
* browser state, and the decision to opt into this legacy operation.
|
|
43
|
+
*/
|
|
44
|
+
var McpClientOAuthDynamicRegistration = class {
|
|
45
|
+
#fetch;
|
|
46
|
+
#endpointPolicy;
|
|
47
|
+
constructor(options) {
|
|
48
|
+
if (typeof options !== "object" || options === null || typeof options.fetch !== "function" || typeof options.endpointPolicy !== "function") throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
49
|
+
this.#fetch = options.fetch;
|
|
50
|
+
this.#endpointPolicy = options.endpointPolicy;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Performs one registration attempt. When a rejected error has `retrySafe === false`, the POST
|
|
54
|
+
* was already dispatched and the same logical registration must never be retried.
|
|
55
|
+
*/
|
|
56
|
+
async register(input) {
|
|
57
|
+
const operation = normalizeRegistrationInput(input);
|
|
58
|
+
throwIfAborted(operation.signal);
|
|
59
|
+
await this.#authorizeEndpoint(operation);
|
|
60
|
+
throwIfAborted(operation.signal);
|
|
61
|
+
const request = createRegistrationRequest(operation);
|
|
62
|
+
let response;
|
|
63
|
+
try {
|
|
64
|
+
response = await this.#fetch(new URL(operation.registrationEndpoint), {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: {
|
|
67
|
+
Accept: "application/json",
|
|
68
|
+
"Content-Type": "application/json"
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify(request),
|
|
71
|
+
redirect: "error",
|
|
72
|
+
...operation.signal === void 0 ? {} : { signal: operation.signal }
|
|
73
|
+
});
|
|
74
|
+
} catch {
|
|
75
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.OutcomeUnknown, true);
|
|
76
|
+
}
|
|
77
|
+
if (response.redirected || response.url.length > 0 && !isExactResponseUrl(response.url, operation.registrationEndpoint)) {
|
|
78
|
+
await discardResponse(response);
|
|
79
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.EndpointRejected, true);
|
|
80
|
+
}
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
await discardResponse(response);
|
|
83
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.RegistrationRejected, true);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return normalizeRegistrationResult(operation, await readBoundedJson(response));
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error instanceof McpClientOAuthDynamicRegistrationError) throw registrationError(error.code, true);
|
|
89
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid, true);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async #authorizeEndpoint(operation) {
|
|
93
|
+
let admitted;
|
|
94
|
+
try {
|
|
95
|
+
admitted = await awaitWithSignal(Promise.resolve().then(() => this.#endpointPolicy(Object.freeze({
|
|
96
|
+
endpoint: new URL(operation.registrationEndpoint),
|
|
97
|
+
exactRegistrationEndpoint: operation.registrationEndpoint,
|
|
98
|
+
issuer: new URL(operation.issuer),
|
|
99
|
+
exactIssuer: operation.issuer,
|
|
100
|
+
serverUrl: new URL(operation.serverUrl),
|
|
101
|
+
resource: new URL(operation.resource),
|
|
102
|
+
method: "POST",
|
|
103
|
+
credentialed: false,
|
|
104
|
+
...operation.signal === void 0 ? {} : { signal: operation.signal }
|
|
105
|
+
}))), operation.signal);
|
|
106
|
+
} catch {
|
|
107
|
+
throwIfAborted(operation.signal);
|
|
108
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.EndpointRejected);
|
|
109
|
+
}
|
|
110
|
+
throwIfAborted(operation.signal);
|
|
111
|
+
if (admitted !== true) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.EndpointRejected);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
function normalizeRegistrationInput(input) {
|
|
115
|
+
if (typeof input !== "object" || input === null) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
116
|
+
const candidate = input.candidate;
|
|
117
|
+
if (typeof candidate !== "object" || candidate === null || typeof candidate.authority !== "object" || candidate.authority === null) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
118
|
+
if (candidate.legacyDynamicRegistrationEndpoint === void 0) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.Unsupported);
|
|
119
|
+
if (!Array.isArray(candidate.authority.tokenEndpointAuthMethodsSupported) || !candidate.authority.tokenEndpointAuthMethodsSupported.includes("none")) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.Unsupported);
|
|
120
|
+
const issuer = requireIssuer(candidate.authority.issuer);
|
|
121
|
+
const serverUrl = requireHttpsUrl(candidate.authority.serverUrl, true).href;
|
|
122
|
+
const resource = requireHttpsUrl(candidate.authority.resource, true).href;
|
|
123
|
+
const registrationEndpoint = requireHttpsUrl(candidate.legacyDynamicRegistrationEndpoint, true).href;
|
|
124
|
+
const metadata = input.clientMetadata;
|
|
125
|
+
if (typeof metadata !== "object" || metadata === null) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
126
|
+
const clientName = requireBoundedText(metadata.clientName, MAX_CLIENT_NAME_LENGTH);
|
|
127
|
+
const redirectUris = normalizeRedirectUris(metadata.redirectUris);
|
|
128
|
+
const applicationType = normalizeApplicationType(metadata.applicationType);
|
|
129
|
+
if (applicationType === "web" && redirectUris.some(isLoopbackHttpRedirect)) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
130
|
+
const clientUri = normalizeOptionalHttpsUrl(metadata.clientUri);
|
|
131
|
+
const contacts = normalizeOptionalTextList(metadata.contacts, MAX_CONTACT_COUNT);
|
|
132
|
+
const softwareId = normalizeOptionalText(metadata.softwareId);
|
|
133
|
+
const softwareVersion = normalizeOptionalText(metadata.softwareVersion);
|
|
134
|
+
const scopes = normalizeOptionalScopes(input.scopes);
|
|
135
|
+
return Object.freeze({
|
|
136
|
+
issuer,
|
|
137
|
+
serverUrl,
|
|
138
|
+
resource,
|
|
139
|
+
registrationEndpoint,
|
|
140
|
+
clientName,
|
|
141
|
+
redirectUris,
|
|
142
|
+
applicationType,
|
|
143
|
+
...clientUri === void 0 ? {} : { clientUri },
|
|
144
|
+
...contacts === void 0 ? {} : { contacts },
|
|
145
|
+
...softwareId === void 0 ? {} : { softwareId },
|
|
146
|
+
...softwareVersion === void 0 ? {} : { softwareVersion },
|
|
147
|
+
...scopes === void 0 ? {} : { scopes },
|
|
148
|
+
signal: input.signal
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function createRegistrationRequest(input) {
|
|
152
|
+
return {
|
|
153
|
+
client_name: input.clientName,
|
|
154
|
+
redirect_uris: [...input.redirectUris],
|
|
155
|
+
token_endpoint_auth_method: "none",
|
|
156
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
157
|
+
response_types: ["code"],
|
|
158
|
+
application_type: input.applicationType,
|
|
159
|
+
...input.clientUri === void 0 ? {} : { client_uri: input.clientUri },
|
|
160
|
+
...input.contacts === void 0 ? {} : { contacts: [...input.contacts] },
|
|
161
|
+
...input.softwareId === void 0 ? {} : { software_id: input.softwareId },
|
|
162
|
+
...input.softwareVersion === void 0 ? {} : { software_version: input.softwareVersion },
|
|
163
|
+
...input.scopes === void 0 ? {} : { scope: input.scopes.join(" ") }
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function normalizeRegistrationResult(input, value) {
|
|
167
|
+
if (!isPlainRecord(value)) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
168
|
+
const clientId = requireRemoteBoundedText(value.client_id, MAX_CLIENT_ID_LENGTH);
|
|
169
|
+
const clientSecret = normalizeRemoteOptionalSecret(value.client_secret);
|
|
170
|
+
if (!sameStrings(normalizeRemoteStringList(value.redirect_uris, MAX_REDIRECT_URI_COUNT), input.redirectUris)) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
171
|
+
if (value.application_type !== void 0 && value.application_type !== input.applicationType) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
172
|
+
if (value.token_endpoint_auth_method !== void 0 && value.token_endpoint_auth_method !== "none") throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
173
|
+
const responseTypes = normalizeRemoteOptionalStringList(value.response_types, 16);
|
|
174
|
+
const grantTypes = normalizeRemoteOptionalStringList(value.grant_types, 16);
|
|
175
|
+
if (responseTypes !== void 0 && !responseTypes.includes("code") || grantTypes !== void 0 && !grantTypes.includes("authorization_code")) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
176
|
+
const clientIdIssuedAt = normalizeRemoteOptionalTimestamp(value.client_id_issued_at);
|
|
177
|
+
const clientSecretExpiresAt = normalizeRemoteOptionalTimestamp(value.client_secret_expires_at);
|
|
178
|
+
const registeredScopes = normalizeRemoteOptionalScope(value.scope);
|
|
179
|
+
return Object.freeze({
|
|
180
|
+
issuer: input.issuer,
|
|
181
|
+
client: Object.freeze({
|
|
182
|
+
clientId,
|
|
183
|
+
authentication: Object.freeze({ method: "none" })
|
|
184
|
+
}),
|
|
185
|
+
...clientSecret === void 0 ? {} : { clientSecret },
|
|
186
|
+
...clientIdIssuedAt === void 0 ? {} : { clientIdIssuedAt },
|
|
187
|
+
...clientSecretExpiresAt === void 0 ? {} : { clientSecretExpiresAt },
|
|
188
|
+
...registeredScopes === void 0 ? {} : { registeredScopes }
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async function readBoundedJson(response) {
|
|
192
|
+
if (response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() !== "application/json") {
|
|
193
|
+
await discardResponse(response);
|
|
194
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
195
|
+
}
|
|
196
|
+
const declaredLength = response.headers.get("content-length");
|
|
197
|
+
if (declaredLength !== null) {
|
|
198
|
+
const length = Number(declaredLength);
|
|
199
|
+
if (!Number.isSafeInteger(length) || length < 0 || length > MAX_RESPONSE_BODY_BYTES) {
|
|
200
|
+
await discardResponse(response);
|
|
201
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
let body;
|
|
205
|
+
try {
|
|
206
|
+
body = await response.text();
|
|
207
|
+
} catch {
|
|
208
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
209
|
+
}
|
|
210
|
+
if (body.length === 0 || body.length > MAX_RESPONSE_BODY_BYTES || new TextEncoder().encode(body).byteLength > MAX_RESPONSE_BODY_BYTES) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
211
|
+
try {
|
|
212
|
+
return JSON.parse(body);
|
|
213
|
+
} catch {
|
|
214
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async function discardResponse(response) {
|
|
218
|
+
try {
|
|
219
|
+
await response.body?.cancel();
|
|
220
|
+
} catch {}
|
|
221
|
+
}
|
|
222
|
+
function normalizeRedirectUris(values) {
|
|
223
|
+
if (!Array.isArray(values) || values.length === 0 || values.length > MAX_REDIRECT_URI_COUNT) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
224
|
+
const normalized = [...new Set(values.map(normalizeRedirectUri))];
|
|
225
|
+
if (normalized.length !== values.length) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
226
|
+
return Object.freeze(normalized);
|
|
227
|
+
}
|
|
228
|
+
function normalizeApplicationType(value) {
|
|
229
|
+
if (value !== "native" && value !== "web") throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
230
|
+
return value;
|
|
231
|
+
}
|
|
232
|
+
function normalizeRedirectUri(value) {
|
|
233
|
+
const url = requireUrl(value);
|
|
234
|
+
if (url.username.length > 0 || url.password.length > 0 || url.hash.length > 0 || url.protocol !== "https:" && !isLoopbackHttpRedirect(url.href)) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
235
|
+
return url.href;
|
|
236
|
+
}
|
|
237
|
+
function isLoopbackHttpRedirect(value) {
|
|
238
|
+
let url;
|
|
239
|
+
try {
|
|
240
|
+
url = new URL(value);
|
|
241
|
+
} catch {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
if (url.protocol !== "http:") return false;
|
|
245
|
+
const host = url.hostname.toLowerCase();
|
|
246
|
+
if (host === "localhost" || host === "[::1]") return true;
|
|
247
|
+
const octets = host.split(".");
|
|
248
|
+
return octets.length === 4 && octets[0] === "127" && octets.every(isDecimalOctet);
|
|
249
|
+
}
|
|
250
|
+
function isDecimalOctet(value) {
|
|
251
|
+
if (!/^\d{1,3}$/u.test(value)) return false;
|
|
252
|
+
const parsed = Number(value);
|
|
253
|
+
return parsed >= 0 && parsed <= 255 && String(parsed) === value;
|
|
254
|
+
}
|
|
255
|
+
function normalizeOptionalHttpsUrl(value) {
|
|
256
|
+
return value === void 0 ? void 0 : requireHttpsUrl(value, true).href;
|
|
257
|
+
}
|
|
258
|
+
function normalizeOptionalText(value) {
|
|
259
|
+
return value === void 0 ? void 0 : requireBoundedText(value, MAX_METADATA_VALUE_LENGTH);
|
|
260
|
+
}
|
|
261
|
+
function normalizeOptionalTextList(values, maximumCount) {
|
|
262
|
+
if (values === void 0) return void 0;
|
|
263
|
+
if (!Array.isArray(values) || values.length === 0 || values.length > maximumCount) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
264
|
+
const normalized = values.map((value) => requireBoundedText(value, MAX_METADATA_VALUE_LENGTH));
|
|
265
|
+
return Object.freeze(normalized);
|
|
266
|
+
}
|
|
267
|
+
function normalizeOptionalScopes(values) {
|
|
268
|
+
if (values === void 0) return void 0;
|
|
269
|
+
if (!Array.isArray(values) || values.length > MAX_SCOPE_COUNT) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
270
|
+
if (values.length === 0) return void 0;
|
|
271
|
+
const normalized = [...new Set(values)];
|
|
272
|
+
for (const value of normalized) requireScopeToken(value);
|
|
273
|
+
if (normalized.join(" ").length > MAX_SCOPE_STRING_LENGTH) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
274
|
+
return Object.freeze(normalized);
|
|
275
|
+
}
|
|
276
|
+
function normalizeRemoteOptionalScope(value) {
|
|
277
|
+
if (value === void 0) return void 0;
|
|
278
|
+
if (typeof value !== "string" || value.length === 0 || value.length > MAX_SCOPE_STRING_LENGTH) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
279
|
+
const scopes = value.split(" ");
|
|
280
|
+
if (scopes.length > MAX_SCOPE_COUNT) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
281
|
+
for (const scope of scopes) requireRemoteScopeToken(scope);
|
|
282
|
+
return Object.freeze([...new Set(scopes)]);
|
|
283
|
+
}
|
|
284
|
+
function normalizeRemoteStringList(value, maximumCount) {
|
|
285
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > maximumCount) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
286
|
+
const result = [];
|
|
287
|
+
for (const item of value) result.push(requireRemoteBoundedText(item, MAX_URL_LENGTH));
|
|
288
|
+
return Object.freeze(result);
|
|
289
|
+
}
|
|
290
|
+
function normalizeRemoteOptionalStringList(value, maximumCount) {
|
|
291
|
+
return value === void 0 ? void 0 : normalizeRemoteStringList(value, maximumCount);
|
|
292
|
+
}
|
|
293
|
+
function normalizeRemoteOptionalSecret(value) {
|
|
294
|
+
if (value === void 0) return void 0;
|
|
295
|
+
return requireRemoteBoundedText(value, MAX_CLIENT_SECRET_LENGTH);
|
|
296
|
+
}
|
|
297
|
+
function normalizeRemoteOptionalTimestamp(value) {
|
|
298
|
+
if (value === void 0) return void 0;
|
|
299
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
300
|
+
return value;
|
|
301
|
+
}
|
|
302
|
+
function requireIssuer(value) {
|
|
303
|
+
requireHttpsUrl(value, false);
|
|
304
|
+
return value;
|
|
305
|
+
}
|
|
306
|
+
function requireHttpsUrl(value, query) {
|
|
307
|
+
const url = requireUrl(value);
|
|
308
|
+
if (url.protocol !== "https:" || url.username.length > 0 || url.password.length > 0 || url.hash.length > 0 || !query && url.search.length > 0) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
309
|
+
return url;
|
|
310
|
+
}
|
|
311
|
+
function requireUrl(value) {
|
|
312
|
+
if (typeof value !== "string" || value.length === 0 || value.length > MAX_URL_LENGTH) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
313
|
+
try {
|
|
314
|
+
return new URL(value);
|
|
315
|
+
} catch {
|
|
316
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function requireBoundedText(value, maximumLength) {
|
|
320
|
+
if (typeof value !== "string" || value.length === 0 || value.length > maximumLength || containsControlCharacter(value)) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
321
|
+
return value;
|
|
322
|
+
}
|
|
323
|
+
function requireRemoteBoundedText(value, maximumLength) {
|
|
324
|
+
if (typeof value !== "string" || value.length === 0 || value.length > maximumLength || containsControlCharacter(value)) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
function requireScopeToken(value) {
|
|
328
|
+
if (!isMcpClientOAuthScopeToken(value)) throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);
|
|
329
|
+
}
|
|
330
|
+
function requireRemoteScopeToken(value) {
|
|
331
|
+
try {
|
|
332
|
+
requireScopeToken(value);
|
|
333
|
+
} catch {
|
|
334
|
+
throw registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function isPlainRecord(value) {
|
|
338
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
339
|
+
}
|
|
340
|
+
function sameStrings(left, right) {
|
|
341
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
342
|
+
}
|
|
343
|
+
function isExactResponseUrl(value, expected) {
|
|
344
|
+
try {
|
|
345
|
+
return new URL(value).href === expected;
|
|
346
|
+
} catch {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function awaitWithSignal(promise, signal) {
|
|
351
|
+
if (signal === void 0) return Promise.resolve(promise);
|
|
352
|
+
signal.throwIfAborted();
|
|
353
|
+
return new Promise((resolve, reject) => {
|
|
354
|
+
const onAbort = () => reject(signal.reason);
|
|
355
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
356
|
+
Promise.resolve(promise).then((value) => {
|
|
357
|
+
signal.removeEventListener("abort", onAbort);
|
|
358
|
+
resolve(value);
|
|
359
|
+
}, (error) => {
|
|
360
|
+
signal.removeEventListener("abort", onAbort);
|
|
361
|
+
reject(error);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
function throwIfAborted(signal) {
|
|
366
|
+
signal?.throwIfAborted();
|
|
367
|
+
}
|
|
368
|
+
function containsControlCharacter(value) {
|
|
369
|
+
for (const character of value) {
|
|
370
|
+
const point = character.codePointAt(0);
|
|
371
|
+
if (point !== void 0 && (point <= 31 || point >= 127 && point <= 159)) return true;
|
|
372
|
+
}
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
function registrationError(code, requestDispatched = false) {
|
|
376
|
+
return new McpClientOAuthDynamicRegistrationError(code, requestDispatched);
|
|
377
|
+
}
|
|
378
|
+
function dynamicRegistrationErrorMessage(code) {
|
|
379
|
+
switch (code) {
|
|
380
|
+
case McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions: return "The dynamic registration options are invalid.";
|
|
381
|
+
case McpClientOAuthDynamicRegistrationErrorCode.Unsupported: return "The selected OAuth authority does not advertise dynamic registration.";
|
|
382
|
+
case McpClientOAuthDynamicRegistrationErrorCode.EndpointRejected: return "The dynamic registration endpoint was rejected.";
|
|
383
|
+
case McpClientOAuthDynamicRegistrationErrorCode.RegistrationRejected: return "The authorization server rejected dynamic registration.";
|
|
384
|
+
case McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid: return "The dynamic registration response is invalid.";
|
|
385
|
+
case McpClientOAuthDynamicRegistrationErrorCode.OutcomeUnknown: return "The dynamic registration outcome is unknown and must not be retried.";
|
|
386
|
+
default: return "Dynamic registration failed.";
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
//#endregion
|
|
390
|
+
export { McpClientOAuthDynamicRegistration, McpClientOAuthDynamicRegistrationError, McpClientOAuthDynamicRegistrationErrorCode };
|
|
391
|
+
|
|
392
|
+
//# sourceMappingURL=dynamic-registration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-registration.mjs","names":["#fetch","#endpointPolicy","#authorizeEndpoint"],"sources":["../../src/oauth/dynamic-registration.ts"],"sourcesContent":["import type { FetchLike } from \"@modelcontextprotocol/client\";\n\nimport type { McpClientOAuthBootstrapCandidate } from \"./bootstrap.ts\";\nimport type { McpClientOAuthClient } from \"./protocol.ts\";\nimport { isMcpClientOAuthScopeToken } from \"./scope.ts\";\n\nconst MAX_URL_LENGTH = 4_096;\nconst MAX_CLIENT_NAME_LENGTH = 256;\nconst MAX_CLIENT_ID_LENGTH = 2_048;\nconst MAX_CLIENT_SECRET_LENGTH = 8_192;\nconst MAX_REDIRECT_URI_COUNT = 16;\nconst MAX_CONTACT_COUNT = 16;\nconst MAX_METADATA_VALUE_LENGTH = 512;\nconst MAX_SCOPE_COUNT = 128;\nconst MAX_SCOPE_STRING_LENGTH = 4_096;\nconst MAX_RESPONSE_BODY_BYTES = 64 * 1_024;\n\n/** Stable, secret-free failure categories for explicitly enabled legacy DCR. */\nexport const McpClientOAuthDynamicRegistrationErrorCode = {\n\tInvalidOptions: \"MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_INVALID_OPTIONS\",\n\tUnsupported: \"MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_UNSUPPORTED\",\n\tEndpointRejected: \"MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_ENDPOINT_REJECTED\",\n\tRegistrationRejected: \"MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_REJECTED\",\n\tResponseInvalid: \"MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_RESPONSE_INVALID\",\n\tOutcomeUnknown: \"MCP_CLIENT_OAUTH_DYNAMIC_REGISTRATION_OUTCOME_UNKNOWN\",\n} as const;\n\nexport type McpClientOAuthDynamicRegistrationErrorCode =\n\t(typeof McpClientOAuthDynamicRegistrationErrorCode)[keyof typeof McpClientOAuthDynamicRegistrationErrorCode];\n\n/** Public errors contain no remote body, URL, client identifier, or host exception text. */\nexport class McpClientOAuthDynamicRegistrationError extends Error {\n\treadonly code: McpClientOAuthDynamicRegistrationErrorCode;\n\t/** Whether the registration POST was handed to the host fetch. */\n\treadonly requestDispatched: boolean;\n\t/** False after dispatch: retrying could create a second client registration. */\n\treadonly retrySafe: boolean;\n\n\tconstructor(code: McpClientOAuthDynamicRegistrationErrorCode, requestDispatched = false) {\n\t\tsuper(dynamicRegistrationErrorMessage(code));\n\t\tthis.name = \"McpClientOAuthDynamicRegistrationError\";\n\t\tthis.code = code;\n\t\tthis.requestDispatched = requestDispatched;\n\t\tthis.retrySafe = !requestDispatched;\n\t}\n}\n\nexport interface McpClientOAuthDynamicRegistrationEndpointPolicyInput {\n\t/** A disposable copy; mutation cannot change the request destination. */\n\treadonly endpoint: URL;\n\treadonly exactRegistrationEndpoint: string;\n\treadonly issuer: URL;\n\t/** Preserved exactly for issuer binding and RFC 9207 comparisons. */\n\treadonly exactIssuer: string;\n\treadonly serverUrl: URL;\n\treadonly resource: URL;\n\treadonly method: \"POST\";\n\treadonly credentialed: false;\n\treadonly signal?: AbortSignal;\n}\n\n/** Only literal `true` admits the single registration POST. */\nexport type McpClientOAuthDynamicRegistrationEndpointPolicy = (\n\tinput: McpClientOAuthDynamicRegistrationEndpointPolicyInput,\n) => boolean | PromiseLike<boolean>;\n\nexport interface McpClientOAuthDynamicRegistrationOptions {\n\t/**\n\t * A host-owned SSRF-hardened fetch with DNS pinning, response byte/time limits, and no retries.\n\t * This primitive additionally forces `redirect: \"error\"` and invokes it exactly once.\n\t */\n\treadonly fetch: FetchLike;\n\treadonly endpointPolicy: McpClientOAuthDynamicRegistrationEndpointPolicy;\n}\n\n/** Narrow allowlist for a public authorization-code client's RFC 7591 request metadata. */\nexport interface McpClientOAuthDynamicRegistrationClientMetadata {\n\treadonly clientName: string;\n\t/** Explicit RFC 7591 application classification; never inferred from redirect URI shape. */\n\treadonly applicationType: \"native\" | \"web\";\n\treadonly redirectUris: readonly string[];\n\treadonly clientUri?: string;\n\treadonly contacts?: readonly string[];\n\treadonly softwareId?: string;\n\treadonly softwareVersion?: string;\n}\n\nexport interface McpClientOAuthDynamicRegistrationInput {\n\t/** Must be the selected `ready.candidate` returned by `McpClientOAuthBootstrap`. */\n\treadonly candidate: McpClientOAuthBootstrapCandidate;\n\treadonly clientMetadata: McpClientOAuthDynamicRegistrationClientMetadata;\n\treadonly scopes?: readonly string[];\n\treadonly signal?: AbortSignal;\n}\n\nexport interface McpClientOAuthDynamicRegistrationResult {\n\treadonly issuer: string;\n\t/** Directly consumable by `McpClientOAuthProtocol.startAuthorization`. */\n\treadonly client: McpClientOAuthClient;\n\t/** Some legacy servers issue a non-confidential secret even to public clients. */\n\treadonly clientSecret?: string;\n\treadonly clientIdIssuedAt?: number;\n\treadonly clientSecretExpiresAt?: number;\n\treadonly registeredScopes?: readonly string[];\n}\n\n/**\n * Explicit compatibility primitive for deprecated Dynamic Client Registration.\n *\n * It is intentionally exported only from `@nest-mcp/client/oauth/dynamic-registration`; normal\n * strict OAuth imports cannot invoke it. The host owns persistence, encryption, tenant policy,\n * browser state, and the decision to opt into this legacy operation.\n */\nexport class McpClientOAuthDynamicRegistration {\n\treadonly #fetch: FetchLike;\n\treadonly #endpointPolicy: McpClientOAuthDynamicRegistrationEndpointPolicy;\n\n\tconstructor(options: McpClientOAuthDynamicRegistrationOptions) {\n\t\tif (\n\t\t\ttypeof options !== \"object\" ||\n\t\t\toptions === null ||\n\t\t\ttypeof options.fetch !== \"function\" ||\n\t\t\ttypeof options.endpointPolicy !== \"function\"\n\t\t) {\n\t\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t\t}\n\t\tthis.#fetch = options.fetch;\n\t\tthis.#endpointPolicy = options.endpointPolicy;\n\t}\n\n\t/**\n\t * Performs one registration attempt. When a rejected error has `retrySafe === false`, the POST\n\t * was already dispatched and the same logical registration must never be retried.\n\t */\n\tasync register(\n\t\tinput: McpClientOAuthDynamicRegistrationInput,\n\t): Promise<McpClientOAuthDynamicRegistrationResult> {\n\t\tconst operation = normalizeRegistrationInput(input);\n\t\tthrowIfAborted(operation.signal);\n\t\tawait this.#authorizeEndpoint(operation);\n\t\tthrowIfAborted(operation.signal);\n\n\t\tconst request = createRegistrationRequest(operation);\n\t\tlet response: Response;\n\t\ttry {\n\t\t\t// From this point onward any thrown failure is ambiguous: the AS may have registered the\n\t\t\t// client before the response was lost. Callers must not retry this logical operation.\n\t\t\tresponse = await this.#fetch(new URL(operation.registrationEndpoint), {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify(request),\n\t\t\t\tredirect: \"error\",\n\t\t\t\t...(operation.signal === undefined ? {} : { signal: operation.signal }),\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.OutcomeUnknown, true);\n\t\t}\n\n\t\tif (\n\t\t\tresponse.redirected ||\n\t\t\t(response.url.length > 0 && !isExactResponseUrl(response.url, operation.registrationEndpoint))\n\t\t) {\n\t\t\tawait discardResponse(response);\n\t\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.EndpointRejected, true);\n\t\t}\n\t\tif (!response.ok) {\n\t\t\tawait discardResponse(response);\n\t\t\tthrow registrationError(\n\t\t\t\tMcpClientOAuthDynamicRegistrationErrorCode.RegistrationRejected,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tconst body = await readBoundedJson(response);\n\t\t\treturn normalizeRegistrationResult(operation, body);\n\t\t} catch (error) {\n\t\t\tif (error instanceof McpClientOAuthDynamicRegistrationError) {\n\t\t\t\tthrow registrationError(error.code, true);\n\t\t\t}\n\t\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid, true);\n\t\t}\n\t}\n\n\tasync #authorizeEndpoint(operation: NormalizedRegistrationInput): Promise<void> {\n\t\tlet admitted: unknown;\n\t\ttry {\n\t\t\tadmitted = await awaitWithSignal(\n\t\t\t\tPromise.resolve().then(() =>\n\t\t\t\t\tthis.#endpointPolicy(\n\t\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\t\tendpoint: new URL(operation.registrationEndpoint),\n\t\t\t\t\t\t\texactRegistrationEndpoint: operation.registrationEndpoint,\n\t\t\t\t\t\t\tissuer: new URL(operation.issuer),\n\t\t\t\t\t\t\texactIssuer: operation.issuer,\n\t\t\t\t\t\t\tserverUrl: new URL(operation.serverUrl),\n\t\t\t\t\t\t\tresource: new URL(operation.resource),\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t\tcredentialed: false,\n\t\t\t\t\t\t\t...(operation.signal === undefined ? {} : { signal: operation.signal }),\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t\toperation.signal,\n\t\t\t);\n\t\t} catch {\n\t\t\tthrowIfAborted(operation.signal);\n\t\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.EndpointRejected);\n\t\t}\n\t\tthrowIfAborted(operation.signal);\n\t\tif (admitted !== true) {\n\t\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.EndpointRejected);\n\t\t}\n\t}\n}\n\ninterface NormalizedRegistrationInput {\n\treadonly issuer: string;\n\treadonly serverUrl: string;\n\treadonly resource: string;\n\treadonly registrationEndpoint: string;\n\treadonly clientName: string;\n\treadonly redirectUris: readonly string[];\n\treadonly applicationType: \"native\" | \"web\";\n\treadonly clientUri?: string;\n\treadonly contacts?: readonly string[];\n\treadonly softwareId?: string;\n\treadonly softwareVersion?: string;\n\treadonly scopes?: readonly string[];\n\treadonly signal: AbortSignal | undefined;\n}\n\nfunction normalizeRegistrationInput(\n\tinput: McpClientOAuthDynamicRegistrationInput,\n): NormalizedRegistrationInput {\n\tif (typeof input !== \"object\" || input === null) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\tconst candidate = input.candidate;\n\tif (\n\t\ttypeof candidate !== \"object\" ||\n\t\tcandidate === null ||\n\t\ttypeof candidate.authority !== \"object\" ||\n\t\tcandidate.authority === null\n\t) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\tif (candidate.legacyDynamicRegistrationEndpoint === undefined) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.Unsupported);\n\t}\n\tif (\n\t\t!Array.isArray(candidate.authority.tokenEndpointAuthMethodsSupported) ||\n\t\t!candidate.authority.tokenEndpointAuthMethodsSupported.includes(\"none\")\n\t) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.Unsupported);\n\t}\n\tconst issuer = requireIssuer(candidate.authority.issuer);\n\tconst serverUrl = requireHttpsUrl(candidate.authority.serverUrl, true).href;\n\tconst resource = requireHttpsUrl(candidate.authority.resource, true).href;\n\tconst registrationEndpoint = requireHttpsUrl(\n\t\tcandidate.legacyDynamicRegistrationEndpoint,\n\t\ttrue,\n\t).href;\n\tconst metadata = input.clientMetadata;\n\tif (typeof metadata !== \"object\" || metadata === null) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\tconst clientName = requireBoundedText(metadata.clientName, MAX_CLIENT_NAME_LENGTH);\n\tconst redirectUris = normalizeRedirectUris(metadata.redirectUris);\n\tconst applicationType = normalizeApplicationType(metadata.applicationType);\n\tif (applicationType === \"web\" && redirectUris.some(isLoopbackHttpRedirect)) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\tconst clientUri = normalizeOptionalHttpsUrl(metadata.clientUri);\n\tconst contacts = normalizeOptionalTextList(metadata.contacts, MAX_CONTACT_COUNT);\n\tconst softwareId = normalizeOptionalText(metadata.softwareId);\n\tconst softwareVersion = normalizeOptionalText(metadata.softwareVersion);\n\tconst scopes = normalizeOptionalScopes(input.scopes);\n\treturn Object.freeze({\n\t\tissuer,\n\t\tserverUrl,\n\t\tresource,\n\t\tregistrationEndpoint,\n\t\tclientName,\n\t\tredirectUris,\n\t\tapplicationType,\n\t\t...(clientUri === undefined ? {} : { clientUri }),\n\t\t...(contacts === undefined ? {} : { contacts }),\n\t\t...(softwareId === undefined ? {} : { softwareId }),\n\t\t...(softwareVersion === undefined ? {} : { softwareVersion }),\n\t\t...(scopes === undefined ? {} : { scopes }),\n\t\tsignal: input.signal,\n\t});\n}\n\nfunction createRegistrationRequest(input: NormalizedRegistrationInput): Record<string, unknown> {\n\treturn {\n\t\tclient_name: input.clientName,\n\t\tredirect_uris: [...input.redirectUris],\n\t\ttoken_endpoint_auth_method: \"none\",\n\t\tgrant_types: [\"authorization_code\", \"refresh_token\"],\n\t\tresponse_types: [\"code\"],\n\t\tapplication_type: input.applicationType,\n\t\t...(input.clientUri === undefined ? {} : { client_uri: input.clientUri }),\n\t\t...(input.contacts === undefined ? {} : { contacts: [...input.contacts] }),\n\t\t...(input.softwareId === undefined ? {} : { software_id: input.softwareId }),\n\t\t...(input.softwareVersion === undefined ? {} : { software_version: input.softwareVersion }),\n\t\t...(input.scopes === undefined ? {} : { scope: input.scopes.join(\" \") }),\n\t};\n}\n\nfunction normalizeRegistrationResult(\n\tinput: NormalizedRegistrationInput,\n\tvalue: unknown,\n): McpClientOAuthDynamicRegistrationResult {\n\tif (!isPlainRecord(value)) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tconst clientId = requireRemoteBoundedText(value.client_id, MAX_CLIENT_ID_LENGTH);\n\tconst clientSecret = normalizeRemoteOptionalSecret(value.client_secret);\n\tconst redirectUris = normalizeRemoteStringList(value.redirect_uris, MAX_REDIRECT_URI_COUNT);\n\tif (!sameStrings(redirectUris, input.redirectUris)) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tif (value.application_type !== undefined && value.application_type !== input.applicationType) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tif (\n\t\tvalue.token_endpoint_auth_method !== undefined &&\n\t\tvalue.token_endpoint_auth_method !== \"none\"\n\t) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tconst responseTypes = normalizeRemoteOptionalStringList(value.response_types, 16);\n\tconst grantTypes = normalizeRemoteOptionalStringList(value.grant_types, 16);\n\tif (\n\t\t(responseTypes !== undefined && !responseTypes.includes(\"code\")) ||\n\t\t(grantTypes !== undefined && !grantTypes.includes(\"authorization_code\"))\n\t) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tconst clientIdIssuedAt = normalizeRemoteOptionalTimestamp(value.client_id_issued_at);\n\tconst clientSecretExpiresAt = normalizeRemoteOptionalTimestamp(value.client_secret_expires_at);\n\tconst registeredScopes = normalizeRemoteOptionalScope(value.scope);\n\treturn Object.freeze({\n\t\tissuer: input.issuer,\n\t\tclient: Object.freeze({\n\t\t\tclientId,\n\t\t\tauthentication: Object.freeze({ method: \"none\" }),\n\t\t}),\n\t\t...(clientSecret === undefined ? {} : { clientSecret }),\n\t\t...(clientIdIssuedAt === undefined ? {} : { clientIdIssuedAt }),\n\t\t...(clientSecretExpiresAt === undefined ? {} : { clientSecretExpiresAt }),\n\t\t...(registeredScopes === undefined ? {} : { registeredScopes }),\n\t});\n}\n\nasync function readBoundedJson(response: Response): Promise<unknown> {\n\tconst contentType = response.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase();\n\tif (contentType !== \"application/json\") {\n\t\tawait discardResponse(response);\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tconst declaredLength = response.headers.get(\"content-length\");\n\tif (declaredLength !== null) {\n\t\tconst length = Number(declaredLength);\n\t\tif (!Number.isSafeInteger(length) || length < 0 || length > MAX_RESPONSE_BODY_BYTES) {\n\t\t\tawait discardResponse(response);\n\t\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t\t}\n\t}\n\tlet body: string;\n\ttry {\n\t\tbody = await response.text();\n\t} catch {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tif (\n\t\tbody.length === 0 ||\n\t\tbody.length > MAX_RESPONSE_BODY_BYTES ||\n\t\tnew TextEncoder().encode(body).byteLength > MAX_RESPONSE_BODY_BYTES\n\t) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\ttry {\n\t\treturn JSON.parse(body) as unknown;\n\t} catch {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n}\n\nasync function discardResponse(response: Response): Promise<void> {\n\ttry {\n\t\tawait response.body?.cancel();\n\t} catch {\n\t\t// A known HTTP response remains rejected even if draining its untrusted body fails.\n\t}\n}\n\nfunction normalizeRedirectUris(values: readonly string[]): readonly string[] {\n\tif (!Array.isArray(values) || values.length === 0 || values.length > MAX_REDIRECT_URI_COUNT) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\tconst normalized = [...new Set(values.map(normalizeRedirectUri))];\n\tif (normalized.length !== values.length) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\treturn Object.freeze(normalized);\n}\n\nfunction normalizeApplicationType(value: unknown): \"native\" | \"web\" {\n\tif (value !== \"native\" && value !== \"web\") {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\treturn value;\n}\n\nfunction normalizeRedirectUri(value: string): string {\n\tconst url = requireUrl(value);\n\tif (\n\t\turl.username.length > 0 ||\n\t\turl.password.length > 0 ||\n\t\turl.hash.length > 0 ||\n\t\t(url.protocol !== \"https:\" && !isLoopbackHttpRedirect(url.href))\n\t) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\treturn url.href;\n}\n\nfunction isLoopbackHttpRedirect(value: string): boolean {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(value);\n\t} catch {\n\t\treturn false;\n\t}\n\tif (url.protocol !== \"http:\") return false;\n\tconst host = url.hostname.toLowerCase();\n\tif (host === \"localhost\" || host === \"[::1]\") return true;\n\tconst octets = host.split(\".\");\n\treturn octets.length === 4 && octets[0] === \"127\" && octets.every(isDecimalOctet);\n}\n\nfunction isDecimalOctet(value: string): boolean {\n\tif (!/^\\d{1,3}$/u.test(value)) return false;\n\tconst parsed = Number(value);\n\treturn parsed >= 0 && parsed <= 255 && String(parsed) === value;\n}\n\nfunction normalizeOptionalHttpsUrl(value: string | undefined): string | undefined {\n\treturn value === undefined ? undefined : requireHttpsUrl(value, true).href;\n}\n\nfunction normalizeOptionalText(value: string | undefined): string | undefined {\n\treturn value === undefined ? undefined : requireBoundedText(value, MAX_METADATA_VALUE_LENGTH);\n}\n\nfunction normalizeOptionalTextList(\n\tvalues: readonly string[] | undefined,\n\tmaximumCount: number,\n): readonly string[] | undefined {\n\tif (values === undefined) return undefined;\n\tif (!Array.isArray(values) || values.length === 0 || values.length > maximumCount) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\tconst normalized = values.map((value) => requireBoundedText(value, MAX_METADATA_VALUE_LENGTH));\n\treturn Object.freeze(normalized);\n}\n\nfunction normalizeOptionalScopes(\n\tvalues: readonly string[] | undefined,\n): readonly string[] | undefined {\n\tif (values === undefined) return undefined;\n\tif (!Array.isArray(values) || values.length > MAX_SCOPE_COUNT) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\tif (values.length === 0) return undefined;\n\tconst normalized = [...new Set(values)];\n\tfor (const value of normalized) requireScopeToken(value);\n\tconst scope = normalized.join(\" \");\n\tif (scope.length > MAX_SCOPE_STRING_LENGTH) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\treturn Object.freeze(normalized);\n}\n\nfunction normalizeRemoteOptionalScope(value: unknown): readonly string[] | undefined {\n\tif (value === undefined) return undefined;\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > MAX_SCOPE_STRING_LENGTH) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tconst scopes = value.split(\" \");\n\tif (scopes.length > MAX_SCOPE_COUNT) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tfor (const scope of scopes) requireRemoteScopeToken(scope);\n\treturn Object.freeze([...new Set(scopes)]);\n}\n\nfunction normalizeRemoteStringList(value: unknown, maximumCount: number): readonly string[] {\n\tif (!Array.isArray(value) || value.length === 0 || value.length > maximumCount) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\tconst result: string[] = [];\n\tfor (const item of value) {\n\t\tresult.push(requireRemoteBoundedText(item, MAX_URL_LENGTH));\n\t}\n\treturn Object.freeze(result);\n}\n\nfunction normalizeRemoteOptionalStringList(\n\tvalue: unknown,\n\tmaximumCount: number,\n): readonly string[] | undefined {\n\treturn value === undefined ? undefined : normalizeRemoteStringList(value, maximumCount);\n}\n\nfunction normalizeRemoteOptionalSecret(value: unknown): string | undefined {\n\tif (value === undefined) return undefined;\n\treturn requireRemoteBoundedText(value, MAX_CLIENT_SECRET_LENGTH);\n}\n\nfunction normalizeRemoteOptionalTimestamp(value: unknown): number | undefined {\n\tif (value === undefined) return undefined;\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\treturn value;\n}\n\nfunction requireIssuer(value: string): string {\n\trequireHttpsUrl(value, false);\n\treturn value;\n}\n\nfunction requireHttpsUrl(value: string, query: boolean): URL {\n\tconst url = requireUrl(value);\n\tif (\n\t\turl.protocol !== \"https:\" ||\n\t\turl.username.length > 0 ||\n\t\turl.password.length > 0 ||\n\t\turl.hash.length > 0 ||\n\t\t(!query && url.search.length > 0)\n\t) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\treturn url;\n}\n\nfunction requireUrl(value: string): URL {\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > MAX_URL_LENGTH) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\ttry {\n\t\treturn new URL(value);\n\t} catch {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n}\n\nfunction requireBoundedText(value: string, maximumLength: number): string {\n\tif (\n\t\ttypeof value !== \"string\" ||\n\t\tvalue.length === 0 ||\n\t\tvalue.length > maximumLength ||\n\t\tcontainsControlCharacter(value)\n\t) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n\treturn value;\n}\n\nfunction requireRemoteBoundedText(value: unknown, maximumLength: number): string {\n\tif (\n\t\ttypeof value !== \"string\" ||\n\t\tvalue.length === 0 ||\n\t\tvalue.length > maximumLength ||\n\t\tcontainsControlCharacter(value)\n\t) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n\treturn value;\n}\n\nfunction requireScopeToken(value: string): void {\n\tif (!isMcpClientOAuthScopeToken(value)) {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions);\n\t}\n}\n\nfunction requireRemoteScopeToken(value: string): void {\n\ttry {\n\t\trequireScopeToken(value);\n\t} catch {\n\t\tthrow registrationError(McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid);\n\t}\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction sameStrings(left: readonly string[], right: readonly string[]): boolean {\n\treturn left.length === right.length && left.every((value, index) => value === right[index]);\n}\n\nfunction isExactResponseUrl(value: string, expected: string): boolean {\n\ttry {\n\t\treturn new URL(value).href === expected;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction awaitWithSignal<Value>(\n\tpromise: PromiseLike<Value>,\n\tsignal: AbortSignal | undefined,\n): Promise<Value> {\n\tif (signal === undefined) return Promise.resolve(promise);\n\tsignal.throwIfAborted();\n\treturn new Promise<Value>((resolve, reject) => {\n\t\tconst onAbort = (): void => reject(signal.reason);\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tPromise.resolve(promise).then(\n\t\t\t(value) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\treject(error);\n\t\t\t},\n\t\t);\n\t});\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n\tsignal?.throwIfAborted();\n}\n\nfunction containsControlCharacter(value: string): boolean {\n\tfor (const character of value) {\n\t\tconst point = character.codePointAt(0);\n\t\tif (point !== undefined && (point <= 0x1f || (point >= 0x7f && point <= 0x9f))) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction registrationError(\n\tcode: McpClientOAuthDynamicRegistrationErrorCode,\n\trequestDispatched = false,\n): McpClientOAuthDynamicRegistrationError {\n\treturn new McpClientOAuthDynamicRegistrationError(code, requestDispatched);\n}\n\nfunction dynamicRegistrationErrorMessage(code: McpClientOAuthDynamicRegistrationErrorCode): string {\n\tswitch (code) {\n\t\tcase McpClientOAuthDynamicRegistrationErrorCode.InvalidOptions:\n\t\t\treturn \"The dynamic registration options are invalid.\";\n\t\tcase McpClientOAuthDynamicRegistrationErrorCode.Unsupported:\n\t\t\treturn \"The selected OAuth authority does not advertise dynamic registration.\";\n\t\tcase McpClientOAuthDynamicRegistrationErrorCode.EndpointRejected:\n\t\t\treturn \"The dynamic registration endpoint was rejected.\";\n\t\tcase McpClientOAuthDynamicRegistrationErrorCode.RegistrationRejected:\n\t\t\treturn \"The authorization server rejected dynamic registration.\";\n\t\tcase McpClientOAuthDynamicRegistrationErrorCode.ResponseInvalid:\n\t\t\treturn \"The dynamic registration response is invalid.\";\n\t\tcase McpClientOAuthDynamicRegistrationErrorCode.OutcomeUnknown:\n\t\t\treturn \"The dynamic registration outcome is unknown and must not be retried.\";\n\t\tdefault:\n\t\t\treturn \"Dynamic registration failed.\";\n\t}\n}\n"],"mappings":";;AAMA,MAAM,iBAAiB;AACvB,MAAM,yBAAyB;AAC/B,MAAM,uBAAuB;AAC7B,MAAM,2BAA2B;AACjC,MAAM,yBAAyB;AAC/B,MAAM,oBAAoB;AAC1B,MAAM,4BAA4B;AAClC,MAAM,kBAAkB;AACxB,MAAM,0BAA0B;AAChC,MAAM,0BAA0B;;AAGhC,MAAa,6CAA6C;CACzD,gBAAgB;CAChB,aAAa;CACb,kBAAkB;CAClB,sBAAsB;CACtB,iBAAiB;CACjB,gBAAgB;AACjB;;AAMA,IAAa,y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