@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.
Files changed (78) hide show
  1. package/README.md +104 -1
  2. package/dist/{authorize-Chb9Sb1f.d.ts → authorize-8crkySbp.d.ts} +1 -1
  3. package/dist/{authorize-Ba1deW5O.d.cts → authorize-BZdUmD37.d.cts} +1 -1
  4. package/dist/{base-D7ei8TjY.d.cts → base-CChLZaEN.d.cts} +1 -1
  5. package/dist/{base-D-lvtqSA.d.ts → base-DQPu0cno.d.ts} +1 -1
  6. package/dist/cli/check-server.cjs +61 -0
  7. package/dist/cli/check-server.d.cts +1 -0
  8. package/dist/cli/check-server.d.ts +1 -0
  9. package/dist/cli/check-server.js +62 -0
  10. package/dist/cli/extract-manifest.cjs +1 -1
  11. package/dist/cli/extract-manifest.js +1 -1
  12. package/dist/{cors-BuPvEjxu.cjs → cors-Ct-kdMcl.cjs} +1 -1
  13. package/dist/{cors-D9LajKfo.js → cors-Ct8SFh-_.js} +1 -1
  14. package/dist/diagnostic-ClI2_5MW.js +11 -0
  15. package/dist/diagnostic-DRKjgCsW.d.cts +12 -0
  16. package/dist/diagnostic-DRKjgCsW.d.ts +12 -0
  17. package/dist/diagnostic-ol9IE9Dl.cjs +16 -0
  18. package/dist/{errors-BEl2IOnx.js → errors-Cul5Uyfw.js} +3 -2
  19. package/dist/{errors-BlSu6Nrn.cjs → errors-ebgNFNvm.cjs} +3 -2
  20. package/dist/format-DDzvc92Z.cjs +41 -0
  21. package/dist/format-DKEuO8Tn.js +30 -0
  22. package/dist/hooks-BOdDe251.js +353 -0
  23. package/dist/hooks-xQl3EkDa.cjs +382 -0
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.d.cts +2 -2
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +1 -1
  28. package/dist/{io-B72X5KDG.d.ts → io-4N9Hcw0w.d.ts} +1 -1
  29. package/dist/{io-foChTR9t.d.cts → io-Be8y8E2V.d.cts} +1 -1
  30. package/dist/{io-BpxqVag8.cjs → io-Bf4Narx6.cjs} +17 -5
  31. package/dist/{io-DFsll31O.js → io-VMIaguRH.js} +14 -2
  32. package/dist/{mcp-DMMqfwKm.cjs → mcp-By6C2M4i.cjs} +156 -70
  33. package/dist/{mcp-B1wBn_X-.js → mcp-DWxIy07i.js} +154 -68
  34. package/dist/{package-Bt33FsvP.cjs → package-CBMX__7C.cjs} +1 -1
  35. package/dist/{package-BWLBCBmc.js → package-Ci4yKJUI.js} +1 -1
  36. package/dist/protocols/mcp/index.cjs +1 -1
  37. package/dist/protocols/mcp/index.d.cts +3 -3
  38. package/dist/protocols/mcp/index.d.ts +3 -3
  39. package/dist/protocols/mcp/index.js +1 -1
  40. package/dist/protocols/oauth-metadata.cjs +1 -1
  41. package/dist/protocols/oauth-metadata.d.cts +3 -3
  42. package/dist/protocols/oauth-metadata.d.ts +3 -3
  43. package/dist/protocols/oauth-metadata.js +1 -1
  44. package/dist/stacks/supabase/index.cjs +2 -2
  45. package/dist/stacks/supabase/index.d.cts +1 -1
  46. package/dist/stacks/supabase/index.d.ts +1 -1
  47. package/dist/stacks/supabase/index.js +2 -2
  48. package/dist/stacks/supabase/vite.cjs +40 -19
  49. package/dist/stacks/supabase/vite.d.cts +1 -1
  50. package/dist/stacks/supabase/vite.d.ts +1 -1
  51. package/dist/stacks/supabase/vite.js +34 -13
  52. package/dist/stacks/tanstack/index.cjs +2 -2
  53. package/dist/stacks/tanstack/index.d.cts +2 -2
  54. package/dist/stacks/tanstack/index.d.ts +2 -2
  55. package/dist/stacks/tanstack/index.js +2 -2
  56. package/dist/stacks/tanstack/vite.cjs +33 -25
  57. package/dist/stacks/tanstack/vite.d.cts +1 -1
  58. package/dist/stacks/tanstack/vite.d.ts +1 -1
  59. package/dist/stacks/tanstack/vite.js +26 -18
  60. package/dist/testing/index.cjs +46 -0
  61. package/dist/testing/index.d.cts +10 -0
  62. package/dist/testing/index.d.ts +10 -0
  63. package/dist/testing/index.js +44 -0
  64. package/dist/testing/server.cjs +197 -0
  65. package/dist/testing/server.d.cts +31 -0
  66. package/dist/testing/server.d.ts +31 -0
  67. package/dist/testing/server.js +195 -0
  68. package/dist/tool-result-teeTDoM1.js +70 -0
  69. package/dist/tool-result-yqOfZUOP.cjs +87 -0
  70. package/dist/{types-srTXYLoX.d.cts → types-CyDJi9Jb.d.cts} +7 -1
  71. package/dist/{types-srTXYLoX.d.ts → types-CyDJi9Jb.d.ts} +7 -1
  72. package/package.json +40 -4
  73. package/skill-imports.d.cts +1 -0
  74. package/skill-imports.d.ts +11 -0
  75. package/dist/fs-errors-CWNzOV75.cjs +0 -11
  76. package/dist/fs-errors-PA2t1TIp.js +0 -6
  77. package/dist/supabase-config-CakTU8YF.js +0 -26
  78. package/dist/supabase-config-Dz7dnUv0.cjs +0 -31
@@ -0,0 +1,382 @@
1
+ const require_format = require("./format-DDzvc92Z.cjs");
2
+ let node_fs = require("node:fs");
3
+ let node_path = require("node:path");
4
+ let node_crypto = require("node:crypto");
5
+ let js_yaml = require("js-yaml");
6
+ //#region src/core/fs-errors.ts
7
+ function isFileMissing(err) {
8
+ return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
9
+ }
10
+ //#endregion
11
+ //#region src/core/supabase-config.ts
12
+ const SUPABASE_CONFIG_RELATIVE_PATH = "supabase/config.toml";
13
+ function readSupabaseProjectRef(projectRoot) {
14
+ let content;
15
+ try {
16
+ content = (0, node_fs.readFileSync)((0, node_path.join)(projectRoot, SUPABASE_CONFIG_RELATIVE_PATH), "utf8");
17
+ } catch (err) {
18
+ if (isFileMissing(err)) return void 0;
19
+ throw err;
20
+ }
21
+ for (const raw of content.split(/\r?\n/)) {
22
+ const line = raw.trim();
23
+ if (line.length === 0 || line.startsWith("#")) continue;
24
+ if (line.startsWith("[")) break;
25
+ const match = /^project_id\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(line);
26
+ if (match) {
27
+ const value = match[1] ?? match[2] ?? "";
28
+ return value.length > 0 ? value : void 0;
29
+ }
30
+ }
31
+ }
32
+ //#endregion
33
+ //#region src/skills/frontmatter.ts
34
+ const NAME_RE = /^[\p{Ll}\p{Lo}\p{N}]+(?:-[\p{Ll}\p{Lo}\p{N}]+)*$/u;
35
+ function assertJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
36
+ if (value === null || typeof value === "string" || typeof value === "boolean") return;
37
+ if (typeof value === "number" && Number.isFinite(value) && !Object.is(value, -0)) {
38
+ if (!Number.isInteger(value) || Number.isSafeInteger(value)) return;
39
+ }
40
+ if (typeof value !== "object" || value === null || ancestors.has(value)) throw new Error("frontmatter must contain finite JSON values without cycles or unsafe integers");
41
+ ancestors.add(value);
42
+ for (const child of Object.values(value)) assertJsonValue(child, ancestors);
43
+ ancestors.delete(value);
44
+ }
45
+ function parseFrontmatter(text, fileAbs) {
46
+ const body = text.startsWith("") ? text.slice(1) : text;
47
+ const match = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(body);
48
+ if (!match) throw new Error(`@lovable.dev/mcp-js: ${fileAbs} must start with YAML frontmatter delimited by ---`);
49
+ let parsed;
50
+ try {
51
+ parsed = (0, js_yaml.load)(match[1], {
52
+ schema: js_yaml.JSON_SCHEMA,
53
+ filename: fileAbs
54
+ });
55
+ } catch (err) {
56
+ throw new Error(`@lovable.dev/mcp-js: invalid SKILL.md frontmatter in ${fileAbs}: ${err.message}`);
57
+ }
58
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`@lovable.dev/mcp-js: SKILL.md frontmatter must be a mapping in ${fileAbs}`);
59
+ try {
60
+ assertJsonValue(parsed);
61
+ } catch (error) {
62
+ throw new Error(`@lovable.dev/mcp-js: invalid frontmatter in ${fileAbs}: ${error.message}`);
63
+ }
64
+ return parsed;
65
+ }
66
+ function validateIdentity(frontmatter, rootAbs, skillPath) {
67
+ const { name, description } = frontmatter;
68
+ if (typeof name !== "string" || Array.from(name).length > 64 || !NAME_RE.test(name)) throw new Error(`@lovable.dev/mcp-js: invalid skill name ${JSON.stringify(name)} in ${rootAbs}/SKILL.md`);
69
+ if (name !== (0, node_path.basename)(rootAbs)) throw new Error(`@lovable.dev/mcp-js: skill name "${name}" must equal its directory name "${(0, node_path.basename)(rootAbs)}"`);
70
+ if (typeof description !== "string" || description.trim().length === 0 || Array.from(description).length > 1024) throw new Error(`@lovable.dev/mcp-js: skill description must be a 1-1024 character string in ${rootAbs}/SKILL.md`);
71
+ if (skillPath.split("/").some((part) => !part || part === "." || part === ".." || /[\\\s]/u.test(part) || Array.from(part).some((char) => char < " ")) || skillPath.split("/").at(-1) !== name) throw new Error(`@lovable.dev/mcp-js: skill path must end in ${name} and contain nonempty directory segments: ${skillPath}`);
72
+ }
73
+ function validateOptionalFields(frontmatter, rootAbs) {
74
+ for (const field of [
75
+ "license",
76
+ "compatibility",
77
+ "allowed-tools"
78
+ ]) if (frontmatter[field] !== void 0 && typeof frontmatter[field] !== "string") throw new Error(`@lovable.dev/mcp-js: ${field} must be a string in ${rootAbs}/SKILL.md`);
79
+ if (typeof frontmatter.compatibility === "string" && (!frontmatter.compatibility.trim() || Array.from(frontmatter.compatibility).length > 500)) throw new Error(`@lovable.dev/mcp-js: compatibility must be 1-500 characters in ${rootAbs}/SKILL.md`);
80
+ const metadata = frontmatter.metadata;
81
+ if (metadata !== void 0 && (metadata === null || typeof metadata !== "object" || Array.isArray(metadata) || Object.values(metadata).some((value) => typeof value !== "string"))) throw new Error(`@lovable.dev/mcp-js: metadata must map strings to strings in ${rootAbs}/SKILL.md`);
82
+ }
83
+ function readSkillFrontmatter(text, rootAbs, skillPath) {
84
+ const frontmatter = parseFrontmatter(text, (0, node_path.join)(rootAbs, "SKILL.md"));
85
+ validateIdentity(frontmatter, rootAbs, skillPath);
86
+ validateOptionalFields(frontmatter, rootAbs);
87
+ return frontmatter;
88
+ }
89
+ //#endregion
90
+ //#region src/skills/compile.ts
91
+ function mimeTypeFor(path) {
92
+ const lower = path.toLowerCase();
93
+ if (lower.endsWith(".md") || lower.endsWith(".markdown")) return "text/markdown";
94
+ if (lower.endsWith(".json")) return "application/json";
95
+ if (lower.endsWith(".yaml") || lower.endsWith(".yml")) return "application/yaml";
96
+ if (lower.endsWith(".csv")) return "text/csv";
97
+ return "text/plain";
98
+ }
99
+ function compareBytes(a, b) {
100
+ return Buffer.compare(Buffer.from(a, "utf8"), Buffer.from(b, "utf8"));
101
+ }
102
+ function approvedHiddenFiles(allowHidden) {
103
+ const allowed = new Set(allowHidden);
104
+ for (const path of allowed) {
105
+ const segments = path.split("/");
106
+ if (segments.some((part) => !part || part === "." || part === "..") || !segments.some((part) => part.startsWith(".")) || Array.from(path).some((char) => "\\:*?[]".includes(char) || char < " " || char === "")) throw new Error(`@lovable.dev/mcp-js: allowHidden requires exact relative hidden-file paths, not directories or globs: ${path}`);
107
+ }
108
+ return allowed;
109
+ }
110
+ function walk(rootAbs, allowHidden) {
111
+ const files = [];
112
+ const dirs = [rootAbs];
113
+ const allowed = approvedHiddenFiles(allowHidden);
114
+ const visit = (dirAbs, relPrefix) => {
115
+ for (const entry of (0, node_fs.readdirSync)(dirAbs)) {
116
+ const abs = (0, node_path.join)(dirAbs, entry);
117
+ const rel = relPrefix ? `${relPrefix}/${entry}` : entry;
118
+ const stat = (0, node_fs.lstatSync)(abs);
119
+ if (stat.isSymbolicLink()) throw new Error(`@lovable.dev/mcp-js: skill files must not be symlinks: ${abs}`);
120
+ if (rel.split("/").some((part) => part.startsWith(".")) && !(stat.isDirectory() ? allowHidden.some((path) => path.startsWith(`${rel}/`)) : allowed.has(rel))) throw new Error(`@lovable.dev/mcp-js: hidden skill entry ${rel} is not approved for publication; remove it or add an exact allowHidden=<relative-file-path> to the ?skill import`);
121
+ if (stat.isDirectory()) {
122
+ dirs.push(abs);
123
+ visit(abs, rel);
124
+ } else if (stat.isFile()) files.push(rel);
125
+ else throw new Error(`@lovable.dev/mcp-js: unsupported skill file type: ${abs}`);
126
+ }
127
+ };
128
+ visit(rootAbs, "");
129
+ for (const path of allowed) if (!files.includes(path)) throw new Error(`@lovable.dev/mcp-js: allowHidden entry does not name a skill file: ${path}`);
130
+ return {
131
+ files,
132
+ dirs
133
+ };
134
+ }
135
+ function encodeUri(skillPath, relPath) {
136
+ const segments = [...skillPath.split("/"), ...relPath.split("/")].map((segment) => encodeURIComponent(segment));
137
+ return new URL(`skill://${segments.join("/")}`).href;
138
+ }
139
+ function decodeSkillFile(bytes, abs) {
140
+ let text;
141
+ try {
142
+ text = new TextDecoder("utf-8", {
143
+ fatal: true,
144
+ ignoreBOM: true
145
+ }).decode(bytes);
146
+ } catch {
147
+ throw new Error(`@lovable.dev/mcp-js: skill file is not UTF-8 text (unsupported in this release): ${abs}`);
148
+ }
149
+ for (const char of text) if (char < " " && char !== " " && char !== "\n" && char !== "\r" || char === "") throw new Error(`@lovable.dev/mcp-js: skill file contains binary control characters: ${abs}`);
150
+ return text;
151
+ }
152
+ function compileSkillDirectory(dirInput, skillPath = (0, node_path.basename)((0, node_path.resolve)(dirInput)), allowHidden = []) {
153
+ const rootAbs = (0, node_path.resolve)(dirInput);
154
+ for (let path = rootAbs;; path = (0, node_path.dirname)(path)) {
155
+ if ((0, node_fs.lstatSync)(path).isSymbolicLink()) throw new Error(`@lovable.dev/mcp-js: skill paths must not be symlinks: ${path}`);
156
+ if ((0, node_path.dirname)(path) === path) break;
157
+ }
158
+ const rootStat = (0, node_fs.lstatSync)(rootAbs);
159
+ if (!rootStat.isDirectory() || rootStat.isSymbolicLink()) throw new Error(`@lovable.dev/mcp-js: ?skill import must name a real directory: ${rootAbs}`);
160
+ const { files: relPaths, dirs } = walk(rootAbs, allowHidden);
161
+ if (!relPaths.includes("SKILL.md")) throw new Error(`@lovable.dev/mcp-js: ${rootAbs} has no SKILL.md`);
162
+ relPaths.sort((a, b) => a === "SKILL.md" ? -1 : b === "SKILL.md" ? 1 : compareBytes(a, b));
163
+ const decoder = new TextDecoder("utf-8", {
164
+ fatal: true,
165
+ ignoreBOM: true
166
+ });
167
+ const skillBytes = (0, node_fs.readFileSync)((0, node_path.join)(rootAbs, "SKILL.md"));
168
+ const frontmatter = readSkillFrontmatter((() => {
169
+ try {
170
+ return decoder.decode(skillBytes);
171
+ } catch {
172
+ throw new Error(`@lovable.dev/mcp-js: ${(0, node_path.join)(rootAbs, "SKILL.md")} is not valid UTF-8`);
173
+ }
174
+ })(), rootAbs, skillPath);
175
+ let totalBytes = 0;
176
+ const files = relPaths.map((path) => {
177
+ const abs = (0, node_path.join)(rootAbs, path);
178
+ const bytes = path === "SKILL.md" ? skillBytes : (0, node_fs.readFileSync)(abs);
179
+ totalBytes += bytes.byteLength;
180
+ const text = decodeSkillFile(bytes, abs);
181
+ return {
182
+ path,
183
+ uri: encodeUri(skillPath, path),
184
+ mimeType: mimeTypeFor(path),
185
+ text,
186
+ size: bytes.byteLength,
187
+ digest: `sha256:${(0, node_crypto.createHash)("sha256").update(bytes).digest("hex")}`
188
+ };
189
+ });
190
+ const uri = encodeUri(skillPath, "SKILL.md");
191
+ const skill = {
192
+ kind: require_format.COMPILED_SKILL_KIND,
193
+ uri,
194
+ rootUri: uri.slice(0, -9),
195
+ frontmatter,
196
+ files
197
+ };
198
+ const report = [`[@lovable.dev/mcp-js] skill ${uri} (${files.length} files, ${totalBytes} bytes) — every file below is published to authorized MCP clients:`, ...files.map((file) => ` ${file.uri} ${file.size} B ${file.digest}`)].join("\n");
199
+ return {
200
+ skill,
201
+ watchFiles: relPaths.map((path) => (0, node_path.join)(rootAbs, path)),
202
+ watchDirs: dirs,
203
+ report
204
+ };
205
+ }
206
+ function skillModuleSource(compilation) {
207
+ return `export default JSON.parse(${JSON.stringify(JSON.stringify(compilation.skill))});\n`;
208
+ }
209
+ //#endregion
210
+ //#region src/skills/imports.ts
211
+ const SKILL_IMPORT_FILTER = /[?&]skill$/;
212
+ function skillImportId(directory, spec) {
213
+ const options = spec.skillPath === void 0 ? [] : [`path=${encodeURIComponent(spec.skillPath)}`];
214
+ for (const path of [...spec.allowHidden].sort()) options.push(`allowHidden=${encodeURIComponent(path)}`);
215
+ return `${directory}?${[...options, "skill"].join("&")}`;
216
+ }
217
+ function parseOption(option, id) {
218
+ const equals = option.indexOf("=");
219
+ const key = option.slice(0, equals);
220
+ if (equals < 0 || key !== "path" && key !== "allowHidden") throw new Error(`@lovable.dev/mcp-js: unknown ?skill import option: ${option}`);
221
+ try {
222
+ return [key, decodeURIComponent(option.slice(equals + 1))];
223
+ } catch {
224
+ throw new Error(`@lovable.dev/mcp-js: invalid percent encoding in ?skill import: ${id}`);
225
+ }
226
+ }
227
+ function parseSkillImport(id) {
228
+ const queryStart = id.lastIndexOf("?");
229
+ if (queryStart < 0 || /[\r\n\u2028\u2029]/.test(id)) return void 0;
230
+ const query = id.slice(queryStart + 1);
231
+ if (query !== "skill" && !query.endsWith("&skill")) return void 0;
232
+ const options = query === "skill" ? [] : query.slice(0, -6).split("&");
233
+ let skillPath;
234
+ const allowHidden = [];
235
+ for (const option of options) {
236
+ const [key, value] = parseOption(option, id);
237
+ if (key === "path") {
238
+ if (skillPath !== void 0) throw new Error("@lovable.dev/mcp-js: duplicate path in ?skill import");
239
+ skillPath = value;
240
+ } else {
241
+ if (allowHidden.includes(value)) throw new Error(`@lovable.dev/mcp-js: duplicate allowHidden entry: ${value}`);
242
+ allowHidden.push(value);
243
+ }
244
+ }
245
+ return {
246
+ directory: id.slice(0, queryStart),
247
+ skillPath,
248
+ allowHidden
249
+ };
250
+ }
251
+ //#endregion
252
+ //#region src/skills/hooks.ts
253
+ const VIRTUAL_PREFIX = "\0lovable-mcp-skill:";
254
+ const ESBUILD_NAMESPACE = "lovable-mcp-skill";
255
+ function resolveSkillDir(spec, baseDir) {
256
+ if (!spec.startsWith(".") && !(0, node_path.isAbsolute)(spec)) return void 0;
257
+ return (0, node_path.resolve)(baseDir, spec);
258
+ }
259
+ function isUnder(dir, file) {
260
+ return file === dir || file.startsWith(dir + node_path.sep);
261
+ }
262
+ function invalidateModule(server, id) {
263
+ for (const environment of Object.values(server.environments ?? {})) {
264
+ const mod = environment.moduleGraph.getModuleById(id);
265
+ if (mod) environment.moduleGraph.invalidateModule(mod);
266
+ }
267
+ const legacy = server.moduleGraph.getModuleById(id);
268
+ if (legacy) server.moduleGraph.invalidateModule(legacy);
269
+ }
270
+ function skillImportVitePlugin(options = {}) {
271
+ const report = options.report ?? ((text) => console.info(text));
272
+ const dirsById = /* @__PURE__ */ new Map();
273
+ let devServer;
274
+ const invalidateFor = (file) => {
275
+ if (!devServer) return;
276
+ const abs = (0, node_path.resolve)(file);
277
+ for (const [id, dir] of dirsById) {
278
+ if (!isUnder(dir, abs)) continue;
279
+ invalidateModule(devServer, id);
280
+ }
281
+ };
282
+ return {
283
+ name: "@lovable.dev/mcp-js/skill-import",
284
+ resolveId: {
285
+ order: "pre",
286
+ handler(source, importer) {
287
+ const spec = parseSkillImport(source);
288
+ if (spec === void 0) return null;
289
+ const baseDir = importer ? (0, node_path.dirname)(importer.replace(/[?#].*$/, "")) : process.cwd();
290
+ const dir = resolveSkillDir(spec.directory, baseDir);
291
+ if (dir === void 0) throw new Error(`@lovable.dev/mcp-js: ?skill imports must be relative or absolute paths, got ${source}`);
292
+ return VIRTUAL_PREFIX + skillImportId(dir, spec);
293
+ }
294
+ },
295
+ load: { handler(id) {
296
+ if (!id.startsWith(VIRTUAL_PREFIX)) return null;
297
+ const spec = parseSkillImport(id.slice(19));
298
+ const dir = spec.directory;
299
+ dirsById.set(id, dir);
300
+ devServer?.watcher.add(dir);
301
+ const compilation = compileSkillDirectory(dir, spec.skillPath, spec.allowHidden);
302
+ for (const file of compilation.watchFiles) this.addWatchFile(file);
303
+ report(compilation.report);
304
+ return skillModuleSource(compilation);
305
+ } },
306
+ configureServer(server) {
307
+ devServer = server;
308
+ server.watcher.on("add", invalidateFor);
309
+ server.watcher.on("change", invalidateFor);
310
+ server.watcher.on("unlink", invalidateFor);
311
+ server.watcher.on("unlinkDir", invalidateFor);
312
+ options.onServer?.(server);
313
+ }
314
+ };
315
+ }
316
+ function skillImportEsbuildPlugin(onCompile, onDirectory) {
317
+ return {
318
+ name: "lovable-mcp-skill-import",
319
+ setup(pluginBuild) {
320
+ const workingDir = pluginBuild.initialOptions.absWorkingDir ?? process.cwd();
321
+ pluginBuild.onResolve({ filter: SKILL_IMPORT_FILTER }, (args) => {
322
+ const spec = parseSkillImport(args.path);
323
+ if (spec === void 0) return void 0;
324
+ const dir = resolveSkillDir(spec.directory, args.resolveDir);
325
+ if (dir === void 0) return { errors: [{ text: `?skill imports must be relative or absolute paths, got ${args.path}` }] };
326
+ onDirectory?.(dir);
327
+ return {
328
+ path: skillImportId((0, node_path.relative)(workingDir, dir).split(node_path.sep).join("/"), spec),
329
+ namespace: ESBUILD_NAMESPACE
330
+ };
331
+ });
332
+ pluginBuild.onLoad({
333
+ filter: /.*/,
334
+ namespace: ESBUILD_NAMESPACE
335
+ }, (args) => {
336
+ const spec = parseSkillImport(args.path);
337
+ const compilation = compileSkillDirectory((0, node_path.resolve)(workingDir, spec.directory), spec.skillPath, spec.allowHidden);
338
+ onCompile(compilation);
339
+ return {
340
+ contents: skillModuleSource(compilation),
341
+ loader: "js",
342
+ watchFiles: [...compilation.watchFiles],
343
+ watchDirs: [...compilation.watchDirs]
344
+ };
345
+ });
346
+ }
347
+ };
348
+ }
349
+ function isSkillImportInput(input) {
350
+ return input.startsWith(`${ESBUILD_NAMESPACE}:`);
351
+ }
352
+ //#endregion
353
+ Object.defineProperty(exports, "isFileMissing", {
354
+ enumerable: true,
355
+ get: function() {
356
+ return isFileMissing;
357
+ }
358
+ });
359
+ Object.defineProperty(exports, "isSkillImportInput", {
360
+ enumerable: true,
361
+ get: function() {
362
+ return isSkillImportInput;
363
+ }
364
+ });
365
+ Object.defineProperty(exports, "readSupabaseProjectRef", {
366
+ enumerable: true,
367
+ get: function() {
368
+ return readSupabaseProjectRef;
369
+ }
370
+ });
371
+ Object.defineProperty(exports, "skillImportEsbuildPlugin", {
372
+ enumerable: true,
373
+ get: function() {
374
+ return skillImportEsbuildPlugin;
375
+ }
376
+ });
377
+ Object.defineProperty(exports, "skillImportVitePlugin", {
378
+ enumerable: true,
379
+ get: function() {
380
+ return skillImportVitePlugin;
381
+ }
382
+ });
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_logger = require("./logger-C-Hdu57K.cjs");
3
- const require_errors = require("./errors-BlSu6Nrn.cjs");
3
+ const require_errors = require("./errors-ebgNFNvm.cjs");
4
4
  //#region src/auth/config.ts
5
5
  function frozenArray(value) {
6
6
  return value === void 0 ? void 0 : Object.freeze([...value]);
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as McpClientInfo, C as ToolVisibilityContext, D as MetricsConfig, E as ZodSchema, F as McpAuthConfig, M as ProgressUpdate, N as ToolContext, O as MetricsOptions, P as JwtClaims, S as ToolHandlerResult, T as ZodRawShape, _ as ResourceLinkIcon, a as ContentBlock, b as ToolContent, c as EmbeddedResource, d as JsonValue, f as JsonValueInput, g as ResourceLink, h as McpDefinitionInput, i as ContentAnnotations, j as McpProtocolEra, k as AuthContext, l as EmbeddedTextResource, m as McpDefinition, n as AppContextToolDefinitionInput, o as CreateAppContextInput, p as McpAllowedOrigins, r as AudioContent, s as EmbeddedBlobResource, t as AppContextToolDefinition, u as ImageContent, v as TextContent, w as ZodOutputSchema, x as ToolDefinition, y as ToolAnnotations } from "./types-srTXYLoX.cjs";
1
+ import { A as AuthContext, C as ToolVisibilityContext, D as Skill, E as ZodSchema, F as JwtClaims, I as McpAuthConfig, M as McpProtocolEra, N as ProgressUpdate, O as MetricsConfig, P as ToolContext, S as ToolHandlerResult, T as ZodRawShape, _ as ResourceLinkIcon, a as ContentBlock, b as ToolContent, c as EmbeddedResource, d as JsonValue, f as JsonValueInput, g as ResourceLink, h as McpDefinitionInput, i as ContentAnnotations, j as McpClientInfo, k as MetricsOptions, l as EmbeddedTextResource, m as McpDefinition, n as AppContextToolDefinitionInput, o as CreateAppContextInput, p as McpAllowedOrigins, r as AudioContent, s as EmbeddedBlobResource, t as AppContextToolDefinition, u as ImageContent, v as TextContent, w as ZodOutputSchema, x as ToolDefinition, y as ToolAnnotations } from "./types-CyDJi9Jb.cjs";
2
2
  //#region src/core/define.d.ts
3
3
  /**
4
4
  * Declare a single MCP tool. Import the result into your MCP definition's
@@ -76,4 +76,4 @@ type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
76
76
  */
77
77
  declare function setLogLevel(level: LogLevel): LogLevel;
78
78
  //#endregion
79
- export { type AppContextToolDefinition, type AppContextToolDefinitionInput, type AudioContent, AuthContext, type ContentAnnotations, type ContentBlock, type CreateAppContextInput, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JsonValue, type JsonValueInput, type JwtClaims, type LogLevel, type McpAllowedOrigins, type McpClientInfo, type McpDefinitionInput, type McpProtocolEra, type MetricsConfig, type MetricsOptions, type ProgressUpdate, type ResourceLink, type ResourceLinkIcon, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ToolVisibilityContext, type ZodOutputSchema, type ZodRawShape, type ZodSchema, auth, defineMcp, defineTool, setLogLevel };
79
+ export { type AppContextToolDefinition, type AppContextToolDefinitionInput, type AudioContent, AuthContext, type ContentAnnotations, type ContentBlock, type CreateAppContextInput, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JsonValue, type JsonValueInput, type JwtClaims, type LogLevel, type McpAllowedOrigins, type McpClientInfo, type McpDefinitionInput, type McpProtocolEra, type MetricsConfig, type MetricsOptions, type ProgressUpdate, type ResourceLink, type ResourceLinkIcon, type Skill, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ToolVisibilityContext, type ZodOutputSchema, type ZodRawShape, type ZodSchema, auth, defineMcp, defineTool, setLogLevel };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as McpClientInfo, C as ToolVisibilityContext, D as MetricsConfig, E as ZodSchema, F as McpAuthConfig, M as ProgressUpdate, N as ToolContext, O as MetricsOptions, P as JwtClaims, S as ToolHandlerResult, T as ZodRawShape, _ as ResourceLinkIcon, a as ContentBlock, b as ToolContent, c as EmbeddedResource, d as JsonValue, f as JsonValueInput, g as ResourceLink, h as McpDefinitionInput, i as ContentAnnotations, j as McpProtocolEra, k as AuthContext, l as EmbeddedTextResource, m as McpDefinition, n as AppContextToolDefinitionInput, o as CreateAppContextInput, p as McpAllowedOrigins, r as AudioContent, s as EmbeddedBlobResource, t as AppContextToolDefinition, u as ImageContent, v as TextContent, w as ZodOutputSchema, x as ToolDefinition, y as ToolAnnotations } from "./types-srTXYLoX.js";
1
+ import { A as AuthContext, C as ToolVisibilityContext, D as Skill, E as ZodSchema, F as JwtClaims, I as McpAuthConfig, M as McpProtocolEra, N as ProgressUpdate, O as MetricsConfig, P as ToolContext, S as ToolHandlerResult, T as ZodRawShape, _ as ResourceLinkIcon, a as ContentBlock, b as ToolContent, c as EmbeddedResource, d as JsonValue, f as JsonValueInput, g as ResourceLink, h as McpDefinitionInput, i as ContentAnnotations, j as McpClientInfo, k as MetricsOptions, l as EmbeddedTextResource, m as McpDefinition, n as AppContextToolDefinitionInput, o as CreateAppContextInput, p as McpAllowedOrigins, r as AudioContent, s as EmbeddedBlobResource, t as AppContextToolDefinition, u as ImageContent, v as TextContent, w as ZodOutputSchema, x as ToolDefinition, y as ToolAnnotations } from "./types-CyDJi9Jb.js";
2
2
  //#region src/core/define.d.ts
3
3
  /**
4
4
  * Declare a single MCP tool. Import the result into your MCP definition's
@@ -76,4 +76,4 @@ type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
76
76
  */
77
77
  declare function setLogLevel(level: LogLevel): LogLevel;
78
78
  //#endregion
79
- export { type AppContextToolDefinition, type AppContextToolDefinitionInput, type AudioContent, AuthContext, type ContentAnnotations, type ContentBlock, type CreateAppContextInput, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JsonValue, type JsonValueInput, type JwtClaims, type LogLevel, type McpAllowedOrigins, type McpClientInfo, type McpDefinitionInput, type McpProtocolEra, type MetricsConfig, type MetricsOptions, type ProgressUpdate, type ResourceLink, type ResourceLinkIcon, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ToolVisibilityContext, type ZodOutputSchema, type ZodRawShape, type ZodSchema, auth, defineMcp, defineTool, setLogLevel };
79
+ export { type AppContextToolDefinition, type AppContextToolDefinitionInput, type AudioContent, AuthContext, type ContentAnnotations, type ContentBlock, type CreateAppContextInput, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JsonValue, type JsonValueInput, type JwtClaims, type LogLevel, type McpAllowedOrigins, type McpClientInfo, type McpDefinitionInput, type McpProtocolEra, type MetricsConfig, type MetricsOptions, type ProgressUpdate, type ResourceLink, type ResourceLinkIcon, type Skill, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ToolVisibilityContext, type ZodOutputSchema, type ZodRawShape, type ZodSchema, auth, defineMcp, defineTool, setLogLevel };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { a as setLogLevel } from "./logger-CpLgYbCG.js";
2
- import { a as ToolContext, i as AuthContext, o as defineMcp, s as defineTool, t as ToolError } from "./errors-BEl2IOnx.js";
2
+ import { a as ToolContext, i as AuthContext, o as defineMcp, s as defineTool, t as ToolError } from "./errors-Cul5Uyfw.js";
3
3
  //#region src/auth/config.ts
4
4
  function frozenArray(value) {
5
5
  return value === void 0 ? void 0 : Object.freeze([...value]);
@@ -1,4 +1,4 @@
1
- import "./types-srTXYLoX.js";
1
+ import "./types-CyDJi9Jb.js";
2
2
  //#region src/manifest/io.d.ts
3
3
  /**
4
4
  * Shape every MCP Vite plugin exposes on its `api` so `runExtract` can read
@@ -1,4 +1,4 @@
1
- import "./types-srTXYLoX.cjs";
1
+ import "./types-CyDJi9Jb.cjs";
2
2
  //#region src/manifest/io.d.ts
3
3
  /**
4
4
  * Shape every MCP Vite plugin exposes on its `api` so `runExtract` can read
@@ -1,6 +1,6 @@
1
1
  const require_schema = require("./schema-CjFpqCEP.cjs");
2
- const require_package = require("./package-Bt33FsvP.cjs");
3
- const require_fs_errors = require("./fs-errors-CWNzOV75.cjs");
2
+ const require_package = require("./package-CBMX__7C.cjs");
3
+ const require_hooks = require("./hooks-xQl3EkDa.cjs");
4
4
  let node_fs = require("node:fs");
5
5
  let node_path = require("node:path");
6
6
  let vite = require("vite");
@@ -59,9 +59,16 @@ function isAuthShape(auth) {
59
59
  const a = auth;
60
60
  return a.type === "oauth" && typeof a.issuer === "string" && a.issuer.length > 0;
61
61
  }
62
+ function hasBlankIssuerHost(issuer) {
63
+ if (!URL.canParse(issuer)) return false;
64
+ const { hostname } = new URL(issuer);
65
+ return hostname === "" || hostname.startsWith(".");
66
+ }
62
67
  function manifestFromDefinition(definition, urlPath, source = "the MCP entry") {
63
68
  const def = definition;
64
69
  if (!(!!def && typeof def === "object" && typeof def.name === "string" && typeof def.title === "string" && typeof def.version === "string" && Array.isArray(def.tools) && def.tools.every(isToolShape) && isAuthShape(def.auth))) throw new Error(`@lovable.dev/mcp-js: ${source} must \`export default defineMcp(...)\` (got ${definition == null ? "no default export" : typeof definition}).`);
70
+ const issuer = def.auth?.issuer;
71
+ if (issuer !== void 0 && hasBlankIssuerHost(issuer)) throw new Error(`@lovable.dev/mcp-js: ${source} resolves its OAuth issuer to "${issuer}", which has no project host. Set VITE_SUPABASE_PROJECT_ID or the top-level project_id in supabase/config.toml, then extract the manifest again.`);
65
72
  return {
66
73
  version: 1,
67
74
  sdk_version: require_package.version,
@@ -84,6 +91,7 @@ async function produceViaSsr(projectRoot, alias, ssr, entryAbs, urlPath) {
84
91
  },
85
92
  optimizeDeps: { noDiscovery: true },
86
93
  resolve: { alias },
94
+ plugins: [require_hooks.skillImportVitePlugin({ report: () => {} })],
87
95
  ssr
88
96
  });
89
97
  try {
@@ -95,6 +103,7 @@ async function produceViaSsr(projectRoot, alias, ssr, entryAbs, urlPath) {
95
103
  //#endregion
96
104
  //#region src/manifest/io.ts
97
105
  const MAX_MANIFEST_TOOLS = 512;
106
+ const SUPABASE_PROJECT_REF_ENV = "VITE_SUPABASE_PROJECT_ID";
98
107
  const MCP_PLUGIN_NAME_PREFIX = "@lovable.dev/mcp-js";
99
108
  const DEFAULT_MCP_ENTRY = "src/lib/mcp/index.ts";
100
109
  const DEFAULT_MCP_PATH = "/mcp";
@@ -104,7 +113,7 @@ function writeManifestIfChanged(file, manifest) {
104
113
  try {
105
114
  existing = (0, node_fs.readFileSync)(file, "utf8");
106
115
  } catch (err) {
107
- if (!require_fs_errors.isFileMissing(err)) throw err;
116
+ if (!require_hooks.isFileMissing(err)) throw err;
108
117
  }
109
118
  if (existing === content) return;
110
119
  (0, node_fs.mkdirSync)((0, node_path.dirname)(file), { recursive: true });
@@ -123,7 +132,7 @@ function removeManifest(file) {
123
132
  try {
124
133
  (0, node_fs.unlinkSync)(file);
125
134
  } catch (err) {
126
- if (!require_fs_errors.isFileMissing(err)) throw err;
135
+ if (!require_hooks.isFileMissing(err)) throw err;
127
136
  }
128
137
  }
129
138
  async function syncManifest(manifestFile, entryAbs, urlPath, produce) {
@@ -131,7 +140,7 @@ async function syncManifest(manifestFile, entryAbs, urlPath, produce) {
131
140
  try {
132
141
  (0, node_fs.lstatSync)(entryAbs);
133
142
  } catch (err) {
134
- if (!require_fs_errors.isFileMissing(err)) throw err;
143
+ if (!require_hooks.isFileMissing(err)) throw err;
135
144
  entryExists = false;
136
145
  }
137
146
  if (!entryExists) {
@@ -143,10 +152,13 @@ async function syncManifest(manifestFile, entryAbs, urlPath, produce) {
143
152
  if (manifest.mcp.tools.length > MAX_MANIFEST_TOOLS) throw new Error(`@lovable.dev/mcp-js: ${entryAbs} declares ${manifest.mcp.tools.length} tools, exceeding the App MCP manifest limit of ${MAX_MANIFEST_TOOLS}. Reduce defineMcp({ tools }) to ${MAX_MANIFEST_TOOLS} tools or fewer and extract the manifest again.`);
144
153
  }
145
154
  async function runExtract(projectRoot) {
155
+ if (process.env[SUPABASE_PROJECT_REF_ENV] === "") delete process.env[SUPABASE_PROJECT_REF_ENV];
146
156
  const resolved = await (0, vite.resolveConfig)({
147
157
  root: projectRoot,
148
158
  logLevel: "silent"
149
159
  }, "serve");
160
+ const ref = resolved.env[SUPABASE_PROJECT_REF_ENV] || require_hooks.readSupabaseProjectRef(projectRoot);
161
+ if (ref) process.env[SUPABASE_PROJECT_REF_ENV] = ref;
150
162
  const alias = resolved.resolve?.alias ?? [];
151
163
  const ssr = {
152
164
  external: resolved.ssr.external,
@@ -1,6 +1,6 @@
1
1
  import { t as jsonSchemaFromDefinition } from "./schema-DBTR1XbM.js";
2
- import { t as version } from "./package-BWLBCBmc.js";
3
- import { t as isFileMissing } from "./fs-errors-PA2t1TIp.js";
2
+ import { t as version } from "./package-Ci4yKJUI.js";
3
+ import { a as isFileMissing, i as readSupabaseProjectRef, r as skillImportVitePlugin } from "./hooks-BOdDe251.js";
4
4
  import { lstatSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
5
5
  import { dirname, resolve } from "node:path";
6
6
  import { createServer, resolveConfig } from "vite";
@@ -59,9 +59,16 @@ function isAuthShape(auth) {
59
59
  const a = auth;
60
60
  return a.type === "oauth" && typeof a.issuer === "string" && a.issuer.length > 0;
61
61
  }
62
+ function hasBlankIssuerHost(issuer) {
63
+ if (!URL.canParse(issuer)) return false;
64
+ const { hostname } = new URL(issuer);
65
+ return hostname === "" || hostname.startsWith(".");
66
+ }
62
67
  function manifestFromDefinition(definition, urlPath, source = "the MCP entry") {
63
68
  const def = definition;
64
69
  if (!(!!def && typeof def === "object" && typeof def.name === "string" && typeof def.title === "string" && typeof def.version === "string" && Array.isArray(def.tools) && def.tools.every(isToolShape) && isAuthShape(def.auth))) throw new Error(`@lovable.dev/mcp-js: ${source} must \`export default defineMcp(...)\` (got ${definition == null ? "no default export" : typeof definition}).`);
70
+ const issuer = def.auth?.issuer;
71
+ if (issuer !== void 0 && hasBlankIssuerHost(issuer)) throw new Error(`@lovable.dev/mcp-js: ${source} resolves its OAuth issuer to "${issuer}", which has no project host. Set VITE_SUPABASE_PROJECT_ID or the top-level project_id in supabase/config.toml, then extract the manifest again.`);
65
72
  return {
66
73
  version: 1,
67
74
  sdk_version: version,
@@ -84,6 +91,7 @@ async function produceViaSsr(projectRoot, alias, ssr, entryAbs, urlPath) {
84
91
  },
85
92
  optimizeDeps: { noDiscovery: true },
86
93
  resolve: { alias },
94
+ plugins: [skillImportVitePlugin({ report: () => {} })],
87
95
  ssr
88
96
  });
89
97
  try {
@@ -95,6 +103,7 @@ async function produceViaSsr(projectRoot, alias, ssr, entryAbs, urlPath) {
95
103
  //#endregion
96
104
  //#region src/manifest/io.ts
97
105
  const MAX_MANIFEST_TOOLS = 512;
106
+ const SUPABASE_PROJECT_REF_ENV = "VITE_SUPABASE_PROJECT_ID";
98
107
  const MCP_PLUGIN_NAME_PREFIX = "@lovable.dev/mcp-js";
99
108
  const DEFAULT_MCP_ENTRY = "src/lib/mcp/index.ts";
100
109
  const DEFAULT_MCP_PATH = "/mcp";
@@ -143,10 +152,13 @@ async function syncManifest(manifestFile, entryAbs, urlPath, produce) {
143
152
  if (manifest.mcp.tools.length > MAX_MANIFEST_TOOLS) throw new Error(`@lovable.dev/mcp-js: ${entryAbs} declares ${manifest.mcp.tools.length} tools, exceeding the App MCP manifest limit of ${MAX_MANIFEST_TOOLS}. Reduce defineMcp({ tools }) to ${MAX_MANIFEST_TOOLS} tools or fewer and extract the manifest again.`);
144
153
  }
145
154
  async function runExtract(projectRoot) {
155
+ if (process.env[SUPABASE_PROJECT_REF_ENV] === "") delete process.env[SUPABASE_PROJECT_REF_ENV];
146
156
  const resolved = await resolveConfig({
147
157
  root: projectRoot,
148
158
  logLevel: "silent"
149
159
  }, "serve");
160
+ const ref = resolved.env[SUPABASE_PROJECT_REF_ENV] || readSupabaseProjectRef(projectRoot);
161
+ if (ref) process.env[SUPABASE_PROJECT_REF_ENV] = ref;
150
162
  const alias = resolved.resolve?.alias ?? [];
151
163
  const ssr = {
152
164
  external: resolved.ssr.external,