@lovable.dev/mcp-js 3.4.0 → 3.6.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/README.md +25 -6
- package/dist/{authorize--W1XtwdB.d.cts → authorize-Bea6qCAA.d.cts} +1 -1
- package/dist/{authorize-DpNYioXM.d.ts → authorize-Q0m8G9Hp.d.ts} +1 -1
- package/dist/{base-qEX8YVcD.d.cts → base-B3gSCNnJ.d.cts} +2 -2
- package/dist/{base-Ce9JYirF.d.ts → base-BjvWv8Jx.d.ts} +2 -2
- package/dist/cli/extract-manifest.cjs +1 -1
- package/dist/cli/extract-manifest.js +1 -1
- package/dist/{cors-M68siADv.js → cors-BaElJs06.js} +24 -44
- package/dist/{cors-DcWb13LI.cjs → cors-Brxo6miH.cjs} +92 -112
- package/dist/{errors-CfaxXr2T.js → errors-DzKZv9OC.js} +11 -2
- package/dist/{errors-xJ_7Su1K.cjs → errors-PS8N0oRK.cjs} +14 -5
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +2 -2
- package/dist/{io-CICYQJSM.js → io-B5n6fVX1.js} +2 -1
- package/dist/{io-Di5ljvZY.d.cts → io-BlRXZ_R_.d.cts} +1 -1
- package/dist/{io-BEpyfk4G.d.ts → io-BteA1cwT.d.ts} +1 -1
- package/dist/{io-DGeqWc6m.cjs → io-DZxlvNBF.cjs} +2 -1
- package/dist/{mcp-DAUFwQ80.cjs → mcp-BanAUaeS.cjs} +7 -7
- package/dist/{mcp-BT9dcts8.js → mcp-D7K2Z_S0.js} +3 -3
- package/dist/{package-Cu_ynl05.cjs → package-BUaaSbJm.cjs} +1 -1
- package/dist/{package-N4he-Z_i.js → package-DEUoZczA.js} +1 -1
- package/dist/protocols/mcp/index.cjs +1 -1
- package/dist/protocols/mcp/index.d.cts +3 -3
- package/dist/protocols/mcp/index.d.ts +3 -3
- package/dist/protocols/mcp/index.js +1 -1
- package/dist/protocols/oauth-metadata.cjs +8 -6
- package/dist/protocols/oauth-metadata.d.cts +3 -3
- package/dist/protocols/oauth-metadata.d.ts +3 -3
- package/dist/protocols/oauth-metadata.js +4 -2
- package/dist/stacks/supabase/index.cjs +5 -4
- package/dist/stacks/supabase/index.d.cts +1 -1
- package/dist/stacks/supabase/index.d.ts +1 -1
- package/dist/stacks/supabase/index.js +4 -3
- package/dist/stacks/supabase/vite.cjs +1 -1
- package/dist/stacks/supabase/vite.d.cts +1 -1
- package/dist/stacks/supabase/vite.d.ts +1 -1
- package/dist/stacks/supabase/vite.js +1 -1
- package/dist/stacks/tanstack/index.cjs +11 -6
- package/dist/stacks/tanstack/index.d.cts +2 -2
- package/dist/stacks/tanstack/index.d.ts +2 -2
- package/dist/stacks/tanstack/index.js +10 -5
- package/dist/stacks/tanstack/vite.d.cts +1 -1
- package/dist/stacks/tanstack/vite.d.ts +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/{types-B_dVw-zM.d.ts → types-NORvAwbQ.d.cts} +6 -0
- package/dist/{types-B_dVw-zM.d.cts → types-NORvAwbQ.d.ts} +6 -0
- package/dist/{logger-C-Hdu57K.cjs → validation-D6hthH5Q.cjs} +162 -72
- package/dist/{logger-CpLgYbCG.js → validation-xzkdIA-x.js} +133 -73
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_package = require("./package-
|
|
1
|
+
const require_validation = require("./validation-D6hthH5Q.cjs");
|
|
2
|
+
const require_package = require("./package-BUaaSbJm.cjs");
|
|
3
3
|
require("./metadata-path-zd7NSNoa.cjs");
|
|
4
4
|
let jose = require("jose");
|
|
5
5
|
//#region src/core/http.ts
|
|
@@ -116,15 +116,6 @@ const NOOP_RECORDER = { async emit() {} };
|
|
|
116
116
|
function createNoopRecorder() {
|
|
117
117
|
return NOOP_RECORDER;
|
|
118
118
|
}
|
|
119
|
-
/** Guarded `process.env` read — the shared fallback both stacks use for local
|
|
120
|
-
* dev. Tolerates a missing `process` global. */
|
|
121
|
-
function readProcessEnv(name) {
|
|
122
|
-
try {
|
|
123
|
-
return typeof process !== "undefined" ? process.env?.[name] || void 0 : void 0;
|
|
124
|
-
} catch {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
119
|
/** Shared recorder implementation. Callers await `emit` or register it with the runtime's request lifetime. */
|
|
129
120
|
var BaseMetricRecorder = class {
|
|
130
121
|
config;
|
|
@@ -150,7 +141,7 @@ var BaseMetricRecorder = class {
|
|
|
150
141
|
}
|
|
151
142
|
async emit(ev) {
|
|
152
143
|
await this.applyLazyLogLevel();
|
|
153
|
-
if (ev.outcome !== "auth_challenge" && ev.outcome !== "origin_rejected")
|
|
144
|
+
if (ev.outcome !== "auth_challenge" && ev.outcome !== "origin_rejected") require_validation.log.info(ev.method === "authorize" ? "gate.rejected" : "tool.invoked", {
|
|
154
145
|
tool: ev.tool,
|
|
155
146
|
method: ev.method,
|
|
156
147
|
outcome: ev.outcome,
|
|
@@ -161,7 +152,7 @@ var BaseMetricRecorder = class {
|
|
|
161
152
|
});
|
|
162
153
|
if (!this.config.enabled) return;
|
|
163
154
|
if (!this.doFetch) {
|
|
164
|
-
|
|
155
|
+
require_validation.log.warn("metrics.disabled_no_fetch", { endpoint: this.config.endpoint });
|
|
165
156
|
return;
|
|
166
157
|
}
|
|
167
158
|
try {
|
|
@@ -171,7 +162,7 @@ var BaseMetricRecorder = class {
|
|
|
171
162
|
if (!key) {
|
|
172
163
|
if (!warnedNoApiKey) {
|
|
173
164
|
warnedNoApiKey = true;
|
|
174
|
-
|
|
165
|
+
require_validation.log.warn("metrics.disabled_no_api_key", {
|
|
175
166
|
envVar: this.config.apiKeyEnvVar,
|
|
176
167
|
endpoint: this.config.endpoint
|
|
177
168
|
});
|
|
@@ -193,13 +184,13 @@ var BaseMetricRecorder = class {
|
|
|
193
184
|
keepalive: true,
|
|
194
185
|
signal: AbortSignal.timeout(METRICS_POST_TIMEOUT_MS)
|
|
195
186
|
});
|
|
196
|
-
if (!res.ok)
|
|
187
|
+
if (!res.ok) require_validation.log.warn("metrics.rejected", {
|
|
197
188
|
status: res.status,
|
|
198
189
|
endpoint: this.config.endpoint
|
|
199
190
|
});
|
|
200
191
|
} catch (err) {
|
|
201
|
-
|
|
202
|
-
...
|
|
192
|
+
require_validation.log.warn("metrics.failed", {
|
|
193
|
+
...require_validation.describeError(err),
|
|
203
194
|
endpoint: this.config.endpoint
|
|
204
195
|
});
|
|
205
196
|
}
|
|
@@ -212,43 +203,17 @@ var BaseMetricRecorder = class {
|
|
|
212
203
|
async applyLazyLogLevel() {
|
|
213
204
|
if (this.lazyLogLevelApplied) return;
|
|
214
205
|
this.lazyLogLevelApplied = true;
|
|
215
|
-
|
|
206
|
+
require_validation.applyLogLevelFromEnv(await this.readEnv(require_validation.LOG_LEVEL_ENV_VAR));
|
|
216
207
|
}
|
|
217
208
|
};
|
|
218
209
|
//#endregion
|
|
219
210
|
//#region src/metrics/impl/cloudflare.ts
|
|
220
|
-
let cloudflareEnvPromise;
|
|
221
|
-
async function readCloudflareEnv(name) {
|
|
222
|
-
try {
|
|
223
|
-
cloudflareEnvPromise ??= import(
|
|
224
|
-
/* @vite-ignore */
|
|
225
|
-
"cloudflare:workers"
|
|
226
|
-
).then((m) => m.env).catch((err) => {
|
|
227
|
-
require_logger.log.debug("metrics.cloudflare_env_import_failed", require_logger.describeError(err));
|
|
228
|
-
});
|
|
229
|
-
const env = await cloudflareEnvPromise;
|
|
230
|
-
const raw = env?.[name];
|
|
231
|
-
const value = typeof raw === "string" && raw ? raw : void 0;
|
|
232
|
-
require_logger.log.debug("metrics.read_cloudflare_env", {
|
|
233
|
-
name,
|
|
234
|
-
hasEnvBinding: !!env,
|
|
235
|
-
found: value !== void 0
|
|
236
|
-
});
|
|
237
|
-
return value;
|
|
238
|
-
} catch (err) {
|
|
239
|
-
require_logger.log.debug("metrics.read_cloudflare_env_error", {
|
|
240
|
-
name,
|
|
241
|
-
...require_logger.describeError(err)
|
|
242
|
-
});
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
211
|
/** TanStack apps deploy to Cloudflare Workers: secrets live on the `env` binding
|
|
247
212
|
* (read via `cloudflare:workers`), with `process.env` as the local-dev fallback. */
|
|
248
213
|
var TanStackMetricRecorder = class extends BaseMetricRecorder {
|
|
249
214
|
stack = "tanstack";
|
|
250
215
|
async readEnv(name) {
|
|
251
|
-
return readProcessEnv(name) ?? await readCloudflareEnv(name);
|
|
216
|
+
return require_validation.readProcessEnv(name) ?? await require_validation.readCloudflareEnv(name);
|
|
252
217
|
}
|
|
253
218
|
};
|
|
254
219
|
//#endregion
|
|
@@ -257,16 +222,16 @@ function readDenoEnv(name) {
|
|
|
257
222
|
try {
|
|
258
223
|
const denoEnv = globalThis.Deno?.env;
|
|
259
224
|
const value = denoEnv?.get?.(name) || void 0;
|
|
260
|
-
|
|
225
|
+
require_validation.log.debug("metrics.read_deno_env", {
|
|
261
226
|
name,
|
|
262
227
|
hasDenoEnv: !!denoEnv,
|
|
263
228
|
found: !!value
|
|
264
229
|
});
|
|
265
230
|
return value;
|
|
266
231
|
} catch (err) {
|
|
267
|
-
|
|
232
|
+
require_validation.log.debug("metrics.read_deno_env_error", {
|
|
268
233
|
name,
|
|
269
|
-
...
|
|
234
|
+
...require_validation.describeError(err)
|
|
270
235
|
});
|
|
271
236
|
return;
|
|
272
237
|
}
|
|
@@ -276,7 +241,7 @@ function readDenoEnv(name) {
|
|
|
276
241
|
var SupabaseMetricRecorder = class extends BaseMetricRecorder {
|
|
277
242
|
stack = "supabase";
|
|
278
243
|
async readEnv(name) {
|
|
279
|
-
return readDenoEnv(name) ?? readProcessEnv(name);
|
|
244
|
+
return readDenoEnv(name) ?? require_validation.readProcessEnv(name);
|
|
280
245
|
}
|
|
281
246
|
};
|
|
282
247
|
//#endregion
|
|
@@ -287,7 +252,7 @@ async function emitBeforeResponse(recorder, event, scheduleBackground) {
|
|
|
287
252
|
scheduleBackground(task);
|
|
288
253
|
return;
|
|
289
254
|
} catch (err) {
|
|
290
|
-
|
|
255
|
+
require_validation.log.warn("metrics.background_schedule_failed", require_validation.describeError(err));
|
|
291
256
|
}
|
|
292
257
|
await task;
|
|
293
258
|
}
|
|
@@ -295,7 +260,7 @@ async function emitBeforeResponse(recorder, event, scheduleBackground) {
|
|
|
295
260
|
* metrics are disabled (`metrics: false`); otherwise the stack-specific class, which
|
|
296
261
|
* logs `tool.invoked` for tool invocations even if the key or endpoint is unavailable. */
|
|
297
262
|
function createRecorderForRuntime(mcp, opts) {
|
|
298
|
-
const config =
|
|
263
|
+
const config = require_validation.resolveMetricsConfig(mcp.metrics);
|
|
299
264
|
const server = {
|
|
300
265
|
name: mcp.name,
|
|
301
266
|
version: mcp.version
|
|
@@ -319,18 +284,18 @@ function cachedPromise(load, label) {
|
|
|
319
284
|
let value;
|
|
320
285
|
return async () => {
|
|
321
286
|
if (settled) {
|
|
322
|
-
if (label)
|
|
287
|
+
if (label) require_validation.log.debug(`${label}.cache_hit`);
|
|
323
288
|
return value;
|
|
324
289
|
}
|
|
325
|
-
if (label)
|
|
290
|
+
if (label) require_validation.log.debug(`${label}.load_start`);
|
|
326
291
|
try {
|
|
327
292
|
const loaded = await load();
|
|
328
293
|
settled = true;
|
|
329
294
|
value = loaded;
|
|
330
|
-
if (label)
|
|
295
|
+
if (label) require_validation.log.debug(`${label}.settled`);
|
|
331
296
|
return loaded;
|
|
332
297
|
} catch (err) {
|
|
333
|
-
if (label)
|
|
298
|
+
if (label) require_validation.log.debug(`${label}.load_failed`, require_validation.describeError(err));
|
|
334
299
|
throw err;
|
|
335
300
|
}
|
|
336
301
|
};
|
|
@@ -361,7 +326,7 @@ var MetadataUnreachableError = class extends Error {
|
|
|
361
326
|
};
|
|
362
327
|
const METADATA_FETCH_TIMEOUT_MS = 5e3;
|
|
363
328
|
function issuerPath(url) {
|
|
364
|
-
const path =
|
|
329
|
+
const path = require_validation.trimTrailingSlash(url.pathname);
|
|
365
330
|
return path === "" ? void 0 : path;
|
|
366
331
|
}
|
|
367
332
|
function pathInsertedOAuthMetadataUrls(url, path) {
|
|
@@ -374,7 +339,7 @@ function pathInsertedOAuthMetadataUrls(url, path) {
|
|
|
374
339
|
* so order affects latency only, never which server verifies tokens.
|
|
375
340
|
*/
|
|
376
341
|
function oauthMetadataUrlsForIssuer(issuer) {
|
|
377
|
-
const normalizedIssuer =
|
|
342
|
+
const normalizedIssuer = require_validation.trimTrailingSlash(issuer);
|
|
378
343
|
const url = new URL(normalizedIssuer);
|
|
379
344
|
const path = issuerPath(url);
|
|
380
345
|
if (!path) return [`${normalizedIssuer}/.well-known/oauth-authorization-server`, `${normalizedIssuer}/.well-known/openid-configuration`];
|
|
@@ -386,15 +351,15 @@ async function fetchFirstValidOAuthServerMetadata(metadataUrls, expectedIssuer)
|
|
|
386
351
|
return await fetchOAuthServerMetadata(url, expectedIssuer);
|
|
387
352
|
} catch (err) {
|
|
388
353
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
389
|
-
|
|
354
|
+
require_validation.log.debug("oauth.discovery.attempt_failed", {
|
|
390
355
|
url,
|
|
391
|
-
...
|
|
356
|
+
...require_validation.describeError(error)
|
|
392
357
|
});
|
|
393
358
|
errors.push(error);
|
|
394
359
|
}
|
|
395
360
|
const unreachable = errors.some((e) => e instanceof MetadataUnreachableError);
|
|
396
361
|
const detail = errors.map((e) => e.message).join("; ");
|
|
397
|
-
|
|
362
|
+
require_validation.log.error("oauth.discovery.exhausted", {
|
|
398
363
|
expectedIssuer,
|
|
399
364
|
urlsTried: metadataUrls,
|
|
400
365
|
errors: detail,
|
|
@@ -404,7 +369,7 @@ async function fetchFirstValidOAuthServerMetadata(metadataUrls, expectedIssuer)
|
|
|
404
369
|
throw unreachable ? new MetadataUnreachableError(message) : new Error(message);
|
|
405
370
|
}
|
|
406
371
|
async function fetchOAuthServerMetadata(url, expectedIssuer) {
|
|
407
|
-
|
|
372
|
+
require_validation.log.debug("oauth.discovery.fetch", { url });
|
|
408
373
|
let response;
|
|
409
374
|
try {
|
|
410
375
|
response = await fetch(url, {
|
|
@@ -420,9 +385,9 @@ async function fetchOAuthServerMetadata(url, expectedIssuer) {
|
|
|
420
385
|
}
|
|
421
386
|
const json = await response.json();
|
|
422
387
|
if (typeof json.issuer !== "string") throw new Error("missing issuer");
|
|
423
|
-
|
|
424
|
-
if (
|
|
425
|
-
|
|
388
|
+
require_validation.parseSafeUrl("discovered issuer", json.issuer);
|
|
389
|
+
if (require_validation.trimTrailingSlash(json.issuer) !== expectedIssuer) {
|
|
390
|
+
require_validation.log.warn("oauth.discovery.issuer_mismatch", {
|
|
426
391
|
url,
|
|
427
392
|
expectedIssuer,
|
|
428
393
|
published: json.issuer
|
|
@@ -430,7 +395,7 @@ async function fetchOAuthServerMetadata(url, expectedIssuer) {
|
|
|
430
395
|
throw new Error("issuer mismatch");
|
|
431
396
|
}
|
|
432
397
|
if (typeof json.jwks_uri !== "string") throw new Error("missing jwks_uri");
|
|
433
|
-
|
|
398
|
+
require_validation.parseSafeUrl("discovered jwks_uri", json.jwks_uri);
|
|
434
399
|
return {
|
|
435
400
|
issuer: json.issuer,
|
|
436
401
|
jwks_uri: json.jwks_uri
|
|
@@ -442,16 +407,16 @@ async function fetchIssuerOAuthServerMetadata(issuer) {
|
|
|
442
407
|
} catch (err) {
|
|
443
408
|
const message = `OAuth issuer discovery failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
444
409
|
if (err instanceof MetadataUnreachableError) {
|
|
445
|
-
|
|
410
|
+
require_validation.log.error("oauth.discovery.unreachable", {
|
|
446
411
|
issuer,
|
|
447
|
-
...
|
|
412
|
+
...require_validation.describeError(err),
|
|
448
413
|
outcome: "503 authorization server unreachable"
|
|
449
414
|
});
|
|
450
415
|
throw new OAuthUpstreamUnreachableError(message, "discovery");
|
|
451
416
|
}
|
|
452
|
-
|
|
417
|
+
require_validation.log.error("oauth.discovery.config_error", {
|
|
453
418
|
issuer,
|
|
454
|
-
...
|
|
419
|
+
...require_validation.describeError(err),
|
|
455
420
|
outcome: "500 oauth configuration error"
|
|
456
421
|
});
|
|
457
422
|
throw new OAuthConfigurationError(message, "discovery");
|
|
@@ -459,20 +424,20 @@ async function fetchIssuerOAuthServerMetadata(issuer) {
|
|
|
459
424
|
}
|
|
460
425
|
/** Metadata and token verification share issuer/JWKS discovery, but transient failures must not poison the runtime. */
|
|
461
426
|
function createOAuthDiscoveryResolver(auth) {
|
|
462
|
-
const configuredIssuer =
|
|
427
|
+
const configuredIssuer = require_validation.trimTrailingSlash(auth.issuer);
|
|
463
428
|
const oauthServerMetadata = cachedPromise(() => fetchIssuerOAuthServerMetadata(configuredIssuer), "oauth.discovery.metadata");
|
|
464
429
|
return {
|
|
465
430
|
resolveIssuer: async () => configuredIssuer,
|
|
466
431
|
resolveJwksUri: async () => {
|
|
467
432
|
if (auth.jwksUri) {
|
|
468
|
-
|
|
433
|
+
require_validation.log.debug("oauth.jwks.resolved", {
|
|
469
434
|
jwksUri: auth.jwksUri,
|
|
470
435
|
source: "configured"
|
|
471
436
|
});
|
|
472
437
|
return auth.jwksUri;
|
|
473
438
|
}
|
|
474
439
|
const jwksUri = (await oauthServerMetadata()).jwks_uri;
|
|
475
|
-
|
|
440
|
+
require_validation.log.debug("oauth.jwks.resolved", {
|
|
476
441
|
jwksUri,
|
|
477
442
|
source: "discovered"
|
|
478
443
|
});
|
|
@@ -484,18 +449,20 @@ function createOAuthDiscoveryResolver(auth) {
|
|
|
484
449
|
//#region src/auth/resource.ts
|
|
485
450
|
/**
|
|
486
451
|
* Defaults the protected-resource name from the request `Host` so hosted apps stay portable
|
|
487
|
-
* across domains.
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
* the
|
|
452
|
+
* across domains.
|
|
453
|
+
*
|
|
454
|
+
* With `acceptedAudiences` set, this default only names the advertised metadata. Under
|
|
455
|
+
* `resourceMode: "lovable-managed"` it is also the accepted audience, which is why that mode
|
|
456
|
+
* requires a platform-delivered origin ([hasLovableManagedOrigin]). Deployments behind an
|
|
457
|
+
* untrusted proxy should pin `auth.resource` so a spoofed `Host` can't shift either.
|
|
491
458
|
*/
|
|
492
459
|
function resolveProtectedResource(auth, request, options) {
|
|
493
|
-
if (auth.resource) return
|
|
460
|
+
if (auth.resource) return require_validation.trimTrailingSlash(auth.resource);
|
|
494
461
|
const path = resolveResourcePath(options.resourcePath, request);
|
|
495
462
|
const resourceURL = new URL(path, request.url);
|
|
496
463
|
resourceURL.search = "";
|
|
497
464
|
resourceURL.hash = "";
|
|
498
|
-
return
|
|
465
|
+
return require_validation.trimTrailingSlash(resourceURL.toString());
|
|
499
466
|
}
|
|
500
467
|
/**
|
|
501
468
|
* A bare absolute path can't anchor `resource` to another origin; `//host`, `\\host`,
|
|
@@ -575,8 +542,8 @@ async function fetchVerificationKeySet(jwksUri) {
|
|
|
575
542
|
redirect: "manual"
|
|
576
543
|
});
|
|
577
544
|
} catch (err) {
|
|
578
|
-
|
|
579
|
-
...
|
|
545
|
+
require_validation.log.error("oauth.jwks.unreachable", {
|
|
546
|
+
...require_validation.describeError(err),
|
|
580
547
|
outcome: "503 authorization server unreachable"
|
|
581
548
|
});
|
|
582
549
|
throw new OAuthUpstreamUnreachableError(`JWKS fetch failed: ${err instanceof Error ? err.message : String(err)}`, "jwks");
|
|
@@ -585,8 +552,8 @@ async function fetchVerificationKeySet(jwksUri) {
|
|
|
585
552
|
if (!response.ok) throw new Error(`JWKS endpoint returned ${response.status}`);
|
|
586
553
|
return (0, jose.createLocalJWKSet)(await response.json());
|
|
587
554
|
} catch (err) {
|
|
588
|
-
|
|
589
|
-
...
|
|
555
|
+
require_validation.log.error("oauth.jwks.fetch_failed", {
|
|
556
|
+
...require_validation.describeError(err),
|
|
590
557
|
outcome: "500 oauth configuration error"
|
|
591
558
|
});
|
|
592
559
|
throw new OAuthConfigurationError(`JWKS fetch failed: ${err instanceof Error ? err.message : String(err)}`, "jwks");
|
|
@@ -595,7 +562,7 @@ async function fetchVerificationKeySet(jwksUri) {
|
|
|
595
562
|
function assertCompactJwsShape(token) {
|
|
596
563
|
const parts = token.split(".");
|
|
597
564
|
if (parts.length !== 3 || parts.some((part) => part.length === 0)) {
|
|
598
|
-
|
|
565
|
+
require_validation.log.debug("oauth.verify.bad_shape", {
|
|
599
566
|
tokenLength: token.length,
|
|
600
567
|
outcome: "401 invalid_token"
|
|
601
568
|
});
|
|
@@ -607,15 +574,15 @@ function assertAccessTokenTyp(token, allowed) {
|
|
|
607
574
|
try {
|
|
608
575
|
header = (0, jose.decodeProtectedHeader)(token);
|
|
609
576
|
} catch (err) {
|
|
610
|
-
|
|
611
|
-
...
|
|
577
|
+
require_validation.log.debug("oauth.verify.bad_header", {
|
|
578
|
+
...require_validation.describeError(err),
|
|
612
579
|
outcome: "401 invalid_token"
|
|
613
580
|
});
|
|
614
581
|
throw new OAuthTokenError(401, "invalid_token", "Malformed JWT header");
|
|
615
582
|
}
|
|
616
583
|
const typ = header.typ;
|
|
617
584
|
if (typeof typ !== "string" || !allowed.includes(typ)) {
|
|
618
|
-
|
|
585
|
+
require_validation.log.debug("oauth.verify.bad_typ", {
|
|
619
586
|
jwtTyp: typ,
|
|
620
587
|
allowed,
|
|
621
588
|
outcome: "401 invalid_token"
|
|
@@ -633,8 +600,8 @@ async function verifyJwtClaims(token, keySet, issuer, auth) {
|
|
|
633
600
|
});
|
|
634
601
|
return payload;
|
|
635
602
|
} catch (err) {
|
|
636
|
-
|
|
637
|
-
...
|
|
603
|
+
require_validation.log.debug("oauth.verify.rejected", {
|
|
604
|
+
...require_validation.describeError(err),
|
|
638
605
|
outcome: "401 invalid_token"
|
|
639
606
|
});
|
|
640
607
|
throw err;
|
|
@@ -643,20 +610,20 @@ async function verifyJwtClaims(token, keySet, issuer, auth) {
|
|
|
643
610
|
function checkAcceptedAudience(claims, accepted, auth) {
|
|
644
611
|
if (claims.aud !== void 0 && !(Array.isArray(claims.aud) && claims.aud.length === 0)) {
|
|
645
612
|
if (stringClaimList(claims.aud).some((audience) => accepted.includes(audience))) return "aud";
|
|
646
|
-
|
|
613
|
+
require_validation.log.debug("oauth.verify.bad_audience", {
|
|
647
614
|
tokenAud: claims.aud,
|
|
648
615
|
accepted,
|
|
649
616
|
outcome: "401 invalid_token"
|
|
650
617
|
});
|
|
651
618
|
} else if (auth.acceptResourceClaim !== false) {
|
|
652
|
-
const acceptedTrimmed = accepted.map(
|
|
653
|
-
if (stringClaimList(claims.resource).some((resource) => acceptedTrimmed.includes(
|
|
654
|
-
|
|
619
|
+
const acceptedTrimmed = accepted.map(require_validation.trimTrailingSlash);
|
|
620
|
+
if (stringClaimList(claims.resource).some((resource) => acceptedTrimmed.includes(require_validation.trimTrailingSlash(resource)))) return "resource";
|
|
621
|
+
require_validation.log.debug("oauth.verify.bad_resource", {
|
|
655
622
|
tokenResource: claims.resource,
|
|
656
623
|
accepted,
|
|
657
624
|
outcome: "401 invalid_token"
|
|
658
625
|
});
|
|
659
|
-
} else
|
|
626
|
+
} else require_validation.log.debug("oauth.verify.empty_audience", {
|
|
660
627
|
accepted,
|
|
661
628
|
outcome: "401 invalid_token"
|
|
662
629
|
});
|
|
@@ -665,14 +632,14 @@ function checkAcceptedAudience(claims, accepted, auth) {
|
|
|
665
632
|
function assertNonEmptySubject(claims) {
|
|
666
633
|
const sub = claims["sub"];
|
|
667
634
|
if (typeof sub !== "string" || sub.trim() === "") {
|
|
668
|
-
|
|
635
|
+
require_validation.log.debug("oauth.verify.bad_subject", { subType: typeof sub });
|
|
669
636
|
throw new OAuthTokenError(401, "invalid_token", "token subject claim must be a non-empty string");
|
|
670
637
|
}
|
|
671
638
|
}
|
|
672
639
|
/** Rejects copied app-session JWTs that were not issued to an OAuth client. */
|
|
673
640
|
function assertOAuthClientClaim(auth, clientId) {
|
|
674
641
|
if (auth.requireOAuthClientClaim !== false && !clientId) {
|
|
675
|
-
|
|
642
|
+
require_validation.log.debug("oauth.verify.missing_client_claim", { outcome: "401 invalid_token" });
|
|
676
643
|
throw new OAuthTokenError(401, "invalid_token", "OAuth client claim is required");
|
|
677
644
|
}
|
|
678
645
|
}
|
|
@@ -708,14 +675,14 @@ function createOAuthTokenVerifier(auth, discovery) {
|
|
|
708
675
|
const resource = resolveProtectedResource(auth, request, options);
|
|
709
676
|
const issuer = await discovery.resolveIssuer();
|
|
710
677
|
const acceptedAudiences = resolveAcceptedAudiences(auth, resource);
|
|
711
|
-
|
|
678
|
+
require_validation.log.debug("oauth.verify.start", {
|
|
712
679
|
issuer,
|
|
713
680
|
acceptedAudiences,
|
|
714
681
|
resource,
|
|
715
682
|
...tokenHeaderFields(token)
|
|
716
683
|
});
|
|
717
684
|
const jwksUri = await discovery.resolveJwksUri();
|
|
718
|
-
|
|
685
|
+
require_validation.log.debug("oauth.jwks.fetch", { jwksUri });
|
|
719
686
|
const claims = await verifyJwtClaims(token, await fetchVerificationKeySet(jwksUri), issuer, auth);
|
|
720
687
|
const audienceVia = checkAcceptedAudience(claims, acceptedAudiences, auth);
|
|
721
688
|
assertNonEmptySubject(claims);
|
|
@@ -727,11 +694,11 @@ function createOAuthTokenVerifier(auth, discovery) {
|
|
|
727
694
|
acceptedAudiences
|
|
728
695
|
});
|
|
729
696
|
assertOAuthClientClaim(auth, context.principal.clientId);
|
|
730
|
-
|
|
697
|
+
require_validation.log.info("oauth.verify.ok", {
|
|
731
698
|
scopes: context.principal.scopes,
|
|
732
699
|
audienceVia
|
|
733
700
|
});
|
|
734
|
-
|
|
701
|
+
require_validation.log.debug("oauth.verify.principal", {
|
|
735
702
|
sub: context.principal.sub,
|
|
736
703
|
clientId: context.principal.clientId
|
|
737
704
|
});
|
|
@@ -816,14 +783,15 @@ function parseBearerToken(request) {
|
|
|
816
783
|
function getOAuthRuntime(mcp, options = {}) {
|
|
817
784
|
if (options.resourcePath !== void 0) assertResourcePathShape(options.resourcePath);
|
|
818
785
|
if (options.metadataPath !== void 0) assertResourcePathShape(options.metadataPath, "metadataPath");
|
|
786
|
+
const auth = mcp.auth?.type === "oauth" ? mcp.auth : void 0;
|
|
787
|
+
const forwardedTrusted = !require_validation.isLovableManagedResource(auth);
|
|
819
788
|
const stableOptions = {
|
|
820
789
|
resourcePath: options.resourcePath,
|
|
821
790
|
metadataPath: options.metadataPath,
|
|
822
|
-
trustForwardedHost: options.trustForwardedHost,
|
|
823
|
-
trustForwardedProto: options.trustForwardedProto,
|
|
791
|
+
trustForwardedHost: forwardedTrusted ? options.trustForwardedHost : void 0,
|
|
792
|
+
trustForwardedProto: forwardedTrusted ? options.trustForwardedProto : void 0,
|
|
824
793
|
forwardedHostTrustedByPlatform: options.forwardedHostTrustedByPlatform
|
|
825
794
|
};
|
|
826
|
-
const auth = mcp.auth?.type === "oauth" ? mcp.auth : void 0;
|
|
827
795
|
if (!auth) return {
|
|
828
796
|
kind: "unconfigured",
|
|
829
797
|
options: stableOptions
|
|
@@ -858,10 +826,22 @@ function createRequestAuthorizer(mcp, options = {}) {
|
|
|
858
826
|
return { async authorize(request, recorder, scheduleBackground) {
|
|
859
827
|
if (runtime.kind === "unconfigured") return { ok: true };
|
|
860
828
|
const startedAt = nowMs();
|
|
829
|
+
if (require_validation.isLovableManagedResource(runtime.auth) && !await require_validation.hasLovableManagedOrigin(request)) {
|
|
830
|
+
await recorder?.emit({
|
|
831
|
+
tool: null,
|
|
832
|
+
method: "authorize",
|
|
833
|
+
outcome: "auth_resource_origin_unavailable",
|
|
834
|
+
durationMs: nowMs() - startedAt
|
|
835
|
+
});
|
|
836
|
+
return {
|
|
837
|
+
ok: false,
|
|
838
|
+
response: oauthConfigurationErrorResponse()
|
|
839
|
+
};
|
|
840
|
+
}
|
|
861
841
|
const token = parseBearerToken(request);
|
|
862
842
|
if (!token) {
|
|
863
843
|
const httpMethod = normalizeHttpMethod(request.method);
|
|
864
|
-
|
|
844
|
+
require_validation.log.info("auth.no_bearer_token", {
|
|
865
845
|
httpMethod,
|
|
866
846
|
outcome: "401"
|
|
867
847
|
});
|
|
@@ -886,8 +866,8 @@ function createRequestAuthorizer(mcp, options = {}) {
|
|
|
886
866
|
};
|
|
887
867
|
} catch (err) {
|
|
888
868
|
if (err instanceof OAuthUpstreamUnreachableError) {
|
|
889
|
-
|
|
890
|
-
...
|
|
869
|
+
require_validation.log.error("auth.upstream_unreachable", {
|
|
870
|
+
...require_validation.describeError(err),
|
|
891
871
|
stage: err.stage,
|
|
892
872
|
outcome: "503"
|
|
893
873
|
});
|
|
@@ -903,8 +883,8 @@ function createRequestAuthorizer(mcp, options = {}) {
|
|
|
903
883
|
};
|
|
904
884
|
}
|
|
905
885
|
if (err instanceof OAuthConfigurationError) {
|
|
906
|
-
|
|
907
|
-
...
|
|
886
|
+
require_validation.log.error("auth.config_error", {
|
|
887
|
+
...require_validation.describeError(err),
|
|
908
888
|
stage: err.stage,
|
|
909
889
|
outcome: "500"
|
|
910
890
|
});
|
|
@@ -926,7 +906,7 @@ function createRequestAuthorizer(mcp, options = {}) {
|
|
|
926
906
|
durationMs: nowMs() - startedAt
|
|
927
907
|
}, scheduleBackground);
|
|
928
908
|
if (err instanceof OAuthTokenError) {
|
|
929
|
-
|
|
909
|
+
require_validation.log.info("auth.token_rejected", {
|
|
930
910
|
status: err.status,
|
|
931
911
|
oauthError: err.oauthError
|
|
932
912
|
});
|
|
@@ -935,13 +915,13 @@ function createRequestAuthorizer(mcp, options = {}) {
|
|
|
935
915
|
response: challengeResponse(runtime.auth, request, runtime.options, err.status, err.oauthError, err.message)
|
|
936
916
|
};
|
|
937
917
|
}
|
|
938
|
-
if (err instanceof jose.errors.JOSEError)
|
|
939
|
-
...
|
|
918
|
+
if (err instanceof jose.errors.JOSEError) require_validation.log.info("auth.token_rejected", {
|
|
919
|
+
...require_validation.describeError(err),
|
|
940
920
|
status: 401,
|
|
941
921
|
oauthError: "invalid_token"
|
|
942
922
|
});
|
|
943
|
-
else
|
|
944
|
-
...
|
|
923
|
+
else require_validation.log.error("auth.unexpected_error", {
|
|
924
|
+
...require_validation.describeError(err),
|
|
945
925
|
outcome: "401"
|
|
946
926
|
});
|
|
947
927
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as resolveMetricsConfig, n as trimTrailingSlash, o as LOVABLE_MANAGED_RESOURCE, t as parseSafeUrl } from "./validation-xzkdIA-x.js";
|
|
2
2
|
import { n as validateSkills } from "./format-DKEuO8Tn.js";
|
|
3
3
|
import { c as freezeApp, i as assertAppDefinitionInput, l as freezeToolUi, o as assertToolUi, s as collectApps } from "./apps-CWG3rGhB.js";
|
|
4
4
|
import { t as jsonSchemaFromDefinition } from "./schema-JK_1KkOa.js";
|
|
@@ -85,7 +85,16 @@ function assertOAuthConfig(auth) {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
if (auth.clockToleranceSeconds !== void 0) assertClockToleranceSeconds(auth.clockToleranceSeconds);
|
|
88
|
-
if (auth.
|
|
88
|
+
if (auth.resourceMode !== void 0) {
|
|
89
|
+
if (auth.resourceMode !== "lovable-managed") throw new Error(`@lovable.dev/mcp-js: auth.resourceMode must be "lovable-managed"`);
|
|
90
|
+
for (const field of [
|
|
91
|
+
"resource",
|
|
92
|
+
"acceptedAudiences",
|
|
93
|
+
"protectedResourceMetadataUrl"
|
|
94
|
+
]) if (auth[field] !== void 0) throw new Error(`@lovable.dev/mcp-js: auth.resourceMode "${LOVABLE_MANAGED_RESOURCE}" derives the resource from the served address, so auth.${field} must not also be set`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (auth.resource === void 0 && auth.acceptedAudiences === void 0) throw new Error(`@lovable.dev/mcp-js: auth.resource, auth.acceptedAudiences or auth.resourceMode "${LOVABLE_MANAGED_RESOURCE}" is required`);
|
|
89
98
|
}
|
|
90
99
|
function freezeAuth(auth) {
|
|
91
100
|
if (!auth) return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_schema = require("./schema-DNMsvJwE.cjs");
|
|
2
|
-
const
|
|
2
|
+
const require_validation = require("./validation-D6hthH5Q.cjs");
|
|
3
3
|
const require_format = require("./format-DDzvc92Z.cjs");
|
|
4
4
|
const require_apps = require("./apps-DyoDrwfi.cjs");
|
|
5
5
|
//#region src/core/define.ts
|
|
@@ -31,7 +31,7 @@ function assertNonEmptyString(label, value) {
|
|
|
31
31
|
}
|
|
32
32
|
function assertHttpsUrlField(name, value) {
|
|
33
33
|
assertNonEmptyString(`auth.${name}`, value);
|
|
34
|
-
|
|
34
|
+
require_validation.parseSafeUrl(`@lovable.dev/mcp-js: auth.${name}`, value);
|
|
35
35
|
}
|
|
36
36
|
function assertScope(scope) {
|
|
37
37
|
if (scope.trim() === "" || /\s/.test(scope)) throw new Error(`@lovable.dev/mcp-js: OAuth scopes must be non-empty space-free tokens`);
|
|
@@ -62,7 +62,7 @@ function assertOAuthConfig(auth) {
|
|
|
62
62
|
for (const audience of auth.acceptedAudiences) {
|
|
63
63
|
if (typeof audience !== "string") throw new Error(`@lovable.dev/mcp-js: auth.acceptedAudiences must contain strings`);
|
|
64
64
|
assertNonEmptyString("auth.acceptedAudiences", audience);
|
|
65
|
-
if (
|
|
65
|
+
if (require_validation.trimTrailingSlash(audience) === "") throw new Error(`@lovable.dev/mcp-js: auth.acceptedAudiences entries must not be only slashes`);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
if (auth.requireOAuthClientClaim !== void 0 && typeof auth.requireOAuthClientClaim !== "boolean") throw new Error(`@lovable.dev/mcp-js: auth.requireOAuthClientClaim must be a boolean`);
|
|
@@ -85,7 +85,16 @@ function assertOAuthConfig(auth) {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
if (auth.clockToleranceSeconds !== void 0) assertClockToleranceSeconds(auth.clockToleranceSeconds);
|
|
88
|
-
if (auth.
|
|
88
|
+
if (auth.resourceMode !== void 0) {
|
|
89
|
+
if (auth.resourceMode !== "lovable-managed") throw new Error(`@lovable.dev/mcp-js: auth.resourceMode must be "lovable-managed"`);
|
|
90
|
+
for (const field of [
|
|
91
|
+
"resource",
|
|
92
|
+
"acceptedAudiences",
|
|
93
|
+
"protectedResourceMetadataUrl"
|
|
94
|
+
]) if (auth[field] !== void 0) throw new Error(`@lovable.dev/mcp-js: auth.resourceMode "${require_validation.LOVABLE_MANAGED_RESOURCE}" derives the resource from the served address, so auth.${field} must not also be set`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (auth.resource === void 0 && auth.acceptedAudiences === void 0) throw new Error(`@lovable.dev/mcp-js: auth.resource, auth.acceptedAudiences or auth.resourceMode "${require_validation.LOVABLE_MANAGED_RESOURCE}" is required`);
|
|
89
98
|
}
|
|
90
99
|
function freezeAuth(auth) {
|
|
91
100
|
if (!auth) return;
|
|
@@ -161,7 +170,7 @@ function defineMcp(def) {
|
|
|
161
170
|
assertToolSchemas(def);
|
|
162
171
|
for (const tool of def.tools) require_apps.assertToolUi(tool);
|
|
163
172
|
require_apps.collectApps(def.tools);
|
|
164
|
-
|
|
173
|
+
require_validation.resolveMetricsConfig(def.metrics);
|
|
165
174
|
freezeAuth(def.auth);
|
|
166
175
|
if (def.limits) Object.freeze(def.limits);
|
|
167
176
|
if (Array.isArray(def.allowedOrigins)) Object.freeze(def.allowedOrigins);
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const require_errors = require("./errors-
|
|
2
|
+
const require_validation = require("./validation-D6hthH5Q.cjs");
|
|
3
|
+
const require_errors = require("./errors-PS8N0oRK.cjs");
|
|
4
4
|
//#region src/auth/config.ts
|
|
5
5
|
function frozenArray(value) {
|
|
6
6
|
return value === void 0 ? void 0 : Object.freeze([...value]);
|
|
@@ -42,4 +42,4 @@ exports.auth = auth;
|
|
|
42
42
|
exports.defineApp = require_errors.defineApp;
|
|
43
43
|
exports.defineMcp = require_errors.defineMcp;
|
|
44
44
|
exports.defineTool = require_errors.defineTool;
|
|
45
|
-
exports.setLogLevel =
|
|
45
|
+
exports.setLogLevel = require_validation.setLogLevel;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="./mcp-app.d.ts" />
|
|
2
|
-
import { A as ToolVisibilityContext, B as ProgressUpdate, C as TextContent, D as ToolHandlerResult, E as ToolDefinition, F as MetricsConfig, H as JwtClaims, I as MetricsOptions, L as AuthContext, M as ZodRawShape, N as ZodSchema, O as ToolUiOptions, P as Skill, R as McpClientInfo, S as ResourceLinkIcon, T as ToolContent, U as McpAuthConfig, V as ToolContext, _ as JsonValueInput, a as AppDefinitionInput, b as McpDefinitionInput, c as ConditionalSkill, d as CreateAppContextInput, f as EmbeddedBlobResource, g as JsonValue, h as ImageContent, i as AppDefinition, j as ZodOutputSchema, k as ToolUiVisibility, l as ContentAnnotations, m as EmbeddedTextResource, n as AppContextToolDefinitionInput, o as AppPermissions, p as EmbeddedResource, r as AppCsp, s as AudioContent, t as AppContextToolDefinition, u as ContentBlock, v as McpAllowedOrigins, w as ToolAnnotations, x as ResourceLink, y as McpDefinition, z as McpProtocolEra } from "./types-
|
|
2
|
+
import { A as ToolVisibilityContext, B as ProgressUpdate, C as TextContent, D as ToolHandlerResult, E as ToolDefinition, F as MetricsConfig, H as JwtClaims, I as MetricsOptions, L as AuthContext, M as ZodRawShape, N as ZodSchema, O as ToolUiOptions, P as Skill, R as McpClientInfo, S as ResourceLinkIcon, T as ToolContent, U as McpAuthConfig, V as ToolContext, _ as JsonValueInput, a as AppDefinitionInput, b as McpDefinitionInput, c as ConditionalSkill, d as CreateAppContextInput, f as EmbeddedBlobResource, g as JsonValue, h as ImageContent, i as AppDefinition, j as ZodOutputSchema, k as ToolUiVisibility, l as ContentAnnotations, m as EmbeddedTextResource, n as AppContextToolDefinitionInput, o as AppPermissions, p as EmbeddedResource, r as AppCsp, s as AudioContent, t as AppContextToolDefinition, u as ContentBlock, v as McpAllowedOrigins, w as ToolAnnotations, x as ResourceLink, y as McpDefinition, z as McpProtocolEra } from "./types-NORvAwbQ.cjs";
|
|
3
3
|
//#region src/core/define.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Declare a single MCP tool. Import the result into your MCP definition's
|
|
@@ -43,9 +43,16 @@ interface IssuerOAuthOptionsBase {
|
|
|
43
43
|
type IssuerOAuthOptions = IssuerOAuthOptionsBase & ({
|
|
44
44
|
readonly resource: string;
|
|
45
45
|
readonly acceptedAudiences?: IssuerAcceptedAudiences;
|
|
46
|
+
readonly resourceMode?: never;
|
|
46
47
|
} | {
|
|
47
48
|
readonly resource?: string;
|
|
48
49
|
readonly acceptedAudiences: IssuerAcceptedAudiences;
|
|
50
|
+
readonly resourceMode?: never;
|
|
51
|
+
} | {
|
|
52
|
+
readonly resourceMode: "lovable-managed";
|
|
53
|
+
readonly resource?: never;
|
|
54
|
+
readonly acceptedAudiences?: never;
|
|
55
|
+
readonly protectedResourceMetadataUrl?: never;
|
|
49
56
|
});
|
|
50
57
|
/**
|
|
51
58
|
* Configure OAuth against an issuer. `acceptedAudiences` (or `resource`) is the
|