@lovable.dev/mcp-js 4.0.0-rc.0 → 4.0.0-rc.1
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 +104 -1
- package/dist/{authorize-Chb9Sb1f.d.ts → authorize-8crkySbp.d.ts} +1 -1
- package/dist/{authorize-Ba1deW5O.d.cts → authorize-BZdUmD37.d.cts} +1 -1
- package/dist/{base-D7ei8TjY.d.cts → base-CChLZaEN.d.cts} +1 -1
- package/dist/{base-D-lvtqSA.d.ts → base-DQPu0cno.d.ts} +1 -1
- package/dist/cli/check-server.cjs +61 -0
- package/dist/cli/check-server.d.cts +1 -0
- package/dist/cli/check-server.d.ts +1 -0
- package/dist/cli/check-server.js +62 -0
- package/dist/cli/extract-manifest.cjs +1 -1
- package/dist/cli/extract-manifest.js +1 -1
- package/dist/{cors-BuPvEjxu.cjs → cors-Ct-kdMcl.cjs} +1 -1
- package/dist/{cors-D9LajKfo.js → cors-Ct8SFh-_.js} +1 -1
- package/dist/diagnostic-ClI2_5MW.js +11 -0
- package/dist/diagnostic-DRKjgCsW.d.cts +12 -0
- package/dist/diagnostic-DRKjgCsW.d.ts +12 -0
- package/dist/diagnostic-ol9IE9Dl.cjs +16 -0
- package/dist/{errors-BEl2IOnx.js → errors-Cul5Uyfw.js} +3 -2
- package/dist/{errors-BlSu6Nrn.cjs → errors-ebgNFNvm.cjs} +3 -2
- package/dist/format-DDzvc92Z.cjs +41 -0
- package/dist/format-DKEuO8Tn.js +30 -0
- package/dist/hooks-BOdDe251.js +353 -0
- package/dist/hooks-xQl3EkDa.cjs +382 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{io-B72X5KDG.d.ts → io-4N9Hcw0w.d.ts} +1 -1
- package/dist/{io-foChTR9t.d.cts → io-Be8y8E2V.d.cts} +1 -1
- package/dist/{io-BpxqVag8.cjs → io-Bf4Narx6.cjs} +17 -5
- package/dist/{io-DFsll31O.js → io-VMIaguRH.js} +14 -2
- package/dist/{mcp-DMMqfwKm.cjs → mcp-By6C2M4i.cjs} +156 -70
- package/dist/{mcp-B1wBn_X-.js → mcp-DWxIy07i.js} +154 -68
- package/dist/{package-Bt33FsvP.cjs → package-CBMX__7C.cjs} +1 -1
- package/dist/{package-BWLBCBmc.js → package-Ci4yKJUI.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 +1 -1
- package/dist/protocols/oauth-metadata.d.cts +3 -3
- package/dist/protocols/oauth-metadata.d.ts +3 -3
- package/dist/protocols/oauth-metadata.js +1 -1
- package/dist/stacks/supabase/index.cjs +2 -2
- package/dist/stacks/supabase/index.d.cts +1 -1
- package/dist/stacks/supabase/index.d.ts +1 -1
- package/dist/stacks/supabase/index.js +2 -2
- package/dist/stacks/supabase/vite.cjs +40 -19
- package/dist/stacks/supabase/vite.d.cts +1 -1
- package/dist/stacks/supabase/vite.d.ts +1 -1
- package/dist/stacks/supabase/vite.js +34 -13
- package/dist/stacks/tanstack/index.cjs +2 -2
- package/dist/stacks/tanstack/index.d.cts +2 -2
- package/dist/stacks/tanstack/index.d.ts +2 -2
- package/dist/stacks/tanstack/index.js +2 -2
- package/dist/stacks/tanstack/vite.cjs +33 -25
- package/dist/stacks/tanstack/vite.d.cts +1 -1
- package/dist/stacks/tanstack/vite.d.ts +1 -1
- package/dist/stacks/tanstack/vite.js +26 -18
- package/dist/testing/index.cjs +46 -0
- package/dist/testing/index.d.cts +10 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.js +44 -0
- package/dist/testing/server.cjs +197 -0
- package/dist/testing/server.d.cts +31 -0
- package/dist/testing/server.d.ts +31 -0
- package/dist/testing/server.js +195 -0
- package/dist/tool-result-teeTDoM1.js +70 -0
- package/dist/tool-result-yqOfZUOP.cjs +87 -0
- package/dist/{types-srTXYLoX.d.cts → types-CyDJi9Jb.d.cts} +7 -1
- package/dist/{types-srTXYLoX.d.ts → types-CyDJi9Jb.d.ts} +7 -1
- package/package.json +40 -4
- package/skill-imports.d.cts +1 -0
- package/skill-imports.d.ts +11 -0
- package/dist/fs-errors-CWNzOV75.cjs +0 -11
- package/dist/fs-errors-PA2t1TIp.js +0 -6
- package/dist/supabase-config-CakTU8YF.js +0 -26
- package/dist/supabase-config-Dz7dnUv0.cjs +0 -31
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { m as McpDefinition } from "../types-
|
|
2
|
-
import { t as MetricsRecorder } from "../base-
|
|
3
|
-
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../authorize-
|
|
1
|
+
import { m as McpDefinition } from "../types-CyDJi9Jb.cjs";
|
|
2
|
+
import { t as MetricsRecorder } from "../base-CChLZaEN.cjs";
|
|
3
|
+
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../authorize-BZdUmD37.cjs";
|
|
4
4
|
//#region src/protocols/oauth-metadata.d.ts
|
|
5
5
|
type OAuthProtectedResourceMetadataHandler = (request: Request, recorder?: MetricsRecorder, scheduleBackground?: ScheduleBackground) => Promise<Response>;
|
|
6
6
|
declare function createOAuthProtectedResourceMetadataHandler(mcp: McpDefinition, options?: McpRuntimeOptions): OAuthProtectedResourceMetadataHandler;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { m as McpDefinition } from "../types-
|
|
2
|
-
import { t as MetricsRecorder } from "../base-
|
|
3
|
-
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../authorize-
|
|
1
|
+
import { m as McpDefinition } from "../types-CyDJi9Jb.js";
|
|
2
|
+
import { t as MetricsRecorder } from "../base-DQPu0cno.js";
|
|
3
|
+
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../authorize-8crkySbp.js";
|
|
4
4
|
//#region src/protocols/oauth-metadata.d.ts
|
|
5
5
|
type OAuthProtectedResourceMetadataHandler = (request: Request, recorder?: MetricsRecorder, scheduleBackground?: ScheduleBackground) => Promise<Response>;
|
|
6
6
|
declare function createOAuthProtectedResourceMetadataHandler(mcp: McpDefinition, options?: McpRuntimeOptions): OAuthProtectedResourceMetadataHandler;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as log, r as describeError } from "../logger-CpLgYbCG.js";
|
|
2
|
-
import { a as oauthConfigurationErrorResponse, f as JSON_HEADERS, i as normalizeHttpMethod, l as emitBeforeResponse, m as methodNotAllowed, p as finalizeWireResponse, r as getOAuthRuntime, s as resolveProtectedResource, t as evaluateCors, u as createNoopRecorder } from "../cors-
|
|
2
|
+
import { a as oauthConfigurationErrorResponse, f as JSON_HEADERS, i as normalizeHttpMethod, l as emitBeforeResponse, m as methodNotAllowed, p as finalizeWireResponse, r as getOAuthRuntime, s as resolveProtectedResource, t as evaluateCors, u as createNoopRecorder } from "../cors-Ct8SFh-_.js";
|
|
3
3
|
//#region src/protocols/oauth-metadata.ts
|
|
4
4
|
function notFound() {
|
|
5
5
|
return new Response(JSON.stringify({ error: "not found" }), {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_logger = require("../../logger-C-Hdu57K.cjs");
|
|
3
|
-
const require_cors = require("../../cors-
|
|
3
|
+
const require_cors = require("../../cors-Ct-kdMcl.cjs");
|
|
4
4
|
const require_metadata_path = require("../../metadata-path-zd7NSNoa.cjs");
|
|
5
|
-
const require_mcp = require("../../mcp-
|
|
5
|
+
const require_mcp = require("../../mcp-By6C2M4i.cjs");
|
|
6
6
|
const require_protocols_oauth_metadata = require("../../protocols/oauth-metadata.cjs");
|
|
7
7
|
const require_forwarded = require("../../forwarded-B37IdmMX.cjs");
|
|
8
8
|
const require_paths = require("../../paths-OP318a6c.cjs");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as McpDefinition } from "../../types-
|
|
1
|
+
import { m as McpDefinition } from "../../types-CyDJi9Jb.cjs";
|
|
2
2
|
//#region src/stacks/supabase/handler.d.ts
|
|
3
3
|
type SupabaseHandler = (request: Request) => Promise<Response>;
|
|
4
4
|
interface SupabaseHandlerOptions {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as McpDefinition } from "../../types-
|
|
1
|
+
import { m as McpDefinition } from "../../types-CyDJi9Jb.js";
|
|
2
2
|
//#region src/stacks/supabase/handler.d.ts
|
|
3
3
|
type SupabaseHandler = (request: Request) => Promise<Response>;
|
|
4
4
|
interface SupabaseHandlerOptions {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { s as trimTrailingSlash } from "../../logger-CpLgYbCG.js";
|
|
2
|
-
import { c as createRecorderForRuntime, o as assertResourcePathShape } from "../../cors-
|
|
2
|
+
import { c as createRecorderForRuntime, o as assertResourcePathShape } from "../../cors-Ct8SFh-_.js";
|
|
3
3
|
import { t as OAUTH_PROTECTED_RESOURCE_METADATA_PATH } from "../../metadata-path-CAkNcfyY.js";
|
|
4
|
-
import { t as createMcpProtocolHandler } from "../../mcp-
|
|
4
|
+
import { t as createMcpProtocolHandler } from "../../mcp-DWxIy07i.js";
|
|
5
5
|
import { createOAuthProtectedResourceMetadataHandler } from "../../protocols/oauth-metadata.js";
|
|
6
6
|
import { t as applyForwardedOrigin } from "../../forwarded-BBXvFeh6.js";
|
|
7
7
|
import { n as assertFunctionName, t as FUNCTIONS_MOUNT_PREFIX } from "../../paths-IS65L6TA.js";
|
|
@@ -2,9 +2,8 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_package = require("../../package-
|
|
6
|
-
const
|
|
7
|
-
const require_supabase_config = require("../../supabase-config-Dz7dnUv0.cjs");
|
|
5
|
+
const require_package = require("../../package-CBMX__7C.cjs");
|
|
6
|
+
const require_hooks = require("../../hooks-xQl3EkDa.cjs");
|
|
8
7
|
const require_paths = require("../../paths-OP318a6c.cjs");
|
|
9
8
|
let node_fs = require("node:fs");
|
|
10
9
|
let node_path = require("node:path");
|
|
@@ -17,7 +16,7 @@ function fileExists(path) {
|
|
|
17
16
|
(0, node_fs.lstatSync)(path);
|
|
18
17
|
return true;
|
|
19
18
|
} catch (err) {
|
|
20
|
-
if (
|
|
19
|
+
if (require_hooks.isFileMissing(err)) return false;
|
|
21
20
|
throw err;
|
|
22
21
|
}
|
|
23
22
|
}
|
|
@@ -37,7 +36,7 @@ function writeIfChanged(file, content, ownershipCheck) {
|
|
|
37
36
|
try {
|
|
38
37
|
existing = (0, node_fs.readFileSync)(file, "utf8");
|
|
39
38
|
} catch (err) {
|
|
40
|
-
if (!
|
|
39
|
+
if (!require_hooks.isFileMissing(err)) throw err;
|
|
41
40
|
}
|
|
42
41
|
if (existing !== void 0) {
|
|
43
42
|
if (!ownershipCheck(existing)) throw new Error(`@lovable.dev/mcp-js: refusing to overwrite user-authored file at ${file}. Delete it or move it first.`);
|
|
@@ -146,11 +145,15 @@ function importMetaEnvDefines(inlineEnv) {
|
|
|
146
145
|
for (const [key, value] of Object.entries(env)) if (/^[A-Za-z_$][\w$]*$/.test(key)) defines[`import.meta.env.${key}`] = JSON.stringify(value);
|
|
147
146
|
return defines;
|
|
148
147
|
}
|
|
149
|
-
async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName,
|
|
148
|
+
async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName, options) {
|
|
150
149
|
const versions = readProjectDependencyVersions(projectRoot);
|
|
150
|
+
const aliases = options.aliases ?? [];
|
|
151
|
+
const wrapper = `import mcp from ${JSON.stringify(mcpEntryAbs)};\nimport { createSupabaseHandler } from "@lovable.dev/mcp-js/stacks/supabase";\nDeno.serve(createSupabaseHandler(mcp, { functionName: ${JSON.stringify(functionName)} }));\n`;
|
|
152
|
+
const skillFiles = [];
|
|
153
|
+
const skillDirs = [];
|
|
151
154
|
const result = await (0, esbuild.build)({
|
|
152
155
|
stdin: {
|
|
153
|
-
contents:
|
|
156
|
+
contents: wrapper,
|
|
154
157
|
resolveDir: projectRoot,
|
|
155
158
|
sourcefile: "lovable-mcp-supabase-entry.ts",
|
|
156
159
|
loader: "ts"
|
|
@@ -163,18 +166,24 @@ async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName, inlin
|
|
|
163
166
|
target: "esnext",
|
|
164
167
|
absWorkingDir: projectRoot,
|
|
165
168
|
logLevel: "silent",
|
|
166
|
-
define: importMetaEnvDefines(inlineEnv),
|
|
169
|
+
define: importMetaEnvDefines(options.inlineEnv),
|
|
167
170
|
plugins: [
|
|
171
|
+
require_hooks.skillImportEsbuildPlugin((compilation) => {
|
|
172
|
+
skillFiles.push(...compilation.watchFiles);
|
|
173
|
+
skillDirs.push(...compilation.watchDirs);
|
|
174
|
+
console.info(compilation.report);
|
|
175
|
+
}, options.onSkillDirectory),
|
|
168
176
|
...aliases.length > 0 ? [resolveViteAliases(aliases)] : [],
|
|
169
177
|
rejectFrontendImages(projectRoot),
|
|
170
178
|
externalizeBareAsNpm(versions)
|
|
171
179
|
]
|
|
172
180
|
});
|
|
173
181
|
const out = result.outputFiles[0]?.text ?? "";
|
|
174
|
-
const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((p) => !p.startsWith("<") && !p.startsWith("npm:")).map((p) => (0, node_path.resolve)(projectRoot, p));
|
|
182
|
+
const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((p) => !p.startsWith("<") && !p.startsWith("npm:") && !require_hooks.isSkillImportInput(p)).map((p) => (0, node_path.resolve)(projectRoot, p)).concat(skillFiles);
|
|
175
183
|
return {
|
|
176
184
|
code: `${GENERATED_BANNER}\n// supabase function: ${functionName}\n// Bundled from ${(0, node_path.relative)(projectRoot, mcpEntryAbs).split(node_path.sep).join("/")} by @lovable.dev/mcp-js.\n` + out,
|
|
177
|
-
inputs
|
|
185
|
+
inputs,
|
|
186
|
+
skillDirs
|
|
178
187
|
};
|
|
179
188
|
}
|
|
180
189
|
function resolvePaths(options) {
|
|
@@ -213,13 +222,14 @@ async function syncSupabaseFunction(options) {
|
|
|
213
222
|
inputs: []
|
|
214
223
|
};
|
|
215
224
|
}
|
|
216
|
-
const { code, inputs } = await bundleFunctionEntry(projectRoot, paths.mcpEntryAbs, functionName, options
|
|
225
|
+
const { code, inputs, skillDirs } = await bundleFunctionEntry(projectRoot, paths.mcpEntryAbs, functionName, options);
|
|
217
226
|
if (writeIfChanged(paths.functionEntry, code, hasGeneratedBanner)) written.push(paths.functionEntry);
|
|
218
227
|
cleanupOrphans(paths.functionDir, /* @__PURE__ */ new Set([paths.functionEntry]), removed);
|
|
219
228
|
return {
|
|
220
229
|
written,
|
|
221
230
|
removed,
|
|
222
|
-
inputs
|
|
231
|
+
inputs,
|
|
232
|
+
skillDirs
|
|
223
233
|
};
|
|
224
234
|
}
|
|
225
235
|
function cleanupOrphans(functionDir, expected, removed) {
|
|
@@ -227,7 +237,7 @@ function cleanupOrphans(functionDir, expected, removed) {
|
|
|
227
237
|
try {
|
|
228
238
|
entries = (0, node_fs.readdirSync)(functionDir);
|
|
229
239
|
} catch (err) {
|
|
230
|
-
if (
|
|
240
|
+
if (require_hooks.isFileMissing(err)) return;
|
|
231
241
|
throw err;
|
|
232
242
|
}
|
|
233
243
|
for (const entry of entries) {
|
|
@@ -237,14 +247,14 @@ function cleanupOrphans(functionDir, expected, removed) {
|
|
|
237
247
|
try {
|
|
238
248
|
content = (0, node_fs.readFileSync)(full, "utf8");
|
|
239
249
|
} catch (err) {
|
|
240
|
-
if (
|
|
250
|
+
if (require_hooks.isFileMissing(err) || err.code === "EISDIR") continue;
|
|
241
251
|
throw err;
|
|
242
252
|
}
|
|
243
253
|
if (hasGeneratedBanner(content) || hasGeneratedJsonMarker(content)) try {
|
|
244
254
|
(0, node_fs.unlinkSync)(full);
|
|
245
255
|
removed.push(full);
|
|
246
256
|
} catch (err) {
|
|
247
|
-
if (!
|
|
257
|
+
if (!require_hooks.isFileMissing(err)) throw err;
|
|
248
258
|
}
|
|
249
259
|
}
|
|
250
260
|
}
|
|
@@ -263,7 +273,7 @@ function productionImportMetaEnv(config) {
|
|
|
263
273
|
SSR: false
|
|
264
274
|
};
|
|
265
275
|
if (!env.VITE_SUPABASE_PROJECT_ID) {
|
|
266
|
-
const ref =
|
|
276
|
+
const ref = require_hooks.readSupabaseProjectRef(config.root);
|
|
267
277
|
if (ref) env.VITE_SUPABASE_PROJECT_ID = ref;
|
|
268
278
|
}
|
|
269
279
|
return env;
|
|
@@ -301,16 +311,24 @@ function mcpPlugin(options = {}) {
|
|
|
301
311
|
let inlineEnv = {};
|
|
302
312
|
let aliases = [];
|
|
303
313
|
let watchedInputs = /* @__PURE__ */ new Set();
|
|
314
|
+
let watchedSkillDirs = [];
|
|
315
|
+
let devServer;
|
|
304
316
|
const regenerate = async () => {
|
|
305
|
-
const { inputs } = await syncSupabaseFunction({
|
|
317
|
+
const { inputs, skillDirs } = await syncSupabaseFunction({
|
|
306
318
|
projectRoot,
|
|
307
319
|
mcpEntry: mcpEntryOption,
|
|
308
320
|
functionsDir: functionsDirOption,
|
|
309
321
|
functionName,
|
|
310
322
|
inlineEnv,
|
|
311
|
-
aliases
|
|
323
|
+
aliases,
|
|
324
|
+
onSkillDirectory(directory) {
|
|
325
|
+
const normalized = normalizePath(directory);
|
|
326
|
+
if (!watchedSkillDirs.includes(normalized)) watchedSkillDirs.push(normalized);
|
|
327
|
+
devServer?.watcher.add(directory);
|
|
328
|
+
}
|
|
312
329
|
});
|
|
313
330
|
watchedInputs = new Set(inputs.map(normalizePath));
|
|
331
|
+
watchedSkillDirs = (skillDirs ?? []).map(normalizePath);
|
|
314
332
|
};
|
|
315
333
|
return {
|
|
316
334
|
name: "@lovable.dev/mcp-js/supabase",
|
|
@@ -331,9 +349,12 @@ function mcpPlugin(options = {}) {
|
|
|
331
349
|
await regenerate();
|
|
332
350
|
},
|
|
333
351
|
configureServer(server) {
|
|
352
|
+
devServer = server;
|
|
353
|
+
server.watcher.add(watchedSkillDirs);
|
|
334
354
|
const onChange = (file) => {
|
|
335
355
|
const norm = normalizePath(file);
|
|
336
|
-
|
|
356
|
+
const inSkillDir = watchedSkillDirs.some((dir) => norm.startsWith(`${dir}/`));
|
|
357
|
+
if (norm !== normalizePath(mcpEntryAbs) && !watchedInputs.has(norm) && !inSkillDir) return;
|
|
337
358
|
regenerate().catch((err) => {
|
|
338
359
|
const message = `[@lovable.dev/mcp-js] failed to regenerate the Supabase function: ${err instanceof Error ? err.message : String(err)}`;
|
|
339
360
|
if (server.config?.logger?.error) server.config.logger.error(message);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as version } from "../../package-
|
|
2
|
-
import {
|
|
3
|
-
import { t as readSupabaseProjectRef } from "../../supabase-config-CakTU8YF.js";
|
|
1
|
+
import { t as version } from "../../package-Ci4yKJUI.js";
|
|
2
|
+
import { a as isFileMissing, i as readSupabaseProjectRef, n as skillImportEsbuildPlugin, t as isSkillImportInput } from "../../hooks-BOdDe251.js";
|
|
4
3
|
import { n as assertFunctionName, t as FUNCTIONS_MOUNT_PREFIX } from "../../paths-IS65L6TA.js";
|
|
5
4
|
import { lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
5
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
@@ -142,11 +141,15 @@ function importMetaEnvDefines(inlineEnv) {
|
|
|
142
141
|
for (const [key, value] of Object.entries(env)) if (/^[A-Za-z_$][\w$]*$/.test(key)) defines[`import.meta.env.${key}`] = JSON.stringify(value);
|
|
143
142
|
return defines;
|
|
144
143
|
}
|
|
145
|
-
async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName,
|
|
144
|
+
async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName, options) {
|
|
146
145
|
const versions = readProjectDependencyVersions(projectRoot);
|
|
146
|
+
const aliases = options.aliases ?? [];
|
|
147
|
+
const wrapper = `import mcp from ${JSON.stringify(mcpEntryAbs)};\nimport { createSupabaseHandler } from "@lovable.dev/mcp-js/stacks/supabase";\nDeno.serve(createSupabaseHandler(mcp, { functionName: ${JSON.stringify(functionName)} }));\n`;
|
|
148
|
+
const skillFiles = [];
|
|
149
|
+
const skillDirs = [];
|
|
147
150
|
const result = await build({
|
|
148
151
|
stdin: {
|
|
149
|
-
contents:
|
|
152
|
+
contents: wrapper,
|
|
150
153
|
resolveDir: projectRoot,
|
|
151
154
|
sourcefile: "lovable-mcp-supabase-entry.ts",
|
|
152
155
|
loader: "ts"
|
|
@@ -159,18 +162,24 @@ async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName, inlin
|
|
|
159
162
|
target: "esnext",
|
|
160
163
|
absWorkingDir: projectRoot,
|
|
161
164
|
logLevel: "silent",
|
|
162
|
-
define: importMetaEnvDefines(inlineEnv),
|
|
165
|
+
define: importMetaEnvDefines(options.inlineEnv),
|
|
163
166
|
plugins: [
|
|
167
|
+
skillImportEsbuildPlugin((compilation) => {
|
|
168
|
+
skillFiles.push(...compilation.watchFiles);
|
|
169
|
+
skillDirs.push(...compilation.watchDirs);
|
|
170
|
+
console.info(compilation.report);
|
|
171
|
+
}, options.onSkillDirectory),
|
|
164
172
|
...aliases.length > 0 ? [resolveViteAliases(aliases)] : [],
|
|
165
173
|
rejectFrontendImages(projectRoot),
|
|
166
174
|
externalizeBareAsNpm(versions)
|
|
167
175
|
]
|
|
168
176
|
});
|
|
169
177
|
const out = result.outputFiles[0]?.text ?? "";
|
|
170
|
-
const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((p) => !p.startsWith("<") && !p.startsWith("npm:")).map((p) => resolve(projectRoot, p));
|
|
178
|
+
const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((p) => !p.startsWith("<") && !p.startsWith("npm:") && !isSkillImportInput(p)).map((p) => resolve(projectRoot, p)).concat(skillFiles);
|
|
171
179
|
return {
|
|
172
180
|
code: `${GENERATED_BANNER}\n// supabase function: ${functionName}\n// Bundled from ${relative(projectRoot, mcpEntryAbs).split(sep).join("/")} by @lovable.dev/mcp-js.\n` + out,
|
|
173
|
-
inputs
|
|
181
|
+
inputs,
|
|
182
|
+
skillDirs
|
|
174
183
|
};
|
|
175
184
|
}
|
|
176
185
|
function resolvePaths(options) {
|
|
@@ -209,13 +218,14 @@ async function syncSupabaseFunction(options) {
|
|
|
209
218
|
inputs: []
|
|
210
219
|
};
|
|
211
220
|
}
|
|
212
|
-
const { code, inputs } = await bundleFunctionEntry(projectRoot, paths.mcpEntryAbs, functionName, options
|
|
221
|
+
const { code, inputs, skillDirs } = await bundleFunctionEntry(projectRoot, paths.mcpEntryAbs, functionName, options);
|
|
213
222
|
if (writeIfChanged(paths.functionEntry, code, hasGeneratedBanner)) written.push(paths.functionEntry);
|
|
214
223
|
cleanupOrphans(paths.functionDir, /* @__PURE__ */ new Set([paths.functionEntry]), removed);
|
|
215
224
|
return {
|
|
216
225
|
written,
|
|
217
226
|
removed,
|
|
218
|
-
inputs
|
|
227
|
+
inputs,
|
|
228
|
+
skillDirs
|
|
219
229
|
};
|
|
220
230
|
}
|
|
221
231
|
function cleanupOrphans(functionDir, expected, removed) {
|
|
@@ -297,16 +307,24 @@ function mcpPlugin(options = {}) {
|
|
|
297
307
|
let inlineEnv = {};
|
|
298
308
|
let aliases = [];
|
|
299
309
|
let watchedInputs = /* @__PURE__ */ new Set();
|
|
310
|
+
let watchedSkillDirs = [];
|
|
311
|
+
let devServer;
|
|
300
312
|
const regenerate = async () => {
|
|
301
|
-
const { inputs } = await syncSupabaseFunction({
|
|
313
|
+
const { inputs, skillDirs } = await syncSupabaseFunction({
|
|
302
314
|
projectRoot,
|
|
303
315
|
mcpEntry: mcpEntryOption,
|
|
304
316
|
functionsDir: functionsDirOption,
|
|
305
317
|
functionName,
|
|
306
318
|
inlineEnv,
|
|
307
|
-
aliases
|
|
319
|
+
aliases,
|
|
320
|
+
onSkillDirectory(directory) {
|
|
321
|
+
const normalized = normalizePath(directory);
|
|
322
|
+
if (!watchedSkillDirs.includes(normalized)) watchedSkillDirs.push(normalized);
|
|
323
|
+
devServer?.watcher.add(directory);
|
|
324
|
+
}
|
|
308
325
|
});
|
|
309
326
|
watchedInputs = new Set(inputs.map(normalizePath));
|
|
327
|
+
watchedSkillDirs = (skillDirs ?? []).map(normalizePath);
|
|
310
328
|
};
|
|
311
329
|
return {
|
|
312
330
|
name: "@lovable.dev/mcp-js/supabase",
|
|
@@ -327,9 +345,12 @@ function mcpPlugin(options = {}) {
|
|
|
327
345
|
await regenerate();
|
|
328
346
|
},
|
|
329
347
|
configureServer(server) {
|
|
348
|
+
devServer = server;
|
|
349
|
+
server.watcher.add(watchedSkillDirs);
|
|
330
350
|
const onChange = (file) => {
|
|
331
351
|
const norm = normalizePath(file);
|
|
332
|
-
|
|
352
|
+
const inSkillDir = watchedSkillDirs.some((dir) => norm.startsWith(`${dir}/`));
|
|
353
|
+
if (norm !== normalizePath(mcpEntryAbs) && !watchedInputs.has(norm) && !inSkillDir) return;
|
|
333
354
|
regenerate().catch((err) => {
|
|
334
355
|
const message = `[@lovable.dev/mcp-js] failed to regenerate the Supabase function: ${err instanceof Error ? err.message : String(err)}`;
|
|
335
356
|
if (server.config?.logger?.error) server.config.logger.error(message);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_cors = require("../../cors-
|
|
3
|
-
const require_mcp = require("../../mcp-
|
|
2
|
+
const require_cors = require("../../cors-Ct-kdMcl.cjs");
|
|
3
|
+
const require_mcp = require("../../mcp-By6C2M4i.cjs");
|
|
4
4
|
const require_protocols_oauth_metadata = require("../../protocols/oauth-metadata.cjs");
|
|
5
5
|
const require_forwarded = require("../../forwarded-B37IdmMX.cjs");
|
|
6
6
|
//#region src/stacks/tanstack/handlers.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { m as McpDefinition } from "../../types-
|
|
2
|
-
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-
|
|
1
|
+
import { m as McpDefinition } from "../../types-CyDJi9Jb.cjs";
|
|
2
|
+
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-BZdUmD37.cjs";
|
|
3
3
|
//#region src/stacks/tanstack/handlers.d.ts
|
|
4
4
|
interface TanStackRequest extends Request {
|
|
5
5
|
waitUntil?: ScheduleBackground;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { m as McpDefinition } from "../../types-
|
|
2
|
-
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-
|
|
1
|
+
import { m as McpDefinition } from "../../types-CyDJi9Jb.js";
|
|
2
|
+
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-8crkySbp.js";
|
|
3
3
|
//#region src/stacks/tanstack/handlers.d.ts
|
|
4
4
|
interface TanStackRequest extends Request {
|
|
5
5
|
waitUntil?: ScheduleBackground;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as createRecorderForRuntime } from "../../cors-
|
|
2
|
-
import { t as createMcpProtocolHandler } from "../../mcp-
|
|
1
|
+
import { c as createRecorderForRuntime } from "../../cors-Ct8SFh-_.js";
|
|
2
|
+
import { t as createMcpProtocolHandler } from "../../mcp-DWxIy07i.js";
|
|
3
3
|
import { createOAuthProtectedResourceMetadataHandler } from "../../protocols/oauth-metadata.js";
|
|
4
4
|
import { t as applyForwardedOrigin } from "../../forwarded-BBXvFeh6.js";
|
|
5
5
|
//#region src/stacks/tanstack/handlers.ts
|
|
@@ -3,8 +3,7 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
require("../../metadata-path-zd7NSNoa.cjs");
|
|
6
|
-
const
|
|
7
|
-
const require_supabase_config = require("../../supabase-config-Dz7dnUv0.cjs");
|
|
6
|
+
const require_hooks = require("../../hooks-xQl3EkDa.cjs");
|
|
8
7
|
let node_fs = require("node:fs");
|
|
9
8
|
let node_path = require("node:path");
|
|
10
9
|
let vite = require("vite");
|
|
@@ -64,7 +63,7 @@ function relativeImportSpecifier(routeFile, target) {
|
|
|
64
63
|
const withoutExt = normalizePath((0, node_path.relative)((0, node_path.dirname)(routeFile), target)).replace(/\.ts$/, "");
|
|
65
64
|
return withoutExt.startsWith(".") ? withoutExt : `./${withoutExt}`;
|
|
66
65
|
}
|
|
67
|
-
function buildRouteSource(route, resourcePath, metadataPath, trustForwardedHost, trustForwardedProto, mcpEntry, projectRoot) {
|
|
66
|
+
function buildRouteSource(route, resourcePath, metadataPath, trustForwardedHost, trustForwardedProto, mcpEntry, projectRoot, hasSitemapInventory) {
|
|
68
67
|
const mcpImport = relativeImportSpecifier(route.file, mcpEntry);
|
|
69
68
|
const routeRel = normalizePath((0, node_path.relative)(projectRoot, route.file));
|
|
70
69
|
const optionEntries = [`resourcePath: "${resourcePath}"`];
|
|
@@ -88,7 +87,7 @@ import { ${route.handlerFactory} } from "@lovable.dev/mcp-js/stacks/tanstack";
|
|
|
88
87
|
import mcp from "${mcpImport}";
|
|
89
88
|
|
|
90
89
|
${routeOpen}
|
|
91
|
-
server: {
|
|
90
|
+
${hasSitemapInventory ? " staticData: { sitemap: false },\n" : ""} server: {
|
|
92
91
|
handlers: {
|
|
93
92
|
ANY: ${route.handlerFactory}(mcp, ${optionsObject}),
|
|
94
93
|
},
|
|
@@ -108,7 +107,7 @@ function writeIfChanged(file, content) {
|
|
|
108
107
|
try {
|
|
109
108
|
existing = (0, node_fs.readFileSync)(file, "utf8");
|
|
110
109
|
} catch (err) {
|
|
111
|
-
if (!
|
|
110
|
+
if (!require_hooks.isFileMissing(err)) throw err;
|
|
112
111
|
}
|
|
113
112
|
if (existing !== void 0) {
|
|
114
113
|
if (!hasGeneratedBanner(existing)) throw new Error(`@lovable.dev/mcp-js: refusing to overwrite user-authored route at ${file}. Delete it or move it first.`);
|
|
@@ -122,7 +121,7 @@ function fileStartsWithBanner(file) {
|
|
|
122
121
|
try {
|
|
123
122
|
return hasGeneratedBanner((0, node_fs.readFileSync)(file, "utf8"));
|
|
124
123
|
} catch (err) {
|
|
125
|
-
if (
|
|
124
|
+
if (require_hooks.isFileMissing(err)) return false;
|
|
126
125
|
throw err;
|
|
127
126
|
}
|
|
128
127
|
}
|
|
@@ -133,7 +132,7 @@ function findAdoptedFiles(routesDir) {
|
|
|
133
132
|
try {
|
|
134
133
|
entries = (0, node_fs.readdirSync)(dir);
|
|
135
134
|
} catch (err) {
|
|
136
|
-
if (
|
|
135
|
+
if (require_hooks.isFileMissing(err)) return;
|
|
137
136
|
throw err;
|
|
138
137
|
}
|
|
139
138
|
for (const entry of entries) {
|
|
@@ -142,7 +141,7 @@ function findAdoptedFiles(routesDir) {
|
|
|
142
141
|
try {
|
|
143
142
|
stat = (0, node_fs.lstatSync)(full);
|
|
144
143
|
} catch (err) {
|
|
145
|
-
if (
|
|
144
|
+
if (require_hooks.isFileMissing(err)) continue;
|
|
146
145
|
throw err;
|
|
147
146
|
}
|
|
148
147
|
if (stat.isDirectory()) visit(full);
|
|
@@ -182,17 +181,25 @@ function mcpPlugin(options = {}) {
|
|
|
182
181
|
const trustForwardedProto = options.trustForwardedProto !== false;
|
|
183
182
|
let projectRoot = process.cwd();
|
|
184
183
|
let mcpEntry = (0, node_path.resolve)(projectRoot, mcpEntryOption);
|
|
184
|
+
let sitemapFile = (0, node_path.resolve)(projectRoot, "src/lib/sitemap.ts");
|
|
185
185
|
let { routesDir, mcpRouteFile, metadataRouteFile } = resolveAllRoutes(projectRoot, routesDirOption, routeFileName, metadataUrlPath);
|
|
186
186
|
const regenerate = () => {
|
|
187
187
|
let mcpEntryExists = true;
|
|
188
188
|
try {
|
|
189
189
|
(0, node_fs.lstatSync)(mcpEntry);
|
|
190
190
|
} catch (err) {
|
|
191
|
-
if (!
|
|
191
|
+
if (!require_hooks.isFileMissing(err)) throw err;
|
|
192
192
|
mcpEntryExists = false;
|
|
193
193
|
}
|
|
194
194
|
const expected = /* @__PURE__ */ new Set();
|
|
195
195
|
if (mcpEntryExists) {
|
|
196
|
+
let sitemapSource = "";
|
|
197
|
+
try {
|
|
198
|
+
sitemapSource = (0, node_fs.readFileSync)(sitemapFile, "utf8");
|
|
199
|
+
} catch (err) {
|
|
200
|
+
if (!require_hooks.isFileMissing(err)) throw err;
|
|
201
|
+
}
|
|
202
|
+
const hasSitemapInventory = /^\s*export\s+const\s+sitemapRouteInventoryVersion\s*=\s*1\s*(?:;|$)/m.test(sitemapSource);
|
|
196
203
|
const routes = [{
|
|
197
204
|
file: mcpRouteFile,
|
|
198
205
|
routeLiteral: urlPath,
|
|
@@ -206,16 +213,29 @@ function mcpPlugin(options = {}) {
|
|
|
206
213
|
});
|
|
207
214
|
for (const route of routes) {
|
|
208
215
|
expected.add(route.file);
|
|
209
|
-
writeIfChanged(route.file, buildRouteSource(route, urlPath, injectedMetadataPath, trustForwardedHost, trustForwardedProto, mcpEntry, projectRoot));
|
|
216
|
+
writeIfChanged(route.file, buildRouteSource(route, urlPath, injectedMetadataPath, trustForwardedHost, trustForwardedProto, mcpEntry, projectRoot, hasSitemapInventory));
|
|
210
217
|
}
|
|
211
218
|
}
|
|
212
219
|
for (const file of findAdoptedFiles(routesDir)) if (!expected.has(file)) try {
|
|
213
220
|
(0, node_fs.unlinkSync)(file);
|
|
214
221
|
} catch (err) {
|
|
215
|
-
if (!
|
|
222
|
+
if (!require_hooks.isFileMissing(err)) throw err;
|
|
216
223
|
}
|
|
217
224
|
};
|
|
218
225
|
return {
|
|
226
|
+
...require_hooks.skillImportVitePlugin({ onServer(server) {
|
|
227
|
+
const onChange = (file) => {
|
|
228
|
+
if (normalizePath(file) === normalizePath(mcpEntry) || normalizePath(file) === normalizePath(sitemapFile)) regenerate();
|
|
229
|
+
};
|
|
230
|
+
server.watcher.on("add", onChange);
|
|
231
|
+
server.watcher.on("change", onChange);
|
|
232
|
+
server.watcher.on("unlink", onChange);
|
|
233
|
+
server.watcher.once("close", () => {
|
|
234
|
+
server.watcher.off("add", onChange);
|
|
235
|
+
server.watcher.off("change", onChange);
|
|
236
|
+
server.watcher.off("unlink", onChange);
|
|
237
|
+
});
|
|
238
|
+
} }),
|
|
219
239
|
name: "@lovable.dev/mcp-js",
|
|
220
240
|
api: {
|
|
221
241
|
get mcpEntry() {
|
|
@@ -228,29 +248,17 @@ function mcpPlugin(options = {}) {
|
|
|
228
248
|
config(userConfig, { mode }) {
|
|
229
249
|
const root = userConfig.root ? (0, node_path.resolve)(userConfig.root) : process.cwd();
|
|
230
250
|
if ((0, vite.loadEnv)(mode, typeof userConfig.envDir === "string" ? (0, node_path.resolve)(root, userConfig.envDir) : root, userConfig.envPrefix ?? "VITE_")[SUPABASE_PROJECT_REF_ENV]) return;
|
|
231
|
-
const ref =
|
|
251
|
+
const ref = require_hooks.readSupabaseProjectRef(root);
|
|
232
252
|
if (!ref) return;
|
|
233
253
|
return { define: { [`import.meta.env.${SUPABASE_PROJECT_REF_ENV}`]: JSON.stringify(ref) } };
|
|
234
254
|
},
|
|
235
255
|
configResolved(config) {
|
|
236
256
|
projectRoot = config.root;
|
|
237
257
|
mcpEntry = (0, node_path.resolve)(projectRoot, mcpEntryOption);
|
|
258
|
+
sitemapFile = (0, node_path.resolve)(projectRoot, "src/lib/sitemap.ts");
|
|
238
259
|
({routesDir, mcpRouteFile, metadataRouteFile} = resolveAllRoutes(projectRoot, routesDirOption, routeFileName, metadataUrlPath));
|
|
239
260
|
regenerate();
|
|
240
261
|
},
|
|
241
|
-
configureServer(server) {
|
|
242
|
-
const onChange = (file) => {
|
|
243
|
-
if (normalizePath(file) === normalizePath(mcpEntry)) regenerate();
|
|
244
|
-
};
|
|
245
|
-
server.watcher.on("add", onChange);
|
|
246
|
-
server.watcher.on("change", onChange);
|
|
247
|
-
server.watcher.on("unlink", onChange);
|
|
248
|
-
server.watcher.once("close", () => {
|
|
249
|
-
server.watcher.off("add", onChange);
|
|
250
|
-
server.watcher.off("change", onChange);
|
|
251
|
-
server.watcher.off("unlink", onChange);
|
|
252
|
-
});
|
|
253
|
-
},
|
|
254
262
|
buildStart() {
|
|
255
263
|
regenerate();
|
|
256
264
|
}
|