@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
package/README.md
CHANGED
|
@@ -227,7 +227,7 @@ Three caveats:
|
|
|
227
227
|
|
|
228
228
|
`@lovable.dev/mcp-js` can protect an app-hosted MCP server as an OAuth 2.1 resource server. The package does not implement `/authorize`, `/token`, client registration, refresh tokens, or consent UI; those stay with the authorization server (for today's Supabase-backed Lovable Cloud apps, Supabase Auth). The MCP runtime validates bearer JWTs, publishes RFC 9728 protected-resource metadata, returns `WWW-Authenticate: Bearer ... resource_metadata="..."` challenges, and passes verified claims to tools.
|
|
229
229
|
|
|
230
|
-
Point the issuer at your OAuth/OIDC authorization server and anchor the accepted audience with
|
|
230
|
+
Point the issuer at your OAuth/OIDC authorization server and anchor the accepted audience with `resource`, `acceptedAudiences`, or, on Lovable hosting, `resourceMode: "lovable-managed"`:
|
|
231
231
|
|
|
232
232
|
```ts
|
|
233
233
|
// src/lib/mcp/index.ts
|
|
@@ -247,7 +247,25 @@ export default defineMcp({
|
|
|
247
247
|
});
|
|
248
248
|
```
|
|
249
249
|
|
|
250
|
-
The `auth` namespace groups auth families; today it exposes `auth.oauth.issuer(...)`. It is exported from the package root (shown above), the canonical surface for app authors. `issuer` must be HTTPS (except localhost development URLs) and match the token `iss` exactly; the SDK discovers `jwks_uri` from the issuer's OAuth/OIDC metadata.
|
|
250
|
+
The `auth` namespace groups auth families; today it exposes `auth.oauth.issuer(...)`. It is exported from the package root (shown above), the canonical surface for app authors. `issuer` must be HTTPS (except localhost development URLs) and match the token `iss` exactly; the SDK discovers `jwks_uri` from the issuer's OAuth/OIDC metadata. Pass configuration values explicitly; the SDK reads no configuration from environment variables.
|
|
251
|
+
|
|
252
|
+
### Lovable-managed resource
|
|
253
|
+
|
|
254
|
+
On Lovable hosting, let the platform supply the public address instead of pinning `resource`:
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
auth: auth.oauth.issuer({
|
|
258
|
+
issuer: "https://lovable.dev/oauth",
|
|
259
|
+
resourceMode: "lovable-managed",
|
|
260
|
+
requiredScopes: ["openid", "email", "profile", "offline"],
|
|
261
|
+
}),
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Each request's `resource` is the origin Lovable routing served it on plus the MCP route path, for example `https://my-app.lovable.app/api/public/mcp`. The `WWW-Authenticate` challenge, the metadata `resource` and the accepted token audience all use that one value, so renaming the app or adding a custom domain needs no code change or republish. A token is accepted only on the address it was issued for: after a rename, clients reconnect through the new URL.
|
|
265
|
+
|
|
266
|
+
The mode trusts the request URL Lovable routing delivers and ignores `X-Forwarded-Host`/`X-Forwarded-Proto`. It fails closed with a `500` (no challenge, no tools) when the request is not HTTPS or the runtime lacks the `__LOVABLE_PROJECT_ID` binding Lovable hosting injects. Outside Lovable hosting, and on the live-preview dev server (`*.lovableproject.com`), pin `resource` instead. The Supabase adapter rejects the mode because clients reach Edge Functions on `supabase.co` directly. `resourceMode` is mutually exclusive with `resource`, `acceptedAudiences` and `protectedResourceMetadataUrl`; the manifest records it as `resource_mode`.
|
|
267
|
+
|
|
268
|
+
Existing apps keep their pinned `resource` behavior. Switching one to `lovable-managed` is a code change: upgrade the package, replace `resource`, regenerate the manifest and republish.
|
|
251
269
|
|
|
252
270
|
### Supabase recipe
|
|
253
271
|
|
|
@@ -371,8 +389,9 @@ Use an OAuth access token from the configured authorization server for MCP calls
|
|
|
371
389
|
| Field | Meaning |
|
|
372
390
|
| --- | --- |
|
|
373
391
|
| `issuer` | OAuth/OIDC issuer URL. Must be HTTPS except localhost development URLs and must match the token `iss` exactly. Required. |
|
|
374
|
-
| `resource` | Canonical protected-resource URL published in metadata. It also anchors the accepted audience unless `acceptedAudiences` is set. When omitted, the published resource is derived from the request origin plus the stack adapter's `resourcePath` and you must set `acceptedAudiences`; the metadata handler throws at construction if neither `resource` nor `resourcePath` is set. |
|
|
375
|
-
| `
|
|
392
|
+
| `resource` | Canonical protected-resource URL published in metadata. It also anchors the accepted audience unless `acceptedAudiences` is set. When omitted, the published resource is derived from the request origin plus the stack adapter's `resourcePath` and you must set `acceptedAudiences` or `resourceMode`; the metadata handler throws at construction if neither `resource` nor `resourcePath` is set. |
|
|
393
|
+
| `resourceMode` | `"lovable-managed"` derives `resource` and the accepted audience from the address Lovable hosting serves each request on; see [Lovable-managed resource](#lovable-managed-resource). |
|
|
394
|
+
| `acceptedAudiences` | Accepted JWT audience(s). Defaults to `resource` when that is set. One of `resource`, `acceptedAudiences` or `resourceMode` is required. A populated token `aud` must match one of these exactly; when `aud` is empty or absent, see `acceptResourceClaim`. |
|
|
376
395
|
| `acceptResourceClaim` | Defaults to `true`: a token whose `aud` is an empty array or absent is accepted when its `resource` claim matches an accepted audience (trailing slashes ignored). The fallback engages for **any** configured issuer minting such tokens, not only Lovable's. The `resource` claim is a Lovable OAuth convention derived from the RFC 8707 `resource` request parameter, not a registered JWT claim; Lovable's OAuth server validates the requested resource at authorization time before stamping it. A populated `aud` is always authoritative — the fallback never rescues a non-matching `aud`. Set `false` to require a matching `aud` (strict RFC 9068). |
|
|
377
396
|
| `jwksUri` | JWKS URL override. If omitted, the runtime discovers `jwks_uri` from OAuth/OIDC metadata; setting it skips discovery entirely. |
|
|
378
397
|
| `requiredScopes` | Required scopes. Advertised in metadata/challenges and enforced against the token `scope`. |
|
|
@@ -384,9 +403,9 @@ Use an OAuth access token from the configured authorization server for MCP calls
|
|
|
384
403
|
|
|
385
404
|
Protected-resource metadata is derived from the same config. When `resource` is omitted, the published resource is the incoming request origin plus the MCP route path the stack adapter supplies as `resourcePath` (for example, `https://my-app.lovable.app/mcp`); `authorization_servers` is the configured issuer, and `resource_name` is `defineMcp({ title })` unless `resourceName` overrides it. Because the metadata endpoint is served from `/.well-known/...`, it can't infer the resource from its own path — the handler throws at construction when neither `resource` nor `resourcePath` is set (the generated TanStack routes always pass `resourcePath`). For Supabase auth, this metadata still names the MCP resource even though Supabase JWTs use the project audience `"authenticated"`.
|
|
386
405
|
|
|
387
|
-
The request-derived `resource` default trusts the incoming `Host` to name this server's origin.
|
|
406
|
+
The request-derived `resource` default trusts the incoming `Host` to name this server's origin. Unless `resourceMode` is `"lovable-managed"`, a config sets `acceptedAudiences` (Supabase: `"authenticated"`) or `resource`, so this default only names the advertised protected-resource metadata, never the accepted JWT audience. A platform that terminates TLS and sets `Host` from the verified domain (Lovable Cloud) makes this safe. Deployments fronted by a proxy that forwards an attacker-controlled `Host` should pin `resource` to the canonical URL so a spoofed host cannot shift the advertised metadata URL.
|
|
388
407
|
|
|
389
|
-
Use `auth.oauth.issuer(...)`, set `resource` or `
|
|
408
|
+
Use `auth.oauth.issuer(...)`, set `resource`, `acceptedAudiences` or `resourceMode: "lovable-managed"` to anchor the accepted audience, and optionally set `jwksUri` and `requiredScopes`. For Supabase project auth, set `acceptedAudiences: "authenticated"`, keep app/business checks in app code, and forward `ctx.getToken()` to Supabase for RLS-backed data access.
|
|
390
409
|
|
|
391
410
|
## Testing
|
|
392
411
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z as McpProtocolEra } from "./types-
|
|
1
|
+
import { z as McpProtocolEra } from "./types-NORvAwbQ.cjs";
|
|
2
2
|
//#region src/metrics/impl/base.d.ts
|
|
3
|
-
type InvocationOutcome = "ok" | "tool_error" | "handler_error" | "transport_error" | "app_context_error" | "auth_challenge" | "auth_token_expired" | "auth_token_invalid" | "auth_insufficient_scope" | "auth_unexpected_error" | "origin_rejected" | "auth_discovery_config_error" | "auth_discovery_unreachable" | "auth_jwks_config_error" | "auth_jwks_unreachable";
|
|
3
|
+
type InvocationOutcome = "ok" | "tool_error" | "handler_error" | "transport_error" | "app_context_error" | "auth_challenge" | "auth_token_expired" | "auth_token_invalid" | "auth_insufficient_scope" | "auth_unexpected_error" | "origin_rejected" | "auth_discovery_config_error" | "auth_discovery_unreachable" | "auth_jwks_config_error" | "auth_jwks_unreachable" | "auth_resource_origin_unavailable";
|
|
4
4
|
/** One recorded MCP call. Carries no arguments or response payloads — only the
|
|
5
5
|
* tool name, the JSON-RPC method, the result class, timing, and byte sizes.
|
|
6
6
|
* `errorText` is the sole exception: it is logged locally for debugging and
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z as McpProtocolEra } from "./types-
|
|
1
|
+
import { z as McpProtocolEra } from "./types-NORvAwbQ.js";
|
|
2
2
|
//#region src/metrics/impl/base.d.ts
|
|
3
|
-
type InvocationOutcome = "ok" | "tool_error" | "handler_error" | "transport_error" | "app_context_error" | "auth_challenge" | "auth_token_expired" | "auth_token_invalid" | "auth_insufficient_scope" | "auth_unexpected_error" | "origin_rejected" | "auth_discovery_config_error" | "auth_discovery_unreachable" | "auth_jwks_config_error" | "auth_jwks_unreachable";
|
|
3
|
+
type InvocationOutcome = "ok" | "tool_error" | "handler_error" | "transport_error" | "app_context_error" | "auth_challenge" | "auth_token_expired" | "auth_token_invalid" | "auth_insufficient_scope" | "auth_unexpected_error" | "origin_rejected" | "auth_discovery_config_error" | "auth_discovery_unreachable" | "auth_jwks_config_error" | "auth_jwks_unreachable" | "auth_resource_origin_unavailable";
|
|
4
4
|
/** One recorded MCP call. Carries no arguments or response payloads — only the
|
|
5
5
|
* tool name, the JSON-RPC method, the result class, timing, and byte sizes.
|
|
6
6
|
* `errorText` is the sole exception: it is logged locally for debugging and
|
|
@@ -7,7 +7,7 @@ import("zod/v3").catch((err) => {
|
|
|
7
7
|
}).then(() => import("vite").catch((err) => {
|
|
8
8
|
const message = err instanceof Error ? err.message : String(err);
|
|
9
9
|
throw new Error(`@lovable.dev/mcp-js requires vite >=5.0.0 <9.0.0 for manifest extraction. Install a compatible Vite version in the project (for example, npm install -D vite@^7) and include dev dependencies when running this command. Underlying error: ${message}`);
|
|
10
|
-
})).then(() => Promise.resolve().then(() => require("../io-
|
|
10
|
+
})).then(() => Promise.resolve().then(() => require("../io-DZxlvNBF.cjs"))).then(({ runExtract }) => runExtract(projectRoot)).catch((err) => {
|
|
11
11
|
console.error(err instanceof Error ? err.message : String(err));
|
|
12
12
|
process.exit(1);
|
|
13
13
|
});
|
|
@@ -7,7 +7,7 @@ import("zod/v3").catch((err) => {
|
|
|
7
7
|
}).then(() => import("vite").catch((err) => {
|
|
8
8
|
const message = err instanceof Error ? err.message : String(err);
|
|
9
9
|
throw new Error(`@lovable.dev/mcp-js requires vite >=5.0.0 <9.0.0 for manifest extraction. Install a compatible Vite version in the project (for example, npm install -D vite@^7) and include dev dependencies when running this command. Underlying error: ${message}`);
|
|
10
|
-
})).then(() => import("../io-
|
|
10
|
+
})).then(() => import("../io-B5n6fVX1.js")).then(({ runExtract }) => runExtract(projectRoot)).catch((err) => {
|
|
11
11
|
console.error(err instanceof Error ? err.message : String(err));
|
|
12
12
|
process.exit(1);
|
|
13
13
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as version } from "./package-
|
|
1
|
+
import { a as resolveMetricsConfig, c as isLovableManagedResource, d as LOG_LEVEL_ENV_VAR, f as applyLogLevelFromEnv, l as readCloudflareEnv, m as log, n as trimTrailingSlash, p as describeError, s as hasLovableManagedOrigin, t as parseSafeUrl, u as readProcessEnv } from "./validation-xzkdIA-x.js";
|
|
2
|
+
import { t as version } from "./package-DEUoZczA.js";
|
|
3
3
|
import "./metadata-path-CAkNcfyY.js";
|
|
4
4
|
import { createLocalJWKSet, decodeProtectedHeader, errors, jwtVerify } from "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;
|
|
@@ -217,32 +208,6 @@ var BaseMetricRecorder = class {
|
|
|
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
|
-
log.debug("metrics.cloudflare_env_import_failed", describeError(err));
|
|
228
|
-
});
|
|
229
|
-
const env = await cloudflareEnvPromise;
|
|
230
|
-
const raw = env?.[name];
|
|
231
|
-
const value = typeof raw === "string" && raw ? raw : void 0;
|
|
232
|
-
log.debug("metrics.read_cloudflare_env", {
|
|
233
|
-
name,
|
|
234
|
-
hasEnvBinding: !!env,
|
|
235
|
-
found: value !== void 0
|
|
236
|
-
});
|
|
237
|
-
return value;
|
|
238
|
-
} catch (err) {
|
|
239
|
-
log.debug("metrics.read_cloudflare_env_error", {
|
|
240
|
-
name,
|
|
241
|
-
...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 {
|
|
@@ -484,10 +449,12 @@ 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
460
|
if (auth.resource) return trimTrailingSlash(auth.resource);
|
|
@@ -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 = !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,6 +826,18 @@ 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 (isLovableManagedResource(runtime.auth) && !await 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);
|