@lovable.dev/mcp-js 0.22.1 → 0.22.2-rc.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-CumVyk7p.d.cts +27 -0
  2. package/dist/authorize-D6p4-9_D.d.ts +27 -0
  3. package/dist/base-DCe0kP79.d.cts +29 -0
  4. package/dist/base-DCe0kP79.d.ts +29 -0
  5. package/dist/cli/extract-manifest.cjs +116 -201
  6. package/dist/cli/extract-manifest.d.cts +1 -1
  7. package/dist/cli/extract-manifest.d.ts +1 -1
  8. package/dist/cli/extract-manifest.js +117 -156
  9. package/dist/content-D5LJAHyM.js +12 -0
  10. package/dist/content-NCYIGgOb.cjs +17 -0
  11. package/dist/context-BweeEcoA.cjs +56 -0
  12. package/dist/context-CIpPzN7P.js +51 -0
  13. package/dist/cors-CSDhBjFd.cjs +913 -0
  14. package/dist/cors-rWp_tbLZ.js +830 -0
  15. package/dist/forwarded--h4efJy-.js +43 -0
  16. package/dist/forwarded-Pi8Hs5Ps.cjs +48 -0
  17. package/dist/fs-errors-CWNzOV75.cjs +11 -0
  18. package/dist/fs-errors-PA2t1TIp.js +6 -0
  19. package/dist/index.cjs +129 -329
  20. package/dist/index.d.cts +26 -26
  21. package/dist/index.d.ts +26 -26
  22. package/dist/index.js +118 -177
  23. package/dist/{io-D4srzRKc.d.ts → io-CfSPxeBN.d.ts} +6 -4
  24. package/dist/io-DPYvBqET.d.cts +15 -0
  25. package/dist/list-tools-B4TTPEl1.d.cts +8 -0
  26. package/dist/list-tools-CFUX-uo-.cjs +57 -0
  27. package/dist/list-tools-DVJrjtmH.js +46 -0
  28. package/dist/list-tools-bh6-eqZM.d.ts +8 -0
  29. package/dist/logger-2OXtfiIW.js +141 -0
  30. package/dist/logger-BqPOa_E1.cjs +194 -0
  31. package/dist/mcp-BNcpj8o7.cjs +128 -0
  32. package/dist/mcp-Bx3bJHzH.js +123 -0
  33. package/dist/metadata-path-CAkNcfyY.js +12 -0
  34. package/dist/metadata-path-zd7NSNoa.cjs +17 -0
  35. package/dist/package-CgwD4Ywz.js +4 -0
  36. package/dist/package-DzstF8Ih.cjs +9 -0
  37. package/dist/paths-IS65L6TA.js +7 -0
  38. package/dist/paths-OP318a6c.cjs +18 -0
  39. package/dist/protocols/mcp/index.cjs +3 -750
  40. package/dist/protocols/mcp/index.d.cts +6 -7
  41. package/dist/protocols/mcp/index.d.ts +6 -7
  42. package/dist/protocols/mcp/index.js +2 -12
  43. package/dist/protocols/oauth-metadata.cjs +48 -539
  44. package/dist/protocols/oauth-metadata.d.cts +5 -6
  45. package/dist/protocols/oauth-metadata.d.ts +5 -6
  46. package/dist/protocols/oauth-metadata.js +52 -10
  47. package/dist/protocols/rest/index.cjs +5 -843
  48. package/dist/protocols/rest/index.d.cts +7 -10
  49. package/dist/protocols/rest/index.d.ts +7 -10
  50. package/dist/protocols/rest/index.js +3 -16
  51. package/dist/rest-BRshnow2.js +117 -0
  52. package/dist/rest-C4ZEGSIV.cjs +122 -0
  53. package/dist/stacks/supabase/index.cjs +76 -1318
  54. package/dist/stacks/supabase/index.d.cts +29 -30
  55. package/dist/stacks/supabase/index.d.ts +29 -30
  56. package/dist/stacks/supabase/index.js +73 -89
  57. package/dist/stacks/supabase/vite.cjs +258 -287
  58. package/dist/stacks/supabase/vite.d.cts +24 -24
  59. package/dist/stacks/supabase/vite.d.ts +24 -24
  60. package/dist/stacks/supabase/vite.js +252 -252
  61. package/dist/stacks/tanstack/index.cjs +42 -1272
  62. package/dist/stacks/tanstack/index.d.cts +8 -9
  63. package/dist/stacks/tanstack/index.d.ts +8 -9
  64. package/dist/stacks/tanstack/index.js +36 -41
  65. package/dist/stacks/tanstack/vite.cjs +223 -312
  66. package/dist/stacks/tanstack/vite.d.cts +80 -81
  67. package/dist/stacks/tanstack/vite.d.ts +80 -81
  68. package/dist/stacks/tanstack/vite.js +216 -282
  69. package/dist/types-BYdYYTjk.d.cts +321 -0
  70. package/dist/types-BYdYYTjk.d.ts +321 -0
  71. package/package.json +4 -4
  72. package/dist/authorize-BMeXd_Sh.d.ts +0 -25
  73. package/dist/base-CM-KCpp6.d.ts +0 -28
  74. package/dist/chunk-5HVSJCKE.js +0 -114
  75. package/dist/chunk-6DXGZZA4.js +0 -6
  76. package/dist/chunk-6QFZYYUV.js +0 -11
  77. package/dist/chunk-6SZOFKGH.js +0 -58
  78. package/dist/chunk-H37EB22A.js +0 -125
  79. package/dist/chunk-IFDWUM7L.js +0 -741
  80. package/dist/chunk-IXZIFYO6.js +0 -79
  81. package/dist/chunk-MA5H6PSF.js +0 -46
  82. package/dist/chunk-TJN33K5U.js +0 -141
  83. package/dist/chunk-UQK5UO6C.js +0 -26
  84. package/dist/chunk-XQWJN6DC.js +0 -14
  85. package/dist/chunk-Y3ZFPEQH.js +0 -8
  86. package/dist/chunk-ZQXSWTPU.js +0 -6
  87. package/dist/types-qqrmJ736.d.ts +0 -321
@@ -1,140 +1,89 @@
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/tanstack/vite.ts
21
- var vite_exports = {};
22
- __export(vite_exports, {
23
- assertMetadataPathShape: () => assertMetadataPathShape,
24
- assertUrlPathShape: () => assertUrlPathShape,
25
- default: () => vite_default,
26
- deriveRouteFileName: () => deriveRouteFileName,
27
- mcpPlugin: () => mcpPlugin
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
28
4
  });
29
- module.exports = __toCommonJS(vite_exports);
30
- var import_node_fs = require("fs");
31
- var import_node_path = require("path");
32
-
33
- // src/auth/metadata-path.ts
34
- var OAUTH_PROTECTED_RESOURCE_METADATA_PATH = "/.well-known/oauth-protected-resource";
35
-
36
- // src/core/fs-errors.ts
37
- function isFileMissing(err) {
38
- return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
39
- }
40
-
41
- // src/stacks/tanstack/vite.ts
42
- 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.";
5
+ require("../../metadata-path-zd7NSNoa.cjs");
6
+ const require_fs_errors = require("../../fs-errors-CWNzOV75.cjs");
7
+ let node_fs = require("node:fs");
8
+ let node_path = require("node:path");
9
+ //#region src/stacks/tanstack/vite.ts
10
+ 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.";
43
11
  function normalizePath(p) {
44
- return p.split(import_node_path.sep).join("/");
12
+ return p.split(node_path.sep).join("/");
45
13
  }
46
14
  function assertContains(parent, child, label) {
47
- if (child !== parent && !child.startsWith(parent + import_node_path.sep)) {
48
- throw new Error(`@lovable.dev/mcp-js: ${label} must resolve under ${parent}, got ${child}`);
49
- }
15
+ if (child !== parent && !child.startsWith(parent + node_path.sep)) throw new Error(`@lovable.dev/mcp-js: ${label} must resolve under ${parent}, got ${child}`);
50
16
  }
51
17
  function wellKnownRouteFile(routesDir, urlPath) {
52
- const segments = urlPath.replace(/^\//, "").split("/");
53
- const fileSegments = segments.map((segment, index) => {
54
- const escaped = segment.startsWith(".") ? `[${segment}]` : segment;
55
- return index === segments.length - 1 ? `${escaped}.ts` : escaped;
56
- });
57
- return (0, import_node_path.resolve)(routesDir, ...fileSegments);
18
+ const segments = urlPath.replace(/^\//, "").split("/");
19
+ return (0, node_path.resolve)(routesDir, ...segments.map((segment, index) => {
20
+ const escaped = segment.startsWith(".") ? `[${segment}]` : segment;
21
+ return index === segments.length - 1 ? `${escaped}.ts` : escaped;
22
+ }));
58
23
  }
59
24
  function resolveRestRoutes(routesDir, mcpUrlPath) {
60
- const parentSegments = mcpUrlPath.replace(/^\/+/, "").replace(/\/+$/, "").split("/").slice(0, -1);
61
- const restDir = (0, import_node_path.resolve)(routesDir, ...parentSegments, "[.mcp]");
62
- const restUrlBase = `/${[...parentSegments, ".mcp"].join("/")}`;
63
- return {
64
- listToolsRouteFile: (0, import_node_path.resolve)(restDir, "list-tools.ts"),
65
- invokeToolRouteFile: (0, import_node_path.resolve)(restDir, "invoke-tool", "$tool.ts"),
66
- listToolsLiteral: `${restUrlBase}/list-tools`,
67
- invokeToolLiteral: `${restUrlBase}/invoke-tool/$tool`
68
- };
25
+ const parentSegments = mcpUrlPath.replace(/^\/+/, "").replace(/\/+$/, "").split("/").slice(0, -1);
26
+ const restDir = (0, node_path.resolve)(routesDir, ...parentSegments, "[.mcp]");
27
+ const restUrlBase = `/${[...parentSegments, ".mcp"].join("/")}`;
28
+ return {
29
+ listToolsRouteFile: (0, node_path.resolve)(restDir, "list-tools.ts"),
30
+ invokeToolRouteFile: (0, node_path.resolve)(restDir, "invoke-tool", "$tool.ts"),
31
+ listToolsLiteral: `${restUrlBase}/list-tools`,
32
+ invokeToolLiteral: `${restUrlBase}/invoke-tool/$tool`
33
+ };
69
34
  }
70
35
  function resolveAllRoutes(projectRoot, routesDirOption, routeFileName, mcpUrlPath, metadataUrlPath) {
71
- const routesDir = (0, import_node_path.resolve)(projectRoot, routesDirOption);
72
- assertContains(projectRoot, routesDir, `routesDir "${routesDirOption}"`);
73
- const mcpRouteFile = (0, import_node_path.resolve)(routesDir, routeFileName);
74
- assertContains(routesDir, mcpRouteFile, `routeFileName "${routeFileName}"`);
75
- const metadataRouteFile = wellKnownRouteFile(routesDir, metadataUrlPath);
76
- assertContains(routesDir, metadataRouteFile, `metadataPath "${metadataUrlPath}"`);
77
- const rest = resolveRestRoutes(routesDir, mcpUrlPath);
78
- assertContains(routesDir, rest.listToolsRouteFile, `REST routes for path "${mcpUrlPath}"`);
79
- assertContains(routesDir, rest.invokeToolRouteFile, `REST routes for path "${mcpUrlPath}"`);
80
- return { routesDir, mcpRouteFile, metadataRouteFile, ...rest };
36
+ const routesDir = (0, node_path.resolve)(projectRoot, routesDirOption);
37
+ assertContains(projectRoot, routesDir, `routesDir "${routesDirOption}"`);
38
+ const mcpRouteFile = (0, node_path.resolve)(routesDir, routeFileName);
39
+ assertContains(routesDir, mcpRouteFile, `routeFileName "${routeFileName}"`);
40
+ const metadataRouteFile = wellKnownRouteFile(routesDir, metadataUrlPath);
41
+ assertContains(routesDir, metadataRouteFile, `metadataPath "${metadataUrlPath}"`);
42
+ const rest = resolveRestRoutes(routesDir, mcpUrlPath);
43
+ assertContains(routesDir, rest.listToolsRouteFile, `REST routes for path "${mcpUrlPath}"`);
44
+ assertContains(routesDir, rest.invokeToolRouteFile, `REST routes for path "${mcpUrlPath}"`);
45
+ return {
46
+ routesDir,
47
+ mcpRouteFile,
48
+ metadataRouteFile,
49
+ ...rest
50
+ };
81
51
  }
82
52
  function assertUrlPathShape(urlPath) {
83
- if (!urlPath.startsWith("/")) {
84
- throw new Error(`@lovable.dev/mcp-js: path must start with "/", got "${urlPath}"`);
85
- }
86
- if (/\/{2,}/.test(urlPath)) {
87
- throw new Error(`@lovable.dev/mcp-js: path "${urlPath}" contains empty segments ("//")`);
88
- }
89
- const trimmed = urlPath.replace(/^\/+/, "").replace(/\/+$/, "");
90
- if (!trimmed) {
91
- throw new Error(`@lovable.dev/mcp-js: path "${urlPath}" has no route segment`);
92
- }
93
- if (!/^[a-zA-Z0-9_\-/]+$/.test(trimmed)) {
94
- throw new Error(`@lovable.dev/mcp-js: path "${urlPath}" contains unsupported characters`);
95
- }
96
- return trimmed;
53
+ if (!urlPath.startsWith("/")) throw new Error(`@lovable.dev/mcp-js: path must start with "/", got "${urlPath}"`);
54
+ if (/\/{2,}/.test(urlPath)) throw new Error(`@lovable.dev/mcp-js: path "${urlPath}" contains empty segments ("//")`);
55
+ const trimmed = urlPath.replace(/^\/+/, "").replace(/\/+$/, "");
56
+ if (!trimmed) throw new Error(`@lovable.dev/mcp-js: path "${urlPath}" has no route segment`);
57
+ if (!/^[a-zA-Z0-9_\-/]+$/.test(trimmed)) throw new Error(`@lovable.dev/mcp-js: path "${urlPath}" contains unsupported characters`);
58
+ return trimmed;
97
59
  }
98
60
  function deriveRouteFileName(urlPath) {
99
- return `${assertUrlPathShape(urlPath)}.ts`;
61
+ return `${assertUrlPathShape(urlPath)}.ts`;
100
62
  }
101
63
  function assertMetadataPathShape(metadataPath) {
102
- if (!metadataPath.startsWith("/")) {
103
- throw new Error(`@lovable.dev/mcp-js: metadataPath must start with "/", got "${metadataPath}"`);
104
- }
105
- if (/\/{2,}/.test(metadataPath)) {
106
- throw new Error(`@lovable.dev/mcp-js: metadataPath "${metadataPath}" contains empty segments ("//")`);
107
- }
108
- if (/(^|\/)\.\.(\/|$)/.test(metadataPath)) {
109
- throw new Error(`@lovable.dev/mcp-js: metadataPath "${metadataPath}" must not contain ".." segments`);
110
- }
111
- const trimmed = metadataPath.replace(/^\/+/, "").replace(/\/+$/, "");
112
- if (!trimmed) {
113
- throw new Error(`@lovable.dev/mcp-js: metadataPath "${metadataPath}" has no route segment`);
114
- }
115
- if (!/^[a-zA-Z0-9_\-./]+$/.test(trimmed)) {
116
- throw new Error(`@lovable.dev/mcp-js: metadataPath "${metadataPath}" contains unsupported characters`);
117
- }
64
+ if (!metadataPath.startsWith("/")) throw new Error(`@lovable.dev/mcp-js: metadataPath must start with "/", got "${metadataPath}"`);
65
+ if (/\/{2,}/.test(metadataPath)) throw new Error(`@lovable.dev/mcp-js: metadataPath "${metadataPath}" contains empty segments ("//")`);
66
+ if (/(^|\/)\.\.(\/|$)/.test(metadataPath)) throw new Error(`@lovable.dev/mcp-js: metadataPath "${metadataPath}" must not contain ".." segments`);
67
+ const trimmed = metadataPath.replace(/^\/+/, "").replace(/\/+$/, "");
68
+ if (!trimmed) throw new Error(`@lovable.dev/mcp-js: metadataPath "${metadataPath}" has no route segment`);
69
+ if (!/^[a-zA-Z0-9_\-./]+$/.test(trimmed)) throw new Error(`@lovable.dev/mcp-js: metadataPath "${metadataPath}" contains unsupported characters`);
118
70
  }
119
71
  function canonicalUrlPath(urlPath) {
120
- return `/${urlPath.replace(/^\/+/, "").replace(/\/+$/, "")}`;
72
+ return `/${urlPath.replace(/^\/+/, "").replace(/\/+$/, "")}`;
121
73
  }
122
74
  function relativeImportSpecifier(routeFile, target) {
123
- const rel = normalizePath((0, import_node_path.relative)((0, import_node_path.dirname)(routeFile), target));
124
- const withoutExt = rel.replace(/\.ts$/, "");
125
- return withoutExt.startsWith(".") ? withoutExt : `./${withoutExt}`;
75
+ const withoutExt = normalizePath((0, node_path.relative)((0, node_path.dirname)(routeFile), target)).replace(/\.ts$/, "");
76
+ return withoutExt.startsWith(".") ? withoutExt : `./${withoutExt}`;
126
77
  }
127
78
  function buildRouteSource(route, resourcePath, metadataPath, trustForwardedHost, mcpEntry, projectRoot) {
128
- const mcpImport = relativeImportSpecifier(route.file, mcpEntry);
129
- const routeRel = normalizePath((0, import_node_path.relative)(projectRoot, route.file));
130
- const note = route.spaFallbackNote ? " // ANY: TanStack returns SPA HTML for methods not in `handlers`; the SDK 405s instead.\n" : "";
131
- const optionEntries = [`resourcePath: "${resourcePath}"`];
132
- if (metadataPath !== void 0)
133
- optionEntries.push(`metadataPath: "${metadataPath}"`);
134
- if (trustForwardedHost)
135
- optionEntries.push("trustForwardedHost: true");
136
- const runtimeOptions = `{ ${optionEntries.join(", ")} }`;
137
- return `${GENERATED_BANNER}
79
+ const mcpImport = relativeImportSpecifier(route.file, mcpEntry);
80
+ const routeRel = normalizePath((0, node_path.relative)(projectRoot, route.file));
81
+ const note = route.spaFallbackNote ? " // ANY: TanStack returns SPA HTML for methods not in `handlers`; the SDK 405s instead.\n" : "";
82
+ const optionEntries = [`resourcePath: "${resourcePath}"`];
83
+ if (metadataPath !== void 0) optionEntries.push(`metadataPath: "${metadataPath}"`);
84
+ if (trustForwardedHost) optionEntries.push("trustForwardedHost: true");
85
+ const runtimeOptions = `{ ${optionEntries.join(", ")} }`;
86
+ return `${GENERATED_BANNER}
138
87
  // route: ${route.routeLiteral}
139
88
  // emitted to: ${routeRel}
140
89
 
@@ -153,210 +102,172 @@ ${note} ANY: ${route.handlerFactory}(mcp, ${runtimeOptions}),
153
102
  });
154
103
  `;
155
104
  }
105
+ /**
106
+ * Writes `content` to `file` if it differs from what's there. Refuses to
107
+ * overwrite files without `GENERATED_BANNER` — the banner is the consent token.
108
+ */
156
109
  function hasGeneratedBanner(content) {
157
- return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
110
+ return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
158
111
  }
159
112
  function writeIfChanged(file, content) {
160
- let existing;
161
- try {
162
- existing = (0, import_node_fs.readFileSync)(file, "utf8");
163
- } catch (err) {
164
- if (!isFileMissing(err))
165
- throw err;
166
- }
167
- if (existing !== void 0) {
168
- if (!hasGeneratedBanner(existing)) {
169
- throw new Error(
170
- `@lovable.dev/mcp-js: refusing to overwrite user-authored route at ${file}. Delete it or move it first.`
171
- );
172
- }
173
- if (existing === content)
174
- return false;
175
- }
176
- (0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(file), { recursive: true });
177
- (0, import_node_fs.writeFileSync)(file, content, "utf8");
178
- return true;
113
+ let existing;
114
+ try {
115
+ existing = (0, node_fs.readFileSync)(file, "utf8");
116
+ } catch (err) {
117
+ if (!require_fs_errors.isFileMissing(err)) throw err;
118
+ }
119
+ if (existing !== void 0) {
120
+ if (!hasGeneratedBanner(existing)) throw new Error(`@lovable.dev/mcp-js: refusing to overwrite user-authored route at ${file}. Delete it or move it first.`);
121
+ if (existing === content) return false;
122
+ }
123
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(file), { recursive: true });
124
+ (0, node_fs.writeFileSync)(file, content, "utf8");
125
+ return true;
179
126
  }
180
127
  function fileStartsWithBanner(file) {
181
- try {
182
- return hasGeneratedBanner((0, import_node_fs.readFileSync)(file, "utf8"));
183
- } catch (err) {
184
- if (isFileMissing(err))
185
- return false;
186
- throw err;
187
- }
128
+ try {
129
+ return hasGeneratedBanner((0, node_fs.readFileSync)(file, "utf8"));
130
+ } catch (err) {
131
+ if (require_fs_errors.isFileMissing(err)) return false;
132
+ throw err;
133
+ }
188
134
  }
189
135
  function findAdoptedFiles(routesDir) {
190
- const adopted = [];
191
- const visit = (dir) => {
192
- let entries;
193
- try {
194
- entries = (0, import_node_fs.readdirSync)(dir);
195
- } catch (err) {
196
- if (isFileMissing(err))
197
- return;
198
- throw err;
199
- }
200
- for (const entry of entries) {
201
- const full = (0, import_node_path.join)(dir, entry);
202
- let stat;
203
- try {
204
- stat = (0, import_node_fs.lstatSync)(full);
205
- } catch (err) {
206
- if (isFileMissing(err))
207
- continue;
208
- throw err;
209
- }
210
- if (stat.isDirectory()) {
211
- visit(full);
212
- } else if (entry.endsWith(".ts") && fileStartsWithBanner(full)) {
213
- adopted.push(full);
214
- }
215
- }
216
- };
217
- visit(routesDir);
218
- return adopted;
136
+ const adopted = [];
137
+ const visit = (dir) => {
138
+ let entries;
139
+ try {
140
+ entries = (0, node_fs.readdirSync)(dir);
141
+ } catch (err) {
142
+ if (require_fs_errors.isFileMissing(err)) return;
143
+ throw err;
144
+ }
145
+ for (const entry of entries) {
146
+ const full = (0, node_path.join)(dir, entry);
147
+ let stat;
148
+ try {
149
+ stat = (0, node_fs.lstatSync)(full);
150
+ } catch (err) {
151
+ if (require_fs_errors.isFileMissing(err)) continue;
152
+ throw err;
153
+ }
154
+ if (stat.isDirectory()) visit(full);
155
+ else if (entry.endsWith(".ts") && fileStartsWithBanner(full)) adopted.push(full);
156
+ }
157
+ };
158
+ visit(routesDir);
159
+ return adopted;
219
160
  }
161
+ /**
162
+ * Generate the TanStack route(s) that mount the MCP server.
163
+ *
164
+ * Place this in your `vite.config.ts` plugins array. Emits during
165
+ * `configResolved` (so dev-server boot and the TanStack file-router both
166
+ * see the routes on the first request) and re-emits when the MCP entry
167
+ * file appears or disappears during dev.
168
+ *
169
+ * The `.lovable/mcp/manifest.json` snapshot is produced separately by the
170
+ * `lovable-mcp-extract-manifest` CLI (run by a host platform at build/commit
171
+ * time) — not by this plugin.
172
+ */
220
173
  function mcpPlugin(options = {}) {
221
- const mcpEntryOption = options.mcpEntry ?? "src/lib/mcp/index.ts";
222
- const routesDirOption = options.routesDir ?? "src/routes";
223
- const rawUrlPath = options.path ?? "/mcp";
224
- assertUrlPathShape(rawUrlPath);
225
- const routeFileName = options.routeFileName ?? deriveRouteFileName(rawUrlPath);
226
- const urlPath = canonicalUrlPath(rawUrlPath);
227
- const emitRestRoutes = options.restRoutes !== false;
228
- const emitProtectedResourceMetadataRoute = options.protectedResourceMetadataRoute !== false;
229
- if (options.metadataPath !== void 0) {
230
- if (!emitProtectedResourceMetadataRoute) {
231
- throw new Error(
232
- `@lovable.dev/mcp-js: metadataPath sets where the protected-resource metadata route is served, so it can't be combined with protectedResourceMetadataRoute: false.`
233
- );
234
- }
235
- assertMetadataPathShape(options.metadataPath);
236
- }
237
- const metadataUrlPath = canonicalUrlPath(options.metadataPath ?? OAUTH_PROTECTED_RESOURCE_METADATA_PATH);
238
- const injectedMetadataPath = emitProtectedResourceMetadataRoute ? metadataUrlPath : void 0;
239
- const trustForwardedHost = options.trustForwardedHost !== false;
240
- let projectRoot = process.cwd();
241
- let mcpEntry = (0, import_node_path.resolve)(projectRoot, mcpEntryOption);
242
- let {
243
- routesDir,
244
- mcpRouteFile,
245
- metadataRouteFile,
246
- listToolsRouteFile,
247
- invokeToolRouteFile,
248
- listToolsLiteral,
249
- invokeToolLiteral
250
- } = resolveAllRoutes(projectRoot, routesDirOption, routeFileName, urlPath, metadataUrlPath);
251
- const regenerate = () => {
252
- let mcpEntryExists = true;
253
- try {
254
- (0, import_node_fs.lstatSync)(mcpEntry);
255
- } catch (err) {
256
- if (!isFileMissing(err))
257
- throw err;
258
- mcpEntryExists = false;
259
- }
260
- const expected = /* @__PURE__ */ new Set();
261
- if (mcpEntryExists) {
262
- const routes = [
263
- { file: mcpRouteFile, routeLiteral: urlPath, handlerFactory: "createTanStackMcpHandler" }
264
- ];
265
- if (emitProtectedResourceMetadataRoute) {
266
- routes.push({
267
- file: metadataRouteFile,
268
- routeLiteral: metadataUrlPath,
269
- handlerFactory: "createTanStackOAuthProtectedResourceMetadataHandler"
270
- });
271
- }
272
- if (emitRestRoutes) {
273
- routes.push(
274
- {
275
- file: listToolsRouteFile,
276
- routeLiteral: listToolsLiteral,
277
- handlerFactory: "createTanStackListToolsHandler",
278
- spaFallbackNote: true
279
- },
280
- {
281
- file: invokeToolRouteFile,
282
- routeLiteral: invokeToolLiteral,
283
- handlerFactory: "createTanStackInvokeToolHandler",
284
- spaFallbackNote: true
285
- }
286
- );
287
- }
288
- for (const route of routes) {
289
- expected.add(route.file);
290
- writeIfChanged(
291
- route.file,
292
- buildRouteSource(route, urlPath, injectedMetadataPath, trustForwardedHost, mcpEntry, projectRoot)
293
- );
294
- }
295
- }
296
- for (const file of findAdoptedFiles(routesDir)) {
297
- if (!expected.has(file)) {
298
- try {
299
- (0, import_node_fs.unlinkSync)(file);
300
- } catch (err) {
301
- if (!isFileMissing(err))
302
- throw err;
303
- }
304
- }
305
- }
306
- };
307
- return {
308
- name: "@lovable.dev/mcp-js",
309
- // The extract CLI reads the resolved entry + URL path back through this
310
- // (via `resolveConfig().plugins`) so the manifest honors custom
311
- // `mcpEntry`/`path` instead of assuming the defaults. Getters because
312
- // `mcpEntry` is finalized in `configResolved`.
313
- api: {
314
- get mcpEntry() {
315
- return mcpEntry;
316
- },
317
- get urlPath() {
318
- return urlPath;
319
- }
320
- },
321
- configResolved(config) {
322
- projectRoot = config.root;
323
- mcpEntry = (0, import_node_path.resolve)(projectRoot, mcpEntryOption);
324
- ({
325
- routesDir,
326
- mcpRouteFile,
327
- metadataRouteFile,
328
- listToolsRouteFile,
329
- invokeToolRouteFile,
330
- listToolsLiteral,
331
- invokeToolLiteral
332
- } = resolveAllRoutes(projectRoot, routesDirOption, routeFileName, urlPath, metadataUrlPath));
333
- regenerate();
334
- },
335
- configureServer(server) {
336
- const onChange = (file) => {
337
- if (normalizePath(file) === normalizePath(mcpEntry)) {
338
- regenerate();
339
- }
340
- };
341
- server.watcher.on("add", onChange);
342
- server.watcher.on("change", onChange);
343
- server.watcher.on("unlink", onChange);
344
- server.watcher.once("close", () => {
345
- server.watcher.off("add", onChange);
346
- server.watcher.off("change", onChange);
347
- server.watcher.off("unlink", onChange);
348
- });
349
- },
350
- buildStart() {
351
- regenerate();
352
- }
353
- };
174
+ const mcpEntryOption = options.mcpEntry ?? "src/lib/mcp/index.ts";
175
+ const routesDirOption = options.routesDir ?? "src/routes";
176
+ const rawUrlPath = options.path ?? "/mcp";
177
+ assertUrlPathShape(rawUrlPath);
178
+ const routeFileName = options.routeFileName ?? deriveRouteFileName(rawUrlPath);
179
+ const urlPath = canonicalUrlPath(rawUrlPath);
180
+ const emitRestRoutes = options.restRoutes !== false;
181
+ const emitProtectedResourceMetadataRoute = options.protectedResourceMetadataRoute !== false;
182
+ if (options.metadataPath !== void 0) {
183
+ if (!emitProtectedResourceMetadataRoute) throw new Error(`@lovable.dev/mcp-js: metadataPath sets where the protected-resource metadata route is served, so it can't be combined with protectedResourceMetadataRoute: false.`);
184
+ assertMetadataPathShape(options.metadataPath);
185
+ }
186
+ const metadataUrlPath = canonicalUrlPath(options.metadataPath ?? "/.well-known/oauth-protected-resource");
187
+ const injectedMetadataPath = emitProtectedResourceMetadataRoute ? metadataUrlPath : void 0;
188
+ const trustForwardedHost = options.trustForwardedHost !== false;
189
+ let projectRoot = process.cwd();
190
+ let mcpEntry = (0, node_path.resolve)(projectRoot, mcpEntryOption);
191
+ let { routesDir, mcpRouteFile, metadataRouteFile, listToolsRouteFile, invokeToolRouteFile, listToolsLiteral, invokeToolLiteral } = resolveAllRoutes(projectRoot, routesDirOption, routeFileName, urlPath, metadataUrlPath);
192
+ const regenerate = () => {
193
+ let mcpEntryExists = true;
194
+ try {
195
+ (0, node_fs.lstatSync)(mcpEntry);
196
+ } catch (err) {
197
+ if (!require_fs_errors.isFileMissing(err)) throw err;
198
+ mcpEntryExists = false;
199
+ }
200
+ const expected = /* @__PURE__ */ new Set();
201
+ if (mcpEntryExists) {
202
+ const routes = [{
203
+ file: mcpRouteFile,
204
+ routeLiteral: urlPath,
205
+ handlerFactory: "createTanStackMcpHandler"
206
+ }];
207
+ if (emitProtectedResourceMetadataRoute) routes.push({
208
+ file: metadataRouteFile,
209
+ routeLiteral: metadataUrlPath,
210
+ handlerFactory: "createTanStackOAuthProtectedResourceMetadataHandler"
211
+ });
212
+ if (emitRestRoutes) routes.push({
213
+ file: listToolsRouteFile,
214
+ routeLiteral: listToolsLiteral,
215
+ handlerFactory: "createTanStackListToolsHandler",
216
+ spaFallbackNote: true
217
+ }, {
218
+ file: invokeToolRouteFile,
219
+ routeLiteral: invokeToolLiteral,
220
+ handlerFactory: "createTanStackInvokeToolHandler",
221
+ spaFallbackNote: true
222
+ });
223
+ for (const route of routes) {
224
+ expected.add(route.file);
225
+ writeIfChanged(route.file, buildRouteSource(route, urlPath, injectedMetadataPath, trustForwardedHost, mcpEntry, projectRoot));
226
+ }
227
+ }
228
+ for (const file of findAdoptedFiles(routesDir)) if (!expected.has(file)) try {
229
+ (0, node_fs.unlinkSync)(file);
230
+ } catch (err) {
231
+ if (!require_fs_errors.isFileMissing(err)) throw err;
232
+ }
233
+ };
234
+ return {
235
+ name: "@lovable.dev/mcp-js",
236
+ api: {
237
+ get mcpEntry() {
238
+ return mcpEntry;
239
+ },
240
+ get urlPath() {
241
+ return urlPath;
242
+ }
243
+ },
244
+ configResolved(config) {
245
+ projectRoot = config.root;
246
+ mcpEntry = (0, node_path.resolve)(projectRoot, mcpEntryOption);
247
+ ({routesDir, mcpRouteFile, metadataRouteFile, listToolsRouteFile, invokeToolRouteFile, listToolsLiteral, invokeToolLiteral} = resolveAllRoutes(projectRoot, routesDirOption, routeFileName, urlPath, metadataUrlPath));
248
+ regenerate();
249
+ },
250
+ configureServer(server) {
251
+ const onChange = (file) => {
252
+ if (normalizePath(file) === normalizePath(mcpEntry)) regenerate();
253
+ };
254
+ server.watcher.on("add", onChange);
255
+ server.watcher.on("change", onChange);
256
+ server.watcher.on("unlink", onChange);
257
+ server.watcher.once("close", () => {
258
+ server.watcher.off("add", onChange);
259
+ server.watcher.off("change", onChange);
260
+ server.watcher.off("unlink", onChange);
261
+ });
262
+ },
263
+ buildStart() {
264
+ regenerate();
265
+ }
266
+ };
354
267
  }
355
- var vite_default = mcpPlugin;
356
- // Annotate the CommonJS export names for ESM import in node:
357
- 0 && (module.exports = {
358
- assertMetadataPathShape,
359
- assertUrlPathShape,
360
- deriveRouteFileName,
361
- mcpPlugin
362
- });
268
+ //#endregion
269
+ exports.assertMetadataPathShape = assertMetadataPathShape;
270
+ exports.assertUrlPathShape = assertUrlPathShape;
271
+ exports.default = mcpPlugin;
272
+ exports.mcpPlugin = mcpPlugin;
273
+ exports.deriveRouteFileName = deriveRouteFileName;