@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,289 +1,318 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/stacks/supabase/vite.ts
|
|
21
|
+
var vite_exports = {};
|
|
22
|
+
__export(vite_exports, {
|
|
23
|
+
default: () => vite_default,
|
|
24
|
+
mcpPlugin: () => mcpPlugin
|
|
4
25
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
26
|
+
module.exports = __toCommonJS(vite_exports);
|
|
27
|
+
var import_node_path2 = require("path");
|
|
28
|
+
var import_vite = require("vite");
|
|
29
|
+
|
|
30
|
+
// src/stacks/supabase/emit.ts
|
|
31
|
+
var import_esbuild = require("esbuild");
|
|
32
|
+
var import_node_fs = require("fs");
|
|
33
|
+
var import_node_path = require("path");
|
|
34
|
+
|
|
35
|
+
// package.json
|
|
36
|
+
var version = "0.22.0";
|
|
37
|
+
|
|
38
|
+
// src/core/fs-errors.ts
|
|
39
|
+
function isFileMissing(err) {
|
|
40
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/stacks/supabase/paths.ts
|
|
44
|
+
var FUNCTIONS_MOUNT_PREFIX = "/functions/v1/";
|
|
45
|
+
function assertFunctionName(value, label = "functionName") {
|
|
46
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`@lovable.dev/mcp-js: ${label} must be a single path segment matching [A-Za-z0-9_-], got ${JSON.stringify(value)}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/stacks/supabase/emit.ts
|
|
54
|
+
var DEFAULT_MCP_ENTRY = "src/lib/mcp/index.ts";
|
|
55
|
+
var DEFAULT_FUNCTIONS_DIR = "supabase/functions";
|
|
56
|
+
var DEFAULT_FUNCTION_NAME = "mcp";
|
|
57
|
+
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.";
|
|
58
|
+
var GENERATED_JSON_MARKER_KEY = "_lovableMcpGenerated";
|
|
14
59
|
function fileExists(path) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
60
|
+
try {
|
|
61
|
+
(0, import_node_fs.lstatSync)(path);
|
|
62
|
+
return true;
|
|
63
|
+
} catch (err) {
|
|
64
|
+
if (isFileMissing(err))
|
|
65
|
+
return false;
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
22
68
|
}
|
|
23
69
|
function hasGeneratedBanner(content) {
|
|
24
|
-
|
|
70
|
+
return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
|
|
25
71
|
}
|
|
26
72
|
function hasGeneratedJsonMarker(content) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
73
|
+
try {
|
|
74
|
+
const parsed = JSON.parse(content);
|
|
75
|
+
return typeof parsed === "object" && parsed !== null && GENERATED_JSON_MARKER_KEY in parsed;
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
33
79
|
}
|
|
34
80
|
function writeIfChanged(file, content, ownershipCheck) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
81
|
+
let existing;
|
|
82
|
+
try {
|
|
83
|
+
existing = (0, import_node_fs.readFileSync)(file, "utf8");
|
|
84
|
+
} catch (err) {
|
|
85
|
+
if (!isFileMissing(err))
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
if (existing !== void 0) {
|
|
89
|
+
if (!ownershipCheck(existing)) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`@lovable.dev/mcp-js: refusing to overwrite user-authored file at ${file}. Delete it or move it first.`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
if (existing === content)
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(file), { recursive: true });
|
|
98
|
+
(0, import_node_fs.writeFileSync)(file, content, "utf8");
|
|
99
|
+
return true;
|
|
48
100
|
}
|
|
49
101
|
function readProjectDependencyVersions(projectRoot) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
57
|
-
} catch {
|
|
58
|
-
return {};
|
|
59
|
-
}
|
|
102
|
+
try {
|
|
103
|
+
const pkg = JSON.parse((0, import_node_fs.readFileSync)((0, import_node_path.join)(projectRoot, "package.json"), "utf8"));
|
|
104
|
+
return { ...pkg.peerDependencies, ...pkg.devDependencies, ...pkg.dependencies };
|
|
105
|
+
} catch {
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
60
108
|
}
|
|
61
109
|
function npmSpecifierFor(bare, versions) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
110
|
+
const pkg = bare.startsWith("@") ? bare.split("/").slice(0, 2).join("/") : bare.split("/")[0];
|
|
111
|
+
const subpath = bare.slice(pkg.length);
|
|
112
|
+
if (pkg === "@lovable.dev/mcp-js")
|
|
113
|
+
return `npm:${pkg}@${version}${subpath}`;
|
|
114
|
+
const range = versions[pkg];
|
|
115
|
+
const version2 = range && /^[\dv^~>=]|^latest$/.test(range) ? range : void 0;
|
|
116
|
+
return version2 ? `npm:${pkg}@${version2}${subpath}` : `npm:${pkg}${subpath}`;
|
|
68
117
|
}
|
|
69
118
|
function externalizeBareAsNpm(versions) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
};
|
|
119
|
+
return {
|
|
120
|
+
name: "lovable-mcp-externalize-bare-as-npm",
|
|
121
|
+
setup(pluginBuild) {
|
|
122
|
+
pluginBuild.onResolve({ filter: /.*/ }, (args) => {
|
|
123
|
+
const p = args.path;
|
|
124
|
+
if (p.startsWith(".") || p.startsWith("/"))
|
|
125
|
+
return null;
|
|
126
|
+
if (/^(npm|node|jsr|https?|data):/.test(p))
|
|
127
|
+
return { path: p, external: true };
|
|
128
|
+
return { path: npmSpecifierFor(p, versions), external: true };
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
87
132
|
}
|
|
88
133
|
function importMetaEnvDefines(inlineEnv) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
134
|
+
const env = inlineEnv ?? {};
|
|
135
|
+
const defines = { "import.meta.env": JSON.stringify(env) };
|
|
136
|
+
for (const [key, value] of Object.entries(env)) {
|
|
137
|
+
if (/^[A-Za-z_$][\w$]*$/.test(key))
|
|
138
|
+
defines[`import.meta.env.${key}`] = JSON.stringify(value);
|
|
139
|
+
}
|
|
140
|
+
return defines;
|
|
93
141
|
}
|
|
94
142
|
async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName, inlineEnv) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
143
|
+
const versions = readProjectDependencyVersions(projectRoot);
|
|
144
|
+
const wrapper = `import mcp from ${JSON.stringify(mcpEntryAbs)};
|
|
145
|
+
import { createSupabaseHandler } from "@lovable.dev/mcp-js/stacks/supabase";
|
|
146
|
+
Deno.serve(createSupabaseHandler(mcp, { functionName: ${JSON.stringify(functionName)} }));
|
|
147
|
+
`;
|
|
148
|
+
const result = await (0, import_esbuild.build)({
|
|
149
|
+
stdin: { contents: wrapper, resolveDir: projectRoot, sourcefile: "lovable-mcp-supabase-entry.ts", loader: "ts" },
|
|
150
|
+
bundle: true,
|
|
151
|
+
write: false,
|
|
152
|
+
metafile: true,
|
|
153
|
+
format: "esm",
|
|
154
|
+
platform: "neutral",
|
|
155
|
+
target: "esnext",
|
|
156
|
+
absWorkingDir: projectRoot,
|
|
157
|
+
logLevel: "silent",
|
|
158
|
+
define: importMetaEnvDefines(inlineEnv),
|
|
159
|
+
plugins: [externalizeBareAsNpm(versions)]
|
|
160
|
+
});
|
|
161
|
+
const out = result.outputFiles[0]?.text ?? "";
|
|
162
|
+
const inputs = Object.keys(result.metafile?.inputs ?? {}).filter((p) => !p.startsWith("<") && !p.startsWith("npm:")).map((p) => (0, import_node_path.resolve)(projectRoot, p));
|
|
163
|
+
const code = `${GENERATED_BANNER}
|
|
164
|
+
// supabase function: ${functionName}
|
|
165
|
+
// Bundled from ${(0, import_node_path.relative)(projectRoot, mcpEntryAbs).split(import_node_path.sep).join("/")} by @lovable.dev/mcp-js.
|
|
166
|
+
` + out;
|
|
167
|
+
return { code, inputs };
|
|
120
168
|
}
|
|
121
169
|
function resolvePaths(options) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
170
|
+
const projectRoot = (0, import_node_path.resolve)(options.projectRoot);
|
|
171
|
+
const mcpEntry = options.mcpEntry ?? DEFAULT_MCP_ENTRY;
|
|
172
|
+
const functionsDir = options.functionsDir ?? DEFAULT_FUNCTIONS_DIR;
|
|
173
|
+
const functionName = options.functionName ?? DEFAULT_FUNCTION_NAME;
|
|
174
|
+
assertFunctionName(functionName);
|
|
175
|
+
const functionDir = (0, import_node_path.resolve)(projectRoot, functionsDir, functionName);
|
|
176
|
+
if (functionDir !== projectRoot && !functionDir.startsWith(projectRoot + import_node_path.sep)) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
`@lovable.dev/mcp-js: functionsDir must resolve within the project root, got ${JSON.stringify(functionsDir)}`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
functionDir,
|
|
183
|
+
functionEntry: (0, import_node_path.join)(functionDir, "index.ts"),
|
|
184
|
+
mcpEntryAbs: (0, import_node_path.resolve)(projectRoot, mcpEntry)
|
|
185
|
+
};
|
|
134
186
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Sync the Supabase function for an MCP entry. Bundles the entry (and its local
|
|
137
|
-
* import graph) into a self-contained `supabase/functions/<name>/index.ts` with
|
|
138
|
-
* direct `npm:` specifiers, and removes the SDK-owned files when the entry
|
|
139
|
-
* disappears so deleting it leaves no stale boilerplate behind. No `deno.json`
|
|
140
|
-
* is emitted — the bundle carries no bare imports, so an import map is moot, and
|
|
141
|
-
* a legacy generated `deno.json` is cleaned up below.
|
|
142
|
-
*/
|
|
143
187
|
async function syncSupabaseFunction(options) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
cleanupOrphans(paths.functionDir, /* @__PURE__ */ new Set([paths.functionEntry]), removed);
|
|
160
|
-
return {
|
|
161
|
-
written,
|
|
162
|
-
removed,
|
|
163
|
-
inputs
|
|
164
|
-
};
|
|
188
|
+
const projectRoot = (0, import_node_path.resolve)(options.projectRoot);
|
|
189
|
+
const paths = resolvePaths(options);
|
|
190
|
+
const functionName = options.functionName ?? DEFAULT_FUNCTION_NAME;
|
|
191
|
+
const written = [];
|
|
192
|
+
const removed = [];
|
|
193
|
+
if (!fileExists(paths.mcpEntryAbs)) {
|
|
194
|
+
cleanupOrphans(paths.functionDir, /* @__PURE__ */ new Set(), removed);
|
|
195
|
+
return { written, removed, inputs: [] };
|
|
196
|
+
}
|
|
197
|
+
const { code, inputs } = await bundleFunctionEntry(projectRoot, paths.mcpEntryAbs, functionName, options.inlineEnv);
|
|
198
|
+
if (writeIfChanged(paths.functionEntry, code, hasGeneratedBanner)) {
|
|
199
|
+
written.push(paths.functionEntry);
|
|
200
|
+
}
|
|
201
|
+
cleanupOrphans(paths.functionDir, /* @__PURE__ */ new Set([paths.functionEntry]), removed);
|
|
202
|
+
return { written, removed, inputs };
|
|
165
203
|
}
|
|
166
204
|
function cleanupOrphans(functionDir, expected, removed) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
205
|
+
let entries;
|
|
206
|
+
try {
|
|
207
|
+
entries = (0, import_node_fs.readdirSync)(functionDir);
|
|
208
|
+
} catch (err) {
|
|
209
|
+
if (isFileMissing(err))
|
|
210
|
+
return;
|
|
211
|
+
throw err;
|
|
212
|
+
}
|
|
213
|
+
for (const entry of entries) {
|
|
214
|
+
const full = (0, import_node_path.join)(functionDir, entry);
|
|
215
|
+
if (expected.has(full))
|
|
216
|
+
continue;
|
|
217
|
+
let content;
|
|
218
|
+
try {
|
|
219
|
+
content = (0, import_node_fs.readFileSync)(full, "utf8");
|
|
220
|
+
} catch (err) {
|
|
221
|
+
if (isFileMissing(err) || err.code === "EISDIR")
|
|
222
|
+
continue;
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
225
|
+
if (hasGeneratedBanner(content) || hasGeneratedJsonMarker(content)) {
|
|
226
|
+
try {
|
|
227
|
+
(0, import_node_fs.unlinkSync)(full);
|
|
228
|
+
removed.push(full);
|
|
229
|
+
} catch (err) {
|
|
230
|
+
if (!isFileMissing(err))
|
|
231
|
+
throw err;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
191
235
|
}
|
|
192
|
-
|
|
193
|
-
|
|
236
|
+
|
|
237
|
+
// src/stacks/supabase/vite.ts
|
|
194
238
|
function normalizePath(p) {
|
|
195
|
-
|
|
239
|
+
return p.split(import_node_path2.sep).join("/");
|
|
196
240
|
}
|
|
197
241
|
function productionImportMetaEnv(config) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
242
|
+
return {
|
|
243
|
+
...(0, import_vite.loadEnv)("production", config.envDir, config.envPrefix),
|
|
244
|
+
MODE: "production",
|
|
245
|
+
BASE_URL: config.base ?? "/",
|
|
246
|
+
DEV: false,
|
|
247
|
+
PROD: true,
|
|
248
|
+
SSR: false
|
|
249
|
+
};
|
|
206
250
|
}
|
|
207
|
-
/**
|
|
208
|
-
* Vite plugin that emits the Supabase Edge Function entry (and its
|
|
209
|
-
* `deno.json` import map) for an `@lovable.dev/mcp-js` MCP server.
|
|
210
|
-
*
|
|
211
|
-
* Place this in your `vite.config.ts` plugins array. It uses Vite as the
|
|
212
|
-
* trigger for codegen even though the emitted output (Deno function) is
|
|
213
|
-
* not part of the Vite bundle — Classic Lovable stacks already run Vite
|
|
214
|
-
* for the frontend, so it's the natural authoring surface.
|
|
215
|
-
*
|
|
216
|
-
* Lifecycle, mirroring `stacks/tanstack/vite`:
|
|
217
|
-
* - `configResolved` finalizes the project root and runs the first emit.
|
|
218
|
-
* - `buildStart` re-runs the emit so a `vite build` always picks up the
|
|
219
|
-
* latest source.
|
|
220
|
-
* - `configureServer` re-emits when the entry or any bundled source file
|
|
221
|
-
* (tools, local helpers) changes during `vite dev`, so editing a tool
|
|
222
|
-
* regenerates the function without restarting the server.
|
|
223
|
-
*
|
|
224
|
-
* The entry and its local import graph are bundled by esbuild into one
|
|
225
|
-
* self-contained Deno module (deps left as `npm:` specifiers), so the deployed
|
|
226
|
-
* function carries no cross-project imports the Supabase deploy can't upload.
|
|
227
|
-
* Idempotent: `syncSupabaseFunction` writes only on byte-level change and
|
|
228
|
-
* cleans up SDK-owned files when the entry is deleted.
|
|
229
|
-
*/
|
|
230
251
|
function mcpPlugin(options = {}) {
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
252
|
+
const mcpEntryOption = options.mcpEntry ?? DEFAULT_MCP_ENTRY;
|
|
253
|
+
const functionsDirOption = options.functionsDir ?? DEFAULT_FUNCTIONS_DIR;
|
|
254
|
+
const functionName = options.functionName ?? DEFAULT_FUNCTION_NAME;
|
|
255
|
+
const urlPath = `${FUNCTIONS_MOUNT_PREFIX}${functionName}`;
|
|
256
|
+
let projectRoot = process.cwd();
|
|
257
|
+
let mcpEntryAbs = (0, import_node_path2.resolve)(projectRoot, mcpEntryOption);
|
|
258
|
+
let inlineEnv = {};
|
|
259
|
+
let watchedInputs = /* @__PURE__ */ new Set();
|
|
260
|
+
const regenerate = async () => {
|
|
261
|
+
const { inputs } = await syncSupabaseFunction({
|
|
262
|
+
projectRoot,
|
|
263
|
+
mcpEntry: mcpEntryOption,
|
|
264
|
+
functionsDir: functionsDirOption,
|
|
265
|
+
functionName,
|
|
266
|
+
inlineEnv
|
|
267
|
+
});
|
|
268
|
+
watchedInputs = new Set(inputs.map(normalizePath));
|
|
269
|
+
};
|
|
270
|
+
return {
|
|
271
|
+
name: "@lovable.dev/mcp-js/supabase",
|
|
272
|
+
// The extract CLI reads these back via `resolveConfig().plugins`. Getter
|
|
273
|
+
// for `mcpEntry` because the absolute path is finalized in `configResolved`;
|
|
274
|
+
// `urlPath` is config-time-final so it's a plain field.
|
|
275
|
+
api: {
|
|
276
|
+
get mcpEntry() {
|
|
277
|
+
return mcpEntryAbs;
|
|
278
|
+
},
|
|
279
|
+
urlPath
|
|
280
|
+
},
|
|
281
|
+
async configResolved(config) {
|
|
282
|
+
projectRoot = config.root;
|
|
283
|
+
mcpEntryAbs = (0, import_node_path2.resolve)(projectRoot, mcpEntryOption);
|
|
284
|
+
inlineEnv = productionImportMetaEnv(config);
|
|
285
|
+
await regenerate();
|
|
286
|
+
},
|
|
287
|
+
configureServer(server) {
|
|
288
|
+
const onChange = (file) => {
|
|
289
|
+
const norm = normalizePath(file);
|
|
290
|
+
if (norm !== normalizePath(mcpEntryAbs) && !watchedInputs.has(norm))
|
|
291
|
+
return;
|
|
292
|
+
regenerate().catch((err) => {
|
|
293
|
+
const message = `[@lovable.dev/mcp-js] failed to regenerate the Supabase function: ${err instanceof Error ? err.message : String(err)}`;
|
|
294
|
+
if (server.config?.logger?.error)
|
|
295
|
+
server.config.logger.error(message);
|
|
296
|
+
else
|
|
297
|
+
console.error(message);
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
server.watcher.on("add", onChange);
|
|
301
|
+
server.watcher.on("change", onChange);
|
|
302
|
+
server.watcher.on("unlink", onChange);
|
|
303
|
+
server.watcher.once("close", () => {
|
|
304
|
+
server.watcher.off("add", onChange);
|
|
305
|
+
server.watcher.off("change", onChange);
|
|
306
|
+
server.watcher.off("unlink", onChange);
|
|
307
|
+
});
|
|
308
|
+
},
|
|
309
|
+
async buildStart() {
|
|
310
|
+
await regenerate();
|
|
311
|
+
}
|
|
312
|
+
};
|
|
286
313
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
exports
|
|
314
|
+
var vite_default = mcpPlugin;
|
|
315
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
316
|
+
0 && (module.exports = {
|
|
317
|
+
mcpPlugin
|
|
318
|
+
});
|
|
@@ -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 };
|