@lovable.dev/mcp-js 0.21.1-rc.1 → 0.22.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.
Files changed (87) hide show
  1. package/dist/authorize-BMeXd_Sh.d.ts +25 -0
  2. package/dist/base-CM-KCpp6.d.ts +28 -0
  3. package/dist/chunk-4EHZUUS5.js +141 -0
  4. package/dist/chunk-6DXGZZA4.js +6 -0
  5. package/dist/chunk-6KNM7RGD.js +79 -0
  6. package/dist/chunk-6QFZYYUV.js +11 -0
  7. package/dist/chunk-EOFPMSND.js +6 -0
  8. package/dist/chunk-H37EB22A.js +125 -0
  9. package/dist/chunk-MA5H6PSF.js +46 -0
  10. package/dist/chunk-P43FIUMZ.js +114 -0
  11. package/dist/chunk-RK62EMPY.js +741 -0
  12. package/dist/chunk-RLE4UE63.js +58 -0
  13. package/dist/chunk-UQK5UO6C.js +26 -0
  14. package/dist/chunk-XQWJN6DC.js +14 -0
  15. package/dist/chunk-Y3ZFPEQH.js +8 -0
  16. package/dist/cli/extract-manifest.cjs +201 -116
  17. package/dist/cli/extract-manifest.d.cts +1 -1
  18. package/dist/cli/extract-manifest.d.ts +1 -1
  19. package/dist/cli/extract-manifest.js +156 -117
  20. package/dist/index.cjs +329 -129
  21. package/dist/index.d.cts +26 -26
  22. package/dist/index.d.ts +26 -26
  23. package/dist/index.js +177 -118
  24. package/dist/{io-CS4UL6_A.d.ts → io-D4srzRKc.d.ts} +4 -6
  25. package/dist/protocols/mcp/index.cjs +750 -3
  26. package/dist/protocols/mcp/index.d.cts +7 -6
  27. package/dist/protocols/mcp/index.d.ts +7 -6
  28. package/dist/protocols/mcp/index.js +12 -2
  29. package/dist/protocols/oauth-metadata.cjs +539 -48
  30. package/dist/protocols/oauth-metadata.d.cts +6 -5
  31. package/dist/protocols/oauth-metadata.d.ts +6 -5
  32. package/dist/protocols/oauth-metadata.js +10 -52
  33. package/dist/protocols/rest/index.cjs +843 -5
  34. package/dist/protocols/rest/index.d.cts +10 -7
  35. package/dist/protocols/rest/index.d.ts +10 -7
  36. package/dist/protocols/rest/index.js +16 -3
  37. package/dist/stacks/supabase/index.cjs +1318 -76
  38. package/dist/stacks/supabase/index.d.cts +30 -29
  39. package/dist/stacks/supabase/index.d.ts +30 -29
  40. package/dist/stacks/supabase/index.js +89 -73
  41. package/dist/stacks/supabase/vite.cjs +287 -258
  42. package/dist/stacks/supabase/vite.d.cts +24 -24
  43. package/dist/stacks/supabase/vite.d.ts +24 -24
  44. package/dist/stacks/supabase/vite.js +252 -252
  45. package/dist/stacks/tanstack/index.cjs +1272 -42
  46. package/dist/stacks/tanstack/index.d.cts +9 -8
  47. package/dist/stacks/tanstack/index.d.ts +9 -8
  48. package/dist/stacks/tanstack/index.js +41 -36
  49. package/dist/stacks/tanstack/vite.cjs +312 -223
  50. package/dist/stacks/tanstack/vite.d.cts +81 -80
  51. package/dist/stacks/tanstack/vite.d.ts +81 -80
  52. package/dist/stacks/tanstack/vite.js +282 -216
  53. package/dist/types-qqrmJ736.d.ts +321 -0
  54. package/package.json +28 -71
  55. package/dist/authorize-CumVyk7p.d.cts +0 -27
  56. package/dist/authorize-D6p4-9_D.d.ts +0 -27
  57. package/dist/base-CoIFvAmS.d.cts +0 -26
  58. package/dist/base-CoIFvAmS.d.ts +0 -26
  59. package/dist/content-D5LJAHyM.js +0 -12
  60. package/dist/content-NCYIGgOb.cjs +0 -17
  61. package/dist/context-BweeEcoA.cjs +0 -56
  62. package/dist/context-CIpPzN7P.js +0 -51
  63. package/dist/cors-B7CTXIHD.js +0 -829
  64. package/dist/cors-BebjKPrc.cjs +0 -912
  65. package/dist/forwarded--h4efJy-.js +0 -43
  66. package/dist/forwarded-Pi8Hs5Ps.cjs +0 -48
  67. package/dist/fs-errors-CWNzOV75.cjs +0 -11
  68. package/dist/fs-errors-PA2t1TIp.js +0 -6
  69. package/dist/io-CbbUbPY3.d.cts +0 -15
  70. package/dist/list-tools-CBCuS1Tv.cjs +0 -57
  71. package/dist/list-tools-CsWgiRy1.d.ts +0 -8
  72. package/dist/list-tools-CtZHOuPv.d.cts +0 -8
  73. package/dist/list-tools-D75RGtgs.js +0 -46
  74. package/dist/logger-2OXtfiIW.js +0 -141
  75. package/dist/logger-BqPOa_E1.cjs +0 -194
  76. package/dist/mcp-Cdj0AYst.cjs +0 -123
  77. package/dist/mcp-GngXbcqN.js +0 -118
  78. package/dist/metadata-path-CAkNcfyY.js +0 -12
  79. package/dist/metadata-path-zd7NSNoa.cjs +0 -17
  80. package/dist/package-7EUptuSJ.js +0 -4
  81. package/dist/package-BwCGVRcB.cjs +0 -9
  82. package/dist/paths-IS65L6TA.js +0 -7
  83. package/dist/paths-OP318a6c.cjs +0 -18
  84. package/dist/rest-CXH6-zv9.js +0 -113
  85. package/dist/rest-CyV8LHeB.cjs +0 -118
  86. package/dist/types-BYdYYTjk.d.cts +0 -321
  87. package/dist/types-BYdYYTjk.d.ts +0 -321
@@ -1,26 +1,26 @@
1
- import { t as McpPluginApi } from "../../io-CS4UL6_A.js";
2
- import { Plugin } from "vite";
3
- //#region src/stacks/supabase/vite.d.ts
1
+ import { Plugin } from 'vite';
2
+ export { M as McpPluginApi } from '../../io-D4srzRKc.js';
3
+
4
4
  interface McpPluginOptions {
5
- /**
6
- * Path to the MCP entry file (default export = `defineMcp(...)` result),
7
- * relative to the project root.
8
- * @default "src/lib/mcp/index.ts"
9
- */
10
- mcpEntry?: string;
11
- /**
12
- * Directory holding Supabase function folders (one per function), relative
13
- * to the project root.
14
- * @default "supabase/functions"
15
- */
16
- functionsDir?: string;
17
- /**
18
- * Name of the function directory under `functionsDir`. Becomes the public
19
- * URL segment (`/functions/v1/<functionName>`) the dispatcher binds OAuth
20
- * metadata to via `resourcePath`.
21
- * @default "mcp"
22
- */
23
- functionName?: string;
5
+ /**
6
+ * Path to the MCP entry file (default export = `defineMcp(...)` result),
7
+ * relative to the project root.
8
+ * @default "src/lib/mcp/index.ts"
9
+ */
10
+ mcpEntry?: string;
11
+ /**
12
+ * Directory holding Supabase function folders (one per function), relative
13
+ * to the project root.
14
+ * @default "supabase/functions"
15
+ */
16
+ functionsDir?: string;
17
+ /**
18
+ * Name of the function directory under `functionsDir`. Becomes the public
19
+ * URL segment (`/functions/v1/<functionName>`) the dispatcher binds OAuth
20
+ * metadata to via `resourcePath`.
21
+ * @default "mcp"
22
+ */
23
+ functionName?: string;
24
24
  }
25
25
  /**
26
26
  * Vite plugin that emits the Supabase Edge Function entry (and its
@@ -46,5 +46,5 @@ interface McpPluginOptions {
46
46
  * cleans up SDK-owned files when the entry is deleted.
47
47
  */
48
48
  declare function mcpPlugin(options?: McpPluginOptions): Plugin;
49
- //#endregion
50
- export { type McpPluginApi, McpPluginOptions, mcpPlugin as default, mcpPlugin };
49
+
50
+ export { type McpPluginOptions, mcpPlugin as default, mcpPlugin };
@@ -1,284 +1,284 @@
1
- import { t as version } from "../../package-7EUptuSJ.js";
2
- import { t as isFileMissing } from "../../fs-errors-PA2t1TIp.js";
3
- import { n as assertFunctionName, t as FUNCTIONS_MOUNT_PREFIX } from "../../paths-IS65L6TA.js";
4
- import { lstatSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
5
- import { dirname, join, relative, resolve, sep } from "node:path";
1
+ import {
2
+ isFileMissing
3
+ } from "../../chunk-Y3ZFPEQH.js";
4
+ import {
5
+ FUNCTIONS_MOUNT_PREFIX,
6
+ assertFunctionName
7
+ } from "../../chunk-XQWJN6DC.js";
8
+ import {
9
+ version
10
+ } from "../../chunk-EOFPMSND.js";
11
+
12
+ // src/stacks/supabase/vite.ts
13
+ import { resolve as resolve2, sep as sep2 } from "path";
6
14
  import { loadEnv } from "vite";
15
+
16
+ // src/stacks/supabase/emit.ts
7
17
  import { build } from "esbuild";
8
- const GENERATED_BANNER = "// AUTO-GENERATED by @lovable.dev/mcp-js — do not edit. Regenerated by the Vite plugin.\n// To take ownership, delete this banner line; the plugin then leaves the file alone.";
9
- const GENERATED_JSON_MARKER_KEY = "_lovableMcpGenerated";
18
+ import { lstatSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "fs";
19
+ import { dirname, join, relative, resolve, sep } from "path";
20
+ var DEFAULT_MCP_ENTRY = "src/lib/mcp/index.ts";
21
+ var DEFAULT_FUNCTIONS_DIR = "supabase/functions";
22
+ var DEFAULT_FUNCTION_NAME = "mcp";
23
+ var GENERATED_BANNER = "// AUTO-GENERATED by @lovable.dev/mcp-js \u2014 do not edit. Regenerated by the Vite plugin.\n// To take ownership, delete this banner line; the plugin then leaves the file alone.";
24
+ var GENERATED_JSON_MARKER_KEY = "_lovableMcpGenerated";
10
25
  function fileExists(path) {
11
- try {
12
- lstatSync(path);
13
- return true;
14
- } catch (err) {
15
- if (isFileMissing(err)) return false;
16
- throw err;
17
- }
26
+ try {
27
+ lstatSync(path);
28
+ return true;
29
+ } catch (err) {
30
+ if (isFileMissing(err))
31
+ return false;
32
+ throw err;
33
+ }
18
34
  }
19
35
  function hasGeneratedBanner(content) {
20
- return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
36
+ return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
21
37
  }
22
38
  function hasGeneratedJsonMarker(content) {
23
- try {
24
- const parsed = JSON.parse(content);
25
- return typeof parsed === "object" && parsed !== null && GENERATED_JSON_MARKER_KEY in parsed;
26
- } catch {
27
- return false;
28
- }
39
+ try {
40
+ const parsed = JSON.parse(content);
41
+ return typeof parsed === "object" && parsed !== null && GENERATED_JSON_MARKER_KEY in parsed;
42
+ } catch {
43
+ return false;
44
+ }
29
45
  }
30
46
  function writeIfChanged(file, content, ownershipCheck) {
31
- let existing;
32
- try {
33
- existing = readFileSync(file, "utf8");
34
- } catch (err) {
35
- if (!isFileMissing(err)) throw err;
36
- }
37
- if (existing !== void 0) {
38
- if (!ownershipCheck(existing)) throw new Error(`@lovable.dev/mcp-js: refusing to overwrite user-authored file at ${file}. Delete it or move it first.`);
39
- if (existing === content) return false;
40
- }
41
- mkdirSync(dirname(file), { recursive: true });
42
- writeFileSync(file, content, "utf8");
43
- return true;
47
+ let existing;
48
+ try {
49
+ existing = readFileSync(file, "utf8");
50
+ } catch (err) {
51
+ if (!isFileMissing(err))
52
+ throw err;
53
+ }
54
+ if (existing !== void 0) {
55
+ if (!ownershipCheck(existing)) {
56
+ throw new Error(
57
+ `@lovable.dev/mcp-js: refusing to overwrite user-authored file at ${file}. Delete it or move it first.`
58
+ );
59
+ }
60
+ if (existing === content)
61
+ return false;
62
+ }
63
+ mkdirSync(dirname(file), { recursive: true });
64
+ writeFileSync(file, content, "utf8");
65
+ return true;
44
66
  }
45
67
  function readProjectDependencyVersions(projectRoot) {
46
- try {
47
- const pkg = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf8"));
48
- return {
49
- ...pkg.peerDependencies,
50
- ...pkg.devDependencies,
51
- ...pkg.dependencies
52
- };
53
- } catch {
54
- return {};
55
- }
68
+ try {
69
+ const pkg = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf8"));
70
+ return { ...pkg.peerDependencies, ...pkg.devDependencies, ...pkg.dependencies };
71
+ } catch {
72
+ return {};
73
+ }
56
74
  }
57
75
  function npmSpecifierFor(bare, versions) {
58
- const pkg = bare.startsWith("@") ? bare.split("/").slice(0, 2).join("/") : bare.split("/")[0];
59
- const subpath = bare.slice(pkg.length);
60
- if (pkg === "@lovable.dev/mcp-js") return `npm:${pkg}@${version}${subpath}`;
61
- const range = versions[pkg];
62
- const version$1 = range && /^[\dv^~>=]|^latest$/.test(range) ? range : void 0;
63
- return version$1 ? `npm:${pkg}@${version$1}${subpath}` : `npm:${pkg}${subpath}`;
76
+ const pkg = bare.startsWith("@") ? bare.split("/").slice(0, 2).join("/") : bare.split("/")[0];
77
+ const subpath = bare.slice(pkg.length);
78
+ if (pkg === "@lovable.dev/mcp-js")
79
+ return `npm:${pkg}@${version}${subpath}`;
80
+ const range = versions[pkg];
81
+ const version2 = range && /^[\dv^~>=]|^latest$/.test(range) ? range : void 0;
82
+ return version2 ? `npm:${pkg}@${version2}${subpath}` : `npm:${pkg}${subpath}`;
64
83
  }
65
84
  function externalizeBareAsNpm(versions) {
66
- return {
67
- name: "lovable-mcp-externalize-bare-as-npm",
68
- setup(pluginBuild) {
69
- pluginBuild.onResolve({ filter: /.*/ }, (args) => {
70
- const p = args.path;
71
- if (p.startsWith(".") || p.startsWith("/")) return null;
72
- if (/^(npm|node|jsr|https?|data):/.test(p)) return {
73
- path: p,
74
- external: true
75
- };
76
- return {
77
- path: npmSpecifierFor(p, versions),
78
- external: true
79
- };
80
- });
81
- }
82
- };
85
+ return {
86
+ name: "lovable-mcp-externalize-bare-as-npm",
87
+ setup(pluginBuild) {
88
+ pluginBuild.onResolve({ filter: /.*/ }, (args) => {
89
+ const p = args.path;
90
+ if (p.startsWith(".") || p.startsWith("/"))
91
+ return null;
92
+ if (/^(npm|node|jsr|https?|data):/.test(p))
93
+ return { path: p, external: true };
94
+ return { path: npmSpecifierFor(p, versions), external: true };
95
+ });
96
+ }
97
+ };
83
98
  }
84
99
  function importMetaEnvDefines(inlineEnv) {
85
- const env = inlineEnv ?? {};
86
- const defines = { "import.meta.env": JSON.stringify(env) };
87
- for (const [key, value] of Object.entries(env)) if (/^[A-Za-z_$][\w$]*$/.test(key)) defines[`import.meta.env.${key}`] = JSON.stringify(value);
88
- return defines;
100
+ const env = inlineEnv ?? {};
101
+ const defines = { "import.meta.env": JSON.stringify(env) };
102
+ for (const [key, value] of Object.entries(env)) {
103
+ if (/^[A-Za-z_$][\w$]*$/.test(key))
104
+ defines[`import.meta.env.${key}`] = JSON.stringify(value);
105
+ }
106
+ return defines;
89
107
  }
90
108
  async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName, inlineEnv) {
91
- const versions = readProjectDependencyVersions(projectRoot);
92
- const result = await build({
93
- stdin: {
94
- contents: `import mcp from ${JSON.stringify(mcpEntryAbs)};\nimport { createSupabaseHandler } from "@lovable.dev/mcp-js/stacks/supabase";\nDeno.serve(createSupabaseHandler(mcp, { functionName: ${JSON.stringify(functionName)} }));\n`,
95
- resolveDir: projectRoot,
96
- sourcefile: "lovable-mcp-supabase-entry.ts",
97
- loader: "ts"
98
- },
99
- bundle: true,
100
- write: false,
101
- metafile: true,
102
- format: "esm",
103
- platform: "neutral",
104
- target: "esnext",
105
- absWorkingDir: projectRoot,
106
- logLevel: "silent",
107
- define: importMetaEnvDefines(inlineEnv),
108
- plugins: [externalizeBareAsNpm(versions)]
109
- });
110
- const out = result.outputFiles[0]?.text ?? "";
111
- const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((p) => !p.startsWith("<") && !p.startsWith("npm:")).map((p) => resolve(projectRoot, p));
112
- return {
113
- code: `${GENERATED_BANNER}\n// supabase function: ${functionName}\n// Bundled from ${relative(projectRoot, mcpEntryAbs).split(sep).join("/")} by @lovable.dev/mcp-js.\n` + out,
114
- inputs
115
- };
109
+ const versions = readProjectDependencyVersions(projectRoot);
110
+ const wrapper = `import mcp from ${JSON.stringify(mcpEntryAbs)};
111
+ import { createSupabaseHandler } from "@lovable.dev/mcp-js/stacks/supabase";
112
+ Deno.serve(createSupabaseHandler(mcp, { functionName: ${JSON.stringify(functionName)} }));
113
+ `;
114
+ const result = await build({
115
+ stdin: { contents: wrapper, resolveDir: projectRoot, sourcefile: "lovable-mcp-supabase-entry.ts", loader: "ts" },
116
+ bundle: true,
117
+ write: false,
118
+ metafile: true,
119
+ format: "esm",
120
+ platform: "neutral",
121
+ target: "esnext",
122
+ absWorkingDir: projectRoot,
123
+ logLevel: "silent",
124
+ define: importMetaEnvDefines(inlineEnv),
125
+ plugins: [externalizeBareAsNpm(versions)]
126
+ });
127
+ const out = result.outputFiles[0]?.text ?? "";
128
+ const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((p) => !p.startsWith("<") && !p.startsWith("npm:")).map((p) => resolve(projectRoot, p));
129
+ const code = `${GENERATED_BANNER}
130
+ // supabase function: ${functionName}
131
+ // Bundled from ${relative(projectRoot, mcpEntryAbs).split(sep).join("/")} by @lovable.dev/mcp-js.
132
+ ` + out;
133
+ return { code, inputs };
116
134
  }
117
135
  function resolvePaths(options) {
118
- const projectRoot = resolve(options.projectRoot);
119
- const mcpEntry = options.mcpEntry ?? "src/lib/mcp/index.ts";
120
- const functionsDir = options.functionsDir ?? "supabase/functions";
121
- const functionName = options.functionName ?? "mcp";
122
- assertFunctionName(functionName);
123
- const functionDir = resolve(projectRoot, functionsDir, functionName);
124
- if (functionDir !== projectRoot && !functionDir.startsWith(projectRoot + sep)) throw new Error(`@lovable.dev/mcp-js: functionsDir must resolve within the project root, got ${JSON.stringify(functionsDir)}`);
125
- return {
126
- functionDir,
127
- functionEntry: join(functionDir, "index.ts"),
128
- mcpEntryAbs: resolve(projectRoot, mcpEntry)
129
- };
136
+ const projectRoot = resolve(options.projectRoot);
137
+ const mcpEntry = options.mcpEntry ?? DEFAULT_MCP_ENTRY;
138
+ const functionsDir = options.functionsDir ?? DEFAULT_FUNCTIONS_DIR;
139
+ const functionName = options.functionName ?? DEFAULT_FUNCTION_NAME;
140
+ assertFunctionName(functionName);
141
+ const functionDir = resolve(projectRoot, functionsDir, functionName);
142
+ if (functionDir !== projectRoot && !functionDir.startsWith(projectRoot + sep)) {
143
+ throw new Error(
144
+ `@lovable.dev/mcp-js: functionsDir must resolve within the project root, got ${JSON.stringify(functionsDir)}`
145
+ );
146
+ }
147
+ return {
148
+ functionDir,
149
+ functionEntry: join(functionDir, "index.ts"),
150
+ mcpEntryAbs: resolve(projectRoot, mcpEntry)
151
+ };
130
152
  }
131
- /**
132
- * Sync the Supabase function for an MCP entry. Bundles the entry (and its local
133
- * import graph) into a self-contained `supabase/functions/<name>/index.ts` with
134
- * direct `npm:` specifiers, and removes the SDK-owned files when the entry
135
- * disappears so deleting it leaves no stale boilerplate behind. No `deno.json`
136
- * is emitted — the bundle carries no bare imports, so an import map is moot, and
137
- * a legacy generated `deno.json` is cleaned up below.
138
- */
139
153
  async function syncSupabaseFunction(options) {
140
- const projectRoot = resolve(options.projectRoot);
141
- const paths = resolvePaths(options);
142
- const functionName = options.functionName ?? "mcp";
143
- const written = [];
144
- const removed = [];
145
- if (!fileExists(paths.mcpEntryAbs)) {
146
- cleanupOrphans(paths.functionDir, /* @__PURE__ */ new Set(), removed);
147
- return {
148
- written,
149
- removed,
150
- inputs: []
151
- };
152
- }
153
- const { code, inputs } = await bundleFunctionEntry(projectRoot, paths.mcpEntryAbs, functionName, options.inlineEnv);
154
- if (writeIfChanged(paths.functionEntry, code, hasGeneratedBanner)) written.push(paths.functionEntry);
155
- cleanupOrphans(paths.functionDir, /* @__PURE__ */ new Set([paths.functionEntry]), removed);
156
- return {
157
- written,
158
- removed,
159
- inputs
160
- };
154
+ const projectRoot = resolve(options.projectRoot);
155
+ const paths = resolvePaths(options);
156
+ const functionName = options.functionName ?? DEFAULT_FUNCTION_NAME;
157
+ const written = [];
158
+ const removed = [];
159
+ if (!fileExists(paths.mcpEntryAbs)) {
160
+ cleanupOrphans(paths.functionDir, /* @__PURE__ */ new Set(), removed);
161
+ return { written, removed, inputs: [] };
162
+ }
163
+ const { code, inputs } = await bundleFunctionEntry(projectRoot, paths.mcpEntryAbs, functionName, options.inlineEnv);
164
+ if (writeIfChanged(paths.functionEntry, code, hasGeneratedBanner)) {
165
+ written.push(paths.functionEntry);
166
+ }
167
+ cleanupOrphans(paths.functionDir, /* @__PURE__ */ new Set([paths.functionEntry]), removed);
168
+ return { written, removed, inputs };
161
169
  }
162
170
  function cleanupOrphans(functionDir, expected, removed) {
163
- let entries;
164
- try {
165
- entries = readdirSync(functionDir);
166
- } catch (err) {
167
- if (isFileMissing(err)) return;
168
- throw err;
169
- }
170
- for (const entry of entries) {
171
- const full = join(functionDir, entry);
172
- if (expected.has(full)) continue;
173
- let content;
174
- try {
175
- content = readFileSync(full, "utf8");
176
- } catch (err) {
177
- if (isFileMissing(err) || err.code === "EISDIR") continue;
178
- throw err;
179
- }
180
- if (hasGeneratedBanner(content) || hasGeneratedJsonMarker(content)) try {
181
- unlinkSync(full);
182
- removed.push(full);
183
- } catch (err) {
184
- if (!isFileMissing(err)) throw err;
185
- }
186
- }
171
+ let entries;
172
+ try {
173
+ entries = readdirSync(functionDir);
174
+ } catch (err) {
175
+ if (isFileMissing(err))
176
+ return;
177
+ throw err;
178
+ }
179
+ for (const entry of entries) {
180
+ const full = join(functionDir, entry);
181
+ if (expected.has(full))
182
+ continue;
183
+ let content;
184
+ try {
185
+ content = readFileSync(full, "utf8");
186
+ } catch (err) {
187
+ if (isFileMissing(err) || err.code === "EISDIR")
188
+ continue;
189
+ throw err;
190
+ }
191
+ if (hasGeneratedBanner(content) || hasGeneratedJsonMarker(content)) {
192
+ try {
193
+ unlinkSync(full);
194
+ removed.push(full);
195
+ } catch (err) {
196
+ if (!isFileMissing(err))
197
+ throw err;
198
+ }
199
+ }
200
+ }
187
201
  }
188
- //#endregion
189
- //#region src/stacks/supabase/vite.ts
202
+
203
+ // src/stacks/supabase/vite.ts
190
204
  function normalizePath(p) {
191
- return p.split(sep).join("/");
205
+ return p.split(sep2).join("/");
192
206
  }
193
207
  function productionImportMetaEnv(config) {
194
- return {
195
- ...loadEnv("production", config.envDir, config.envPrefix),
196
- MODE: "production",
197
- BASE_URL: config.base ?? "/",
198
- DEV: false,
199
- PROD: true,
200
- SSR: false
201
- };
208
+ return {
209
+ ...loadEnv("production", config.envDir, config.envPrefix),
210
+ MODE: "production",
211
+ BASE_URL: config.base ?? "/",
212
+ DEV: false,
213
+ PROD: true,
214
+ SSR: false
215
+ };
202
216
  }
203
- /**
204
- * Vite plugin that emits the Supabase Edge Function entry (and its
205
- * `deno.json` import map) for an `@lovable.dev/mcp-js` MCP server.
206
- *
207
- * Place this in your `vite.config.ts` plugins array. It uses Vite as the
208
- * trigger for codegen even though the emitted output (Deno function) is
209
- * not part of the Vite bundle — Classic Lovable stacks already run Vite
210
- * for the frontend, so it's the natural authoring surface.
211
- *
212
- * Lifecycle, mirroring `stacks/tanstack/vite`:
213
- * - `configResolved` finalizes the project root and runs the first emit.
214
- * - `buildStart` re-runs the emit so a `vite build` always picks up the
215
- * latest source.
216
- * - `configureServer` re-emits when the entry or any bundled source file
217
- * (tools, local helpers) changes during `vite dev`, so editing a tool
218
- * regenerates the function without restarting the server.
219
- *
220
- * The entry and its local import graph are bundled by esbuild into one
221
- * self-contained Deno module (deps left as `npm:` specifiers), so the deployed
222
- * function carries no cross-project imports the Supabase deploy can't upload.
223
- * Idempotent: `syncSupabaseFunction` writes only on byte-level change and
224
- * cleans up SDK-owned files when the entry is deleted.
225
- */
226
217
  function mcpPlugin(options = {}) {
227
- const mcpEntryOption = options.mcpEntry ?? "src/lib/mcp/index.ts";
228
- const functionsDirOption = options.functionsDir ?? "supabase/functions";
229
- const functionName = options.functionName ?? "mcp";
230
- const urlPath = `${FUNCTIONS_MOUNT_PREFIX}${functionName}`;
231
- let projectRoot = process.cwd();
232
- let mcpEntryAbs = resolve(projectRoot, mcpEntryOption);
233
- let inlineEnv = {};
234
- let watchedInputs = /* @__PURE__ */ new Set();
235
- const regenerate = async () => {
236
- const { inputs } = await syncSupabaseFunction({
237
- projectRoot,
238
- mcpEntry: mcpEntryOption,
239
- functionsDir: functionsDirOption,
240
- functionName,
241
- inlineEnv
242
- });
243
- watchedInputs = new Set(inputs.map(normalizePath));
244
- };
245
- return {
246
- name: "@lovable.dev/mcp-js/supabase",
247
- api: {
248
- get mcpEntry() {
249
- return mcpEntryAbs;
250
- },
251
- urlPath
252
- },
253
- async configResolved(config) {
254
- projectRoot = config.root;
255
- mcpEntryAbs = resolve(projectRoot, mcpEntryOption);
256
- inlineEnv = productionImportMetaEnv(config);
257
- await regenerate();
258
- },
259
- configureServer(server) {
260
- const onChange = (file) => {
261
- const norm = normalizePath(file);
262
- if (norm !== normalizePath(mcpEntryAbs) && !watchedInputs.has(norm)) return;
263
- regenerate().catch((err) => {
264
- const message = `[@lovable.dev/mcp-js] failed to regenerate the Supabase function: ${err instanceof Error ? err.message : String(err)}`;
265
- if (server.config?.logger?.error) server.config.logger.error(message);
266
- else console.error(message);
267
- });
268
- };
269
- server.watcher.on("add", onChange);
270
- server.watcher.on("change", onChange);
271
- server.watcher.on("unlink", onChange);
272
- server.watcher.once("close", () => {
273
- server.watcher.off("add", onChange);
274
- server.watcher.off("change", onChange);
275
- server.watcher.off("unlink", onChange);
276
- });
277
- },
278
- async buildStart() {
279
- await regenerate();
280
- }
281
- };
218
+ const mcpEntryOption = options.mcpEntry ?? DEFAULT_MCP_ENTRY;
219
+ const functionsDirOption = options.functionsDir ?? DEFAULT_FUNCTIONS_DIR;
220
+ const functionName = options.functionName ?? DEFAULT_FUNCTION_NAME;
221
+ const urlPath = `${FUNCTIONS_MOUNT_PREFIX}${functionName}`;
222
+ let projectRoot = process.cwd();
223
+ let mcpEntryAbs = resolve2(projectRoot, mcpEntryOption);
224
+ let inlineEnv = {};
225
+ let watchedInputs = /* @__PURE__ */ new Set();
226
+ const regenerate = async () => {
227
+ const { inputs } = await syncSupabaseFunction({
228
+ projectRoot,
229
+ mcpEntry: mcpEntryOption,
230
+ functionsDir: functionsDirOption,
231
+ functionName,
232
+ inlineEnv
233
+ });
234
+ watchedInputs = new Set(inputs.map(normalizePath));
235
+ };
236
+ return {
237
+ name: "@lovable.dev/mcp-js/supabase",
238
+ // The extract CLI reads these back via `resolveConfig().plugins`. Getter
239
+ // for `mcpEntry` because the absolute path is finalized in `configResolved`;
240
+ // `urlPath` is config-time-final so it's a plain field.
241
+ api: {
242
+ get mcpEntry() {
243
+ return mcpEntryAbs;
244
+ },
245
+ urlPath
246
+ },
247
+ async configResolved(config) {
248
+ projectRoot = config.root;
249
+ mcpEntryAbs = resolve2(projectRoot, mcpEntryOption);
250
+ inlineEnv = productionImportMetaEnv(config);
251
+ await regenerate();
252
+ },
253
+ configureServer(server) {
254
+ const onChange = (file) => {
255
+ const norm = normalizePath(file);
256
+ if (norm !== normalizePath(mcpEntryAbs) && !watchedInputs.has(norm))
257
+ return;
258
+ regenerate().catch((err) => {
259
+ const message = `[@lovable.dev/mcp-js] failed to regenerate the Supabase function: ${err instanceof Error ? err.message : String(err)}`;
260
+ if (server.config?.logger?.error)
261
+ server.config.logger.error(message);
262
+ else
263
+ console.error(message);
264
+ });
265
+ };
266
+ server.watcher.on("add", onChange);
267
+ server.watcher.on("change", onChange);
268
+ server.watcher.on("unlink", onChange);
269
+ server.watcher.once("close", () => {
270
+ server.watcher.off("add", onChange);
271
+ server.watcher.off("change", onChange);
272
+ server.watcher.off("unlink", onChange);
273
+ });
274
+ },
275
+ async buildStart() {
276
+ await regenerate();
277
+ }
278
+ };
282
279
  }
283
- //#endregion
284
- export { mcpPlugin as default, mcpPlugin };
280
+ var vite_default = mcpPlugin;
281
+ export {
282
+ vite_default as default,
283
+ mcpPlugin
284
+ };