@lovable.dev/mcp-js 3.5.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-D83r8WUF.js → cors-BaElJs06.js} +24 -44
- package/dist/{cors-B_Oui5La.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-STpVLkbi.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-CUnV4kTL.cjs → io-DZxlvNBF.cjs} +2 -1
- package/dist/{mcp-DpI0wwnW.cjs → mcp-BanAUaeS.cjs} +7 -7
- package/dist/{mcp-BgIFUoo1.js → mcp-D7K2Z_S0.js} +3 -3
- package/dist/{package-CuCho6-k.cjs → package-BUaaSbJm.cjs} +1 -1
- package/dist/{package-Cz6Z5F_X.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 +2 -2
|
@@ -1,75 +1,3 @@
|
|
|
1
|
-
//#region src/metrics/config.ts
|
|
2
|
-
const DEFAULT_METRICS_ENDPOINT = "https://api.lovable.dev/internal/v1/app-mcp-usage";
|
|
3
|
-
const LEGACY_METRICS_ENDPOINT = "https://api.lovable.dev/v1/app-mcp-usage";
|
|
4
|
-
const METRICS_API_KEY_ENV_VAR = "LOVABLE_API_KEY";
|
|
5
|
-
/**
|
|
6
|
-
* Validate the ingest endpoint at plugin-construction time so a malformed URL
|
|
7
|
-
* fails the build rather than silently dropping every batch at runtime.
|
|
8
|
-
*/
|
|
9
|
-
function assertMetricsEndpoint(endpoint) {
|
|
10
|
-
let url;
|
|
11
|
-
try {
|
|
12
|
-
url = new URL(endpoint);
|
|
13
|
-
} catch {
|
|
14
|
-
throw new Error(`@lovable.dev/mcp-js: metrics.endpoint must be an absolute URL, got ${JSON.stringify(endpoint)}`);
|
|
15
|
-
}
|
|
16
|
-
if (url.protocol !== "https:" && url.protocol !== "http:") throw new Error(`@lovable.dev/mcp-js: metrics.endpoint must be http(s), got ${JSON.stringify(endpoint)}`);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Resolve `boolean | MetricsOptions` into a frozen config. Telemetry is on by
|
|
20
|
-
* default and self-disables at runtime when `LOVABLE_API_KEY` is absent (so a
|
|
21
|
-
* local `vite dev` stays silent); pass `false` to opt out entirely.
|
|
22
|
-
*/
|
|
23
|
-
function resolveMetricsConfig(config = true) {
|
|
24
|
-
const options = typeof config === "boolean" ? { enabled: config } : config;
|
|
25
|
-
const endpoint = options.endpoint ?? "https://api.lovable.dev/internal/v1/app-mcp-usage";
|
|
26
|
-
assertMetricsEndpoint(endpoint);
|
|
27
|
-
return Object.freeze({
|
|
28
|
-
enabled: options.enabled ?? true,
|
|
29
|
-
endpoint,
|
|
30
|
-
headers: options.headers ?? {},
|
|
31
|
-
apiKeyEnvVar: METRICS_API_KEY_ENV_VAR
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/core/url.ts
|
|
36
|
-
function trimTrailingSlash(value) {
|
|
37
|
-
return value.replace(/\/+$/, "");
|
|
38
|
-
}
|
|
39
|
-
function isLocalHTTPHost(hostname) {
|
|
40
|
-
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Shared scheme/credential/query checks for every absolute URL we accept or
|
|
44
|
-
* discover. Returns the human-readable problem suffix so each call site can
|
|
45
|
-
* prefix it with its own subject and throw its own error type.
|
|
46
|
-
*/
|
|
47
|
-
function urlSafetyProblem(url) {
|
|
48
|
-
const isAllowedHTTP = url.protocol === "http:" && isLocalHTTPHost(url.hostname);
|
|
49
|
-
if (url.protocol !== "https:" && !isAllowedHTTP) return "must use https://, except localhost development URLs";
|
|
50
|
-
if (url.username || url.password) return "must not include credentials";
|
|
51
|
-
if (url.search || url.hash) return "must not include query or fragment";
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/core/validation.ts
|
|
55
|
-
/**
|
|
56
|
-
* Parse `raw` as an absolute URL and reject unsafe shapes (non-HTTPS except
|
|
57
|
-
* localhost, embedded credentials, query/fragment). `subject` is the
|
|
58
|
-
* fully-formed message prefix (e.g. `auth.issuer`, `managed OAuth issuer`) so
|
|
59
|
-
* each call site keeps its own wording; `ErrorClass` selects the thrown type.
|
|
60
|
-
*/
|
|
61
|
-
function parseSafeUrl(subject, raw, ErrorClass = Error) {
|
|
62
|
-
let url;
|
|
63
|
-
try {
|
|
64
|
-
url = new URL(raw);
|
|
65
|
-
} catch {
|
|
66
|
-
throw new ErrorClass(`${subject} must be an absolute URL`);
|
|
67
|
-
}
|
|
68
|
-
const problem = urlSafetyProblem(url);
|
|
69
|
-
if (problem) throw new ErrorClass(`${subject} ${problem}`);
|
|
70
|
-
return url;
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
1
|
//#region src/core/logger.ts
|
|
74
2
|
const LEVEL_RANK = {
|
|
75
3
|
silent: 0,
|
|
@@ -146,6 +74,138 @@ function describeError(err) {
|
|
|
146
74
|
}
|
|
147
75
|
}
|
|
148
76
|
//#endregion
|
|
77
|
+
//#region src/core/runtime-env.ts
|
|
78
|
+
/** Guarded `process.env` read; tolerates a missing `process` global. */
|
|
79
|
+
function readProcessEnv(name) {
|
|
80
|
+
try {
|
|
81
|
+
return typeof process !== "undefined" ? process.env?.[name] || void 0 : void 0;
|
|
82
|
+
} catch {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let cloudflareEnvPromise;
|
|
87
|
+
async function readCloudflareEnv(name) {
|
|
88
|
+
try {
|
|
89
|
+
cloudflareEnvPromise ??= import(
|
|
90
|
+
/* @vite-ignore */
|
|
91
|
+
"cloudflare:workers"
|
|
92
|
+
).then((m) => m.env).catch((err) => {
|
|
93
|
+
log.debug("runtime_env.cloudflare_import_failed", describeError(err));
|
|
94
|
+
});
|
|
95
|
+
const env = await cloudflareEnvPromise;
|
|
96
|
+
const raw = env?.[name];
|
|
97
|
+
const value = typeof raw === "string" && raw ? raw : void 0;
|
|
98
|
+
log.debug("runtime_env.read_cloudflare_env", {
|
|
99
|
+
name,
|
|
100
|
+
hasEnvBinding: !!env,
|
|
101
|
+
found: value !== void 0
|
|
102
|
+
});
|
|
103
|
+
return value;
|
|
104
|
+
} catch (err) {
|
|
105
|
+
log.debug("runtime_env.read_cloudflare_env_error", {
|
|
106
|
+
name,
|
|
107
|
+
...describeError(err)
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/auth/managed-resource.ts
|
|
114
|
+
const LOVABLE_MANAGED_RESOURCE = "lovable-managed";
|
|
115
|
+
const LOVABLE_PROJECT_ID_ENV_VAR = "__LOVABLE_PROJECT_ID";
|
|
116
|
+
function isLovableManagedResource(auth) {
|
|
117
|
+
return auth?.resourceMode === LOVABLE_MANAGED_RESOURCE;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Reports whether the request URL may anchor a Lovable-managed resource.
|
|
121
|
+
*
|
|
122
|
+
* Off Lovable hosting the URL can follow a client's `Host`; HTTPS also excludes
|
|
123
|
+
* the live-preview dev server's `http://localhost` hop.
|
|
124
|
+
*/
|
|
125
|
+
async function hasLovableManagedOrigin(request) {
|
|
126
|
+
const onPlatform = readProcessEnv(LOVABLE_PROJECT_ID_ENV_VAR) !== void 0 || await readCloudflareEnv(LOVABLE_PROJECT_ID_ENV_VAR) !== void 0;
|
|
127
|
+
const https = new URL(request.url).protocol === "https:";
|
|
128
|
+
if (onPlatform && https) return true;
|
|
129
|
+
log.error("oauth.managed_resource.origin_unavailable", {
|
|
130
|
+
onPlatform,
|
|
131
|
+
https,
|
|
132
|
+
outcome: "500 oauth configuration error"
|
|
133
|
+
});
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/metrics/config.ts
|
|
138
|
+
const DEFAULT_METRICS_ENDPOINT = "https://api.lovable.dev/internal/v1/app-mcp-usage";
|
|
139
|
+
const LEGACY_METRICS_ENDPOINT = "https://api.lovable.dev/v1/app-mcp-usage";
|
|
140
|
+
const METRICS_API_KEY_ENV_VAR = "LOVABLE_API_KEY";
|
|
141
|
+
/**
|
|
142
|
+
* Validate the ingest endpoint at plugin-construction time so a malformed URL
|
|
143
|
+
* fails the build rather than silently dropping every batch at runtime.
|
|
144
|
+
*/
|
|
145
|
+
function assertMetricsEndpoint(endpoint) {
|
|
146
|
+
let url;
|
|
147
|
+
try {
|
|
148
|
+
url = new URL(endpoint);
|
|
149
|
+
} catch {
|
|
150
|
+
throw new Error(`@lovable.dev/mcp-js: metrics.endpoint must be an absolute URL, got ${JSON.stringify(endpoint)}`);
|
|
151
|
+
}
|
|
152
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") throw new Error(`@lovable.dev/mcp-js: metrics.endpoint must be http(s), got ${JSON.stringify(endpoint)}`);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Resolve `boolean | MetricsOptions` into a frozen config. Telemetry is on by
|
|
156
|
+
* default and self-disables at runtime when `LOVABLE_API_KEY` is absent (so a
|
|
157
|
+
* local `vite dev` stays silent); pass `false` to opt out entirely.
|
|
158
|
+
*/
|
|
159
|
+
function resolveMetricsConfig(config = true) {
|
|
160
|
+
const options = typeof config === "boolean" ? { enabled: config } : config;
|
|
161
|
+
const endpoint = options.endpoint ?? "https://api.lovable.dev/internal/v1/app-mcp-usage";
|
|
162
|
+
assertMetricsEndpoint(endpoint);
|
|
163
|
+
return Object.freeze({
|
|
164
|
+
enabled: options.enabled ?? true,
|
|
165
|
+
endpoint,
|
|
166
|
+
headers: options.headers ?? {},
|
|
167
|
+
apiKeyEnvVar: METRICS_API_KEY_ENV_VAR
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/core/url.ts
|
|
172
|
+
function trimTrailingSlash(value) {
|
|
173
|
+
return value.replace(/\/+$/, "");
|
|
174
|
+
}
|
|
175
|
+
function isLocalHTTPHost(hostname) {
|
|
176
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Shared scheme/credential/query checks for every absolute URL we accept or
|
|
180
|
+
* discover. Returns the human-readable problem suffix so each call site can
|
|
181
|
+
* prefix it with its own subject and throw its own error type.
|
|
182
|
+
*/
|
|
183
|
+
function urlSafetyProblem(url) {
|
|
184
|
+
const isAllowedHTTP = url.protocol === "http:" && isLocalHTTPHost(url.hostname);
|
|
185
|
+
if (url.protocol !== "https:" && !isAllowedHTTP) return "must use https://, except localhost development URLs";
|
|
186
|
+
if (url.username || url.password) return "must not include credentials";
|
|
187
|
+
if (url.search || url.hash) return "must not include query or fragment";
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/core/validation.ts
|
|
191
|
+
/**
|
|
192
|
+
* Parse `raw` as an absolute URL and reject unsafe shapes (non-HTTPS except
|
|
193
|
+
* localhost, embedded credentials, query/fragment). `subject` is the
|
|
194
|
+
* fully-formed message prefix (e.g. `auth.issuer`, `managed OAuth issuer`) so
|
|
195
|
+
* each call site keeps its own wording; `ErrorClass` selects the thrown type.
|
|
196
|
+
*/
|
|
197
|
+
function parseSafeUrl(subject, raw, ErrorClass = Error) {
|
|
198
|
+
let url;
|
|
199
|
+
try {
|
|
200
|
+
url = new URL(raw);
|
|
201
|
+
} catch {
|
|
202
|
+
throw new ErrorClass(`${subject} must be an absolute URL`);
|
|
203
|
+
}
|
|
204
|
+
const problem = urlSafetyProblem(url);
|
|
205
|
+
if (problem) throw new ErrorClass(`${subject} ${problem}`);
|
|
206
|
+
return url;
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
149
209
|
Object.defineProperty(exports, "DEFAULT_METRICS_ENDPOINT", {
|
|
150
210
|
enumerable: true,
|
|
151
211
|
get: function() {
|
|
@@ -164,6 +224,12 @@ Object.defineProperty(exports, "LOG_LEVEL_ENV_VAR", {
|
|
|
164
224
|
return LOG_LEVEL_ENV_VAR;
|
|
165
225
|
}
|
|
166
226
|
});
|
|
227
|
+
Object.defineProperty(exports, "LOVABLE_MANAGED_RESOURCE", {
|
|
228
|
+
enumerable: true,
|
|
229
|
+
get: function() {
|
|
230
|
+
return LOVABLE_MANAGED_RESOURCE;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
167
233
|
Object.defineProperty(exports, "applyLogLevelFromEnv", {
|
|
168
234
|
enumerable: true,
|
|
169
235
|
get: function() {
|
|
@@ -176,6 +242,18 @@ Object.defineProperty(exports, "describeError", {
|
|
|
176
242
|
return describeError;
|
|
177
243
|
}
|
|
178
244
|
});
|
|
245
|
+
Object.defineProperty(exports, "hasLovableManagedOrigin", {
|
|
246
|
+
enumerable: true,
|
|
247
|
+
get: function() {
|
|
248
|
+
return hasLovableManagedOrigin;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
Object.defineProperty(exports, "isLovableManagedResource", {
|
|
252
|
+
enumerable: true,
|
|
253
|
+
get: function() {
|
|
254
|
+
return isLovableManagedResource;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
179
257
|
Object.defineProperty(exports, "log", {
|
|
180
258
|
enumerable: true,
|
|
181
259
|
get: function() {
|
|
@@ -188,6 +266,18 @@ Object.defineProperty(exports, "parseSafeUrl", {
|
|
|
188
266
|
return parseSafeUrl;
|
|
189
267
|
}
|
|
190
268
|
});
|
|
269
|
+
Object.defineProperty(exports, "readCloudflareEnv", {
|
|
270
|
+
enumerable: true,
|
|
271
|
+
get: function() {
|
|
272
|
+
return readCloudflareEnv;
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
Object.defineProperty(exports, "readProcessEnv", {
|
|
276
|
+
enumerable: true,
|
|
277
|
+
get: function() {
|
|
278
|
+
return readProcessEnv;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
191
281
|
Object.defineProperty(exports, "resolveMetricsConfig", {
|
|
192
282
|
enumerable: true,
|
|
193
283
|
get: function() {
|
|
@@ -1,75 +1,3 @@
|
|
|
1
|
-
//#region src/metrics/config.ts
|
|
2
|
-
const DEFAULT_METRICS_ENDPOINT = "https://api.lovable.dev/internal/v1/app-mcp-usage";
|
|
3
|
-
const LEGACY_METRICS_ENDPOINT = "https://api.lovable.dev/v1/app-mcp-usage";
|
|
4
|
-
const METRICS_API_KEY_ENV_VAR = "LOVABLE_API_KEY";
|
|
5
|
-
/**
|
|
6
|
-
* Validate the ingest endpoint at plugin-construction time so a malformed URL
|
|
7
|
-
* fails the build rather than silently dropping every batch at runtime.
|
|
8
|
-
*/
|
|
9
|
-
function assertMetricsEndpoint(endpoint) {
|
|
10
|
-
let url;
|
|
11
|
-
try {
|
|
12
|
-
url = new URL(endpoint);
|
|
13
|
-
} catch {
|
|
14
|
-
throw new Error(`@lovable.dev/mcp-js: metrics.endpoint must be an absolute URL, got ${JSON.stringify(endpoint)}`);
|
|
15
|
-
}
|
|
16
|
-
if (url.protocol !== "https:" && url.protocol !== "http:") throw new Error(`@lovable.dev/mcp-js: metrics.endpoint must be http(s), got ${JSON.stringify(endpoint)}`);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Resolve `boolean | MetricsOptions` into a frozen config. Telemetry is on by
|
|
20
|
-
* default and self-disables at runtime when `LOVABLE_API_KEY` is absent (so a
|
|
21
|
-
* local `vite dev` stays silent); pass `false` to opt out entirely.
|
|
22
|
-
*/
|
|
23
|
-
function resolveMetricsConfig(config = true) {
|
|
24
|
-
const options = typeof config === "boolean" ? { enabled: config } : config;
|
|
25
|
-
const endpoint = options.endpoint ?? "https://api.lovable.dev/internal/v1/app-mcp-usage";
|
|
26
|
-
assertMetricsEndpoint(endpoint);
|
|
27
|
-
return Object.freeze({
|
|
28
|
-
enabled: options.enabled ?? true,
|
|
29
|
-
endpoint,
|
|
30
|
-
headers: options.headers ?? {},
|
|
31
|
-
apiKeyEnvVar: METRICS_API_KEY_ENV_VAR
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/core/url.ts
|
|
36
|
-
function trimTrailingSlash(value) {
|
|
37
|
-
return value.replace(/\/+$/, "");
|
|
38
|
-
}
|
|
39
|
-
function isLocalHTTPHost(hostname) {
|
|
40
|
-
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Shared scheme/credential/query checks for every absolute URL we accept or
|
|
44
|
-
* discover. Returns the human-readable problem suffix so each call site can
|
|
45
|
-
* prefix it with its own subject and throw its own error type.
|
|
46
|
-
*/
|
|
47
|
-
function urlSafetyProblem(url) {
|
|
48
|
-
const isAllowedHTTP = url.protocol === "http:" && isLocalHTTPHost(url.hostname);
|
|
49
|
-
if (url.protocol !== "https:" && !isAllowedHTTP) return "must use https://, except localhost development URLs";
|
|
50
|
-
if (url.username || url.password) return "must not include credentials";
|
|
51
|
-
if (url.search || url.hash) return "must not include query or fragment";
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/core/validation.ts
|
|
55
|
-
/**
|
|
56
|
-
* Parse `raw` as an absolute URL and reject unsafe shapes (non-HTTPS except
|
|
57
|
-
* localhost, embedded credentials, query/fragment). `subject` is the
|
|
58
|
-
* fully-formed message prefix (e.g. `auth.issuer`, `managed OAuth issuer`) so
|
|
59
|
-
* each call site keeps its own wording; `ErrorClass` selects the thrown type.
|
|
60
|
-
*/
|
|
61
|
-
function parseSafeUrl(subject, raw, ErrorClass = Error) {
|
|
62
|
-
let url;
|
|
63
|
-
try {
|
|
64
|
-
url = new URL(raw);
|
|
65
|
-
} catch {
|
|
66
|
-
throw new ErrorClass(`${subject} must be an absolute URL`);
|
|
67
|
-
}
|
|
68
|
-
const problem = urlSafetyProblem(url);
|
|
69
|
-
if (problem) throw new ErrorClass(`${subject} ${problem}`);
|
|
70
|
-
return url;
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
1
|
//#region src/core/logger.ts
|
|
74
2
|
const LEVEL_RANK = {
|
|
75
3
|
silent: 0,
|
|
@@ -146,4 +74,136 @@ function describeError(err) {
|
|
|
146
74
|
}
|
|
147
75
|
}
|
|
148
76
|
//#endregion
|
|
149
|
-
|
|
77
|
+
//#region src/core/runtime-env.ts
|
|
78
|
+
/** Guarded `process.env` read; tolerates a missing `process` global. */
|
|
79
|
+
function readProcessEnv(name) {
|
|
80
|
+
try {
|
|
81
|
+
return typeof process !== "undefined" ? process.env?.[name] || void 0 : void 0;
|
|
82
|
+
} catch {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let cloudflareEnvPromise;
|
|
87
|
+
async function readCloudflareEnv(name) {
|
|
88
|
+
try {
|
|
89
|
+
cloudflareEnvPromise ??= import(
|
|
90
|
+
/* @vite-ignore */
|
|
91
|
+
"cloudflare:workers"
|
|
92
|
+
).then((m) => m.env).catch((err) => {
|
|
93
|
+
log.debug("runtime_env.cloudflare_import_failed", describeError(err));
|
|
94
|
+
});
|
|
95
|
+
const env = await cloudflareEnvPromise;
|
|
96
|
+
const raw = env?.[name];
|
|
97
|
+
const value = typeof raw === "string" && raw ? raw : void 0;
|
|
98
|
+
log.debug("runtime_env.read_cloudflare_env", {
|
|
99
|
+
name,
|
|
100
|
+
hasEnvBinding: !!env,
|
|
101
|
+
found: value !== void 0
|
|
102
|
+
});
|
|
103
|
+
return value;
|
|
104
|
+
} catch (err) {
|
|
105
|
+
log.debug("runtime_env.read_cloudflare_env_error", {
|
|
106
|
+
name,
|
|
107
|
+
...describeError(err)
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/auth/managed-resource.ts
|
|
114
|
+
const LOVABLE_MANAGED_RESOURCE = "lovable-managed";
|
|
115
|
+
const LOVABLE_PROJECT_ID_ENV_VAR = "__LOVABLE_PROJECT_ID";
|
|
116
|
+
function isLovableManagedResource(auth) {
|
|
117
|
+
return auth?.resourceMode === LOVABLE_MANAGED_RESOURCE;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Reports whether the request URL may anchor a Lovable-managed resource.
|
|
121
|
+
*
|
|
122
|
+
* Off Lovable hosting the URL can follow a client's `Host`; HTTPS also excludes
|
|
123
|
+
* the live-preview dev server's `http://localhost` hop.
|
|
124
|
+
*/
|
|
125
|
+
async function hasLovableManagedOrigin(request) {
|
|
126
|
+
const onPlatform = readProcessEnv(LOVABLE_PROJECT_ID_ENV_VAR) !== void 0 || await readCloudflareEnv(LOVABLE_PROJECT_ID_ENV_VAR) !== void 0;
|
|
127
|
+
const https = new URL(request.url).protocol === "https:";
|
|
128
|
+
if (onPlatform && https) return true;
|
|
129
|
+
log.error("oauth.managed_resource.origin_unavailable", {
|
|
130
|
+
onPlatform,
|
|
131
|
+
https,
|
|
132
|
+
outcome: "500 oauth configuration error"
|
|
133
|
+
});
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/metrics/config.ts
|
|
138
|
+
const DEFAULT_METRICS_ENDPOINT = "https://api.lovable.dev/internal/v1/app-mcp-usage";
|
|
139
|
+
const LEGACY_METRICS_ENDPOINT = "https://api.lovable.dev/v1/app-mcp-usage";
|
|
140
|
+
const METRICS_API_KEY_ENV_VAR = "LOVABLE_API_KEY";
|
|
141
|
+
/**
|
|
142
|
+
* Validate the ingest endpoint at plugin-construction time so a malformed URL
|
|
143
|
+
* fails the build rather than silently dropping every batch at runtime.
|
|
144
|
+
*/
|
|
145
|
+
function assertMetricsEndpoint(endpoint) {
|
|
146
|
+
let url;
|
|
147
|
+
try {
|
|
148
|
+
url = new URL(endpoint);
|
|
149
|
+
} catch {
|
|
150
|
+
throw new Error(`@lovable.dev/mcp-js: metrics.endpoint must be an absolute URL, got ${JSON.stringify(endpoint)}`);
|
|
151
|
+
}
|
|
152
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") throw new Error(`@lovable.dev/mcp-js: metrics.endpoint must be http(s), got ${JSON.stringify(endpoint)}`);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Resolve `boolean | MetricsOptions` into a frozen config. Telemetry is on by
|
|
156
|
+
* default and self-disables at runtime when `LOVABLE_API_KEY` is absent (so a
|
|
157
|
+
* local `vite dev` stays silent); pass `false` to opt out entirely.
|
|
158
|
+
*/
|
|
159
|
+
function resolveMetricsConfig(config = true) {
|
|
160
|
+
const options = typeof config === "boolean" ? { enabled: config } : config;
|
|
161
|
+
const endpoint = options.endpoint ?? "https://api.lovable.dev/internal/v1/app-mcp-usage";
|
|
162
|
+
assertMetricsEndpoint(endpoint);
|
|
163
|
+
return Object.freeze({
|
|
164
|
+
enabled: options.enabled ?? true,
|
|
165
|
+
endpoint,
|
|
166
|
+
headers: options.headers ?? {},
|
|
167
|
+
apiKeyEnvVar: METRICS_API_KEY_ENV_VAR
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/core/url.ts
|
|
172
|
+
function trimTrailingSlash(value) {
|
|
173
|
+
return value.replace(/\/+$/, "");
|
|
174
|
+
}
|
|
175
|
+
function isLocalHTTPHost(hostname) {
|
|
176
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Shared scheme/credential/query checks for every absolute URL we accept or
|
|
180
|
+
* discover. Returns the human-readable problem suffix so each call site can
|
|
181
|
+
* prefix it with its own subject and throw its own error type.
|
|
182
|
+
*/
|
|
183
|
+
function urlSafetyProblem(url) {
|
|
184
|
+
const isAllowedHTTP = url.protocol === "http:" && isLocalHTTPHost(url.hostname);
|
|
185
|
+
if (url.protocol !== "https:" && !isAllowedHTTP) return "must use https://, except localhost development URLs";
|
|
186
|
+
if (url.username || url.password) return "must not include credentials";
|
|
187
|
+
if (url.search || url.hash) return "must not include query or fragment";
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/core/validation.ts
|
|
191
|
+
/**
|
|
192
|
+
* Parse `raw` as an absolute URL and reject unsafe shapes (non-HTTPS except
|
|
193
|
+
* localhost, embedded credentials, query/fragment). `subject` is the
|
|
194
|
+
* fully-formed message prefix (e.g. `auth.issuer`, `managed OAuth issuer`) so
|
|
195
|
+
* each call site keeps its own wording; `ErrorClass` selects the thrown type.
|
|
196
|
+
*/
|
|
197
|
+
function parseSafeUrl(subject, raw, ErrorClass = Error) {
|
|
198
|
+
let url;
|
|
199
|
+
try {
|
|
200
|
+
url = new URL(raw);
|
|
201
|
+
} catch {
|
|
202
|
+
throw new ErrorClass(`${subject} must be an absolute URL`);
|
|
203
|
+
}
|
|
204
|
+
const problem = urlSafetyProblem(url);
|
|
205
|
+
if (problem) throw new ErrorClass(`${subject} ${problem}`);
|
|
206
|
+
return url;
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
export { resolveMetricsConfig as a, isLovableManagedResource as c, LOG_LEVEL_ENV_VAR as d, applyLogLevelFromEnv as f, setLogLevel as h, LEGACY_METRICS_ENDPOINT as i, readCloudflareEnv as l, log as m, trimTrailingSlash as n, LOVABLE_MANAGED_RESOURCE as o, describeError as p, DEFAULT_METRICS_ENDPOINT as r, hasLovableManagedOrigin as s, parseSafeUrl as t, readProcessEnv as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lovable.dev/mcp-js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=20"
|
|
6
6
|
},
|
|
@@ -180,7 +180,7 @@
|
|
|
180
180
|
},
|
|
181
181
|
"devDependencies": {
|
|
182
182
|
"@modelcontextprotocol/ext-apps": "^1.7.3",
|
|
183
|
-
"@tailwindcss/node": "4.3.
|
|
183
|
+
"@tailwindcss/node": "4.3.4",
|
|
184
184
|
"@tailwindcss/oxide": "4.3.3",
|
|
185
185
|
"@tailwindcss/vite": "4.3.0",
|
|
186
186
|
"@types/estree": "^1.0.8",
|