@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.
- package/dist/authorize-BMeXd_Sh.d.ts +25 -0
- package/dist/base-CM-KCpp6.d.ts +28 -0
- package/dist/chunk-4EHZUUS5.js +141 -0
- package/dist/chunk-6DXGZZA4.js +6 -0
- package/dist/chunk-6KNM7RGD.js +79 -0
- package/dist/chunk-6QFZYYUV.js +11 -0
- package/dist/chunk-EOFPMSND.js +6 -0
- package/dist/chunk-H37EB22A.js +125 -0
- package/dist/chunk-MA5H6PSF.js +46 -0
- package/dist/chunk-P43FIUMZ.js +114 -0
- package/dist/chunk-RK62EMPY.js +741 -0
- package/dist/chunk-RLE4UE63.js +58 -0
- package/dist/chunk-UQK5UO6C.js +26 -0
- package/dist/chunk-XQWJN6DC.js +14 -0
- package/dist/chunk-Y3ZFPEQH.js +8 -0
- package/dist/cli/extract-manifest.cjs +201 -116
- package/dist/cli/extract-manifest.d.cts +1 -1
- package/dist/cli/extract-manifest.d.ts +1 -1
- package/dist/cli/extract-manifest.js +156 -117
- package/dist/index.cjs +329 -129
- package/dist/index.d.cts +26 -26
- package/dist/index.d.ts +26 -26
- package/dist/index.js +177 -118
- package/dist/{io-CS4UL6_A.d.ts → io-D4srzRKc.d.ts} +4 -6
- package/dist/protocols/mcp/index.cjs +750 -3
- package/dist/protocols/mcp/index.d.cts +7 -6
- package/dist/protocols/mcp/index.d.ts +7 -6
- package/dist/protocols/mcp/index.js +12 -2
- package/dist/protocols/oauth-metadata.cjs +539 -48
- package/dist/protocols/oauth-metadata.d.cts +6 -5
- package/dist/protocols/oauth-metadata.d.ts +6 -5
- package/dist/protocols/oauth-metadata.js +10 -52
- package/dist/protocols/rest/index.cjs +843 -5
- package/dist/protocols/rest/index.d.cts +10 -7
- package/dist/protocols/rest/index.d.ts +10 -7
- package/dist/protocols/rest/index.js +16 -3
- package/dist/stacks/supabase/index.cjs +1318 -76
- package/dist/stacks/supabase/index.d.cts +30 -29
- package/dist/stacks/supabase/index.d.ts +30 -29
- package/dist/stacks/supabase/index.js +89 -73
- package/dist/stacks/supabase/vite.cjs +287 -258
- package/dist/stacks/supabase/vite.d.cts +24 -24
- package/dist/stacks/supabase/vite.d.ts +24 -24
- package/dist/stacks/supabase/vite.js +252 -252
- package/dist/stacks/tanstack/index.cjs +1272 -42
- package/dist/stacks/tanstack/index.d.cts +9 -8
- package/dist/stacks/tanstack/index.d.ts +9 -8
- package/dist/stacks/tanstack/index.js +41 -36
- package/dist/stacks/tanstack/vite.cjs +312 -223
- package/dist/stacks/tanstack/vite.d.cts +81 -80
- package/dist/stacks/tanstack/vite.d.ts +81 -80
- package/dist/stacks/tanstack/vite.js +282 -216
- package/dist/types-qqrmJ736.d.ts +321 -0
- package/package.json +28 -71
- package/dist/authorize-CumVyk7p.d.cts +0 -27
- package/dist/authorize-D6p4-9_D.d.ts +0 -27
- package/dist/base-CoIFvAmS.d.cts +0 -26
- package/dist/base-CoIFvAmS.d.ts +0 -26
- package/dist/content-D5LJAHyM.js +0 -12
- package/dist/content-NCYIGgOb.cjs +0 -17
- package/dist/context-BweeEcoA.cjs +0 -56
- package/dist/context-CIpPzN7P.js +0 -51
- package/dist/cors-B7CTXIHD.js +0 -829
- package/dist/cors-BebjKPrc.cjs +0 -912
- package/dist/forwarded--h4efJy-.js +0 -43
- package/dist/forwarded-Pi8Hs5Ps.cjs +0 -48
- package/dist/fs-errors-CWNzOV75.cjs +0 -11
- package/dist/fs-errors-PA2t1TIp.js +0 -6
- package/dist/io-CbbUbPY3.d.cts +0 -15
- package/dist/list-tools-CBCuS1Tv.cjs +0 -57
- package/dist/list-tools-CsWgiRy1.d.ts +0 -8
- package/dist/list-tools-CtZHOuPv.d.cts +0 -8
- package/dist/list-tools-D75RGtgs.js +0 -46
- package/dist/logger-2OXtfiIW.js +0 -141
- package/dist/logger-BqPOa_E1.cjs +0 -194
- package/dist/mcp-Cdj0AYst.cjs +0 -123
- package/dist/mcp-GngXbcqN.js +0 -118
- package/dist/metadata-path-CAkNcfyY.js +0 -12
- package/dist/metadata-path-zd7NSNoa.cjs +0 -17
- package/dist/package-7EUptuSJ.js +0 -4
- package/dist/package-BwCGVRcB.cjs +0 -9
- package/dist/paths-IS65L6TA.js +0 -7
- package/dist/paths-OP318a6c.cjs +0 -18
- package/dist/rest-CXH6-zv9.js +0 -113
- package/dist/rest-CyV8LHeB.cjs +0 -118
- package/dist/types-BYdYYTjk.d.cts +0 -321
- package/dist/types-BYdYYTjk.d.ts +0 -321
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
export { M as McpPluginApi } from '../../io-D4srzRKc.js';
|
|
3
|
+
|
|
4
4
|
interface McpPluginOptions {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
50
|
-
export { type
|
|
49
|
+
|
|
50
|
+
export { type McpPluginOptions, mcpPlugin as default, mcpPlugin };
|
|
@@ -1,284 +1,284 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
36
|
+
return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
|
|
21
37
|
}
|
|
22
38
|
function hasGeneratedJsonMarker(content) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
189
|
-
|
|
202
|
+
|
|
203
|
+
// src/stacks/supabase/vite.ts
|
|
190
204
|
function normalizePath(p) {
|
|
191
|
-
|
|
205
|
+
return p.split(sep2).join("/");
|
|
192
206
|
}
|
|
193
207
|
function productionImportMetaEnv(config) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
284
|
-
export {
|
|
280
|
+
var vite_default = mcpPlugin;
|
|
281
|
+
export {
|
|
282
|
+
vite_default as default,
|
|
283
|
+
mcpPlugin
|
|
284
|
+
};
|