@lovable.dev/mcp-js 0.22.1 → 0.22.2-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.
- package/dist/authorize-CumVyk7p.d.cts +27 -0
- package/dist/authorize-D6p4-9_D.d.ts +27 -0
- package/dist/base-DCe0kP79.d.cts +29 -0
- package/dist/base-DCe0kP79.d.ts +29 -0
- package/dist/cli/extract-manifest.cjs +116 -201
- package/dist/cli/extract-manifest.d.cts +1 -1
- package/dist/cli/extract-manifest.d.ts +1 -1
- package/dist/cli/extract-manifest.js +117 -156
- package/dist/content-D5LJAHyM.js +12 -0
- package/dist/content-NCYIGgOb.cjs +17 -0
- package/dist/context-BweeEcoA.cjs +56 -0
- package/dist/context-CIpPzN7P.js +51 -0
- package/dist/cors-C2n2LxrC.js +830 -0
- package/dist/cors-Cga2PWEg.cjs +913 -0
- package/dist/forwarded--h4efJy-.js +43 -0
- package/dist/forwarded-Pi8Hs5Ps.cjs +48 -0
- package/dist/fs-errors-CWNzOV75.cjs +11 -0
- package/dist/fs-errors-PA2t1TIp.js +6 -0
- package/dist/index.cjs +129 -329
- package/dist/index.d.cts +26 -26
- package/dist/index.d.ts +26 -26
- package/dist/index.js +118 -177
- package/dist/{io-D4srzRKc.d.ts → io-CfSPxeBN.d.ts} +6 -4
- package/dist/io-DPYvBqET.d.cts +15 -0
- package/dist/list-tools-07OV14rK.cjs +57 -0
- package/dist/list-tools-B4TTPEl1.d.cts +8 -0
- package/dist/list-tools-I8Hvub9P.js +46 -0
- package/dist/list-tools-bh6-eqZM.d.ts +8 -0
- package/dist/logger-2OXtfiIW.js +141 -0
- package/dist/logger-BqPOa_E1.cjs +194 -0
- package/dist/mcp-B6z5Givq.js +123 -0
- package/dist/mcp-DLv_c1O5.cjs +128 -0
- package/dist/metadata-path-CAkNcfyY.js +12 -0
- package/dist/metadata-path-zd7NSNoa.cjs +17 -0
- package/dist/package-CxQcGWdU.cjs +9 -0
- package/dist/package-xS6mk-b_.js +4 -0
- package/dist/paths-IS65L6TA.js +7 -0
- package/dist/paths-OP318a6c.cjs +18 -0
- package/dist/protocols/mcp/index.cjs +3 -750
- package/dist/protocols/mcp/index.d.cts +6 -7
- package/dist/protocols/mcp/index.d.ts +6 -7
- package/dist/protocols/mcp/index.js +2 -12
- package/dist/protocols/oauth-metadata.cjs +48 -539
- package/dist/protocols/oauth-metadata.d.cts +5 -6
- package/dist/protocols/oauth-metadata.d.ts +5 -6
- package/dist/protocols/oauth-metadata.js +52 -10
- package/dist/protocols/rest/index.cjs +5 -843
- package/dist/protocols/rest/index.d.cts +7 -10
- package/dist/protocols/rest/index.d.ts +7 -10
- package/dist/protocols/rest/index.js +3 -16
- package/dist/rest-CggWx00c.js +117 -0
- package/dist/rest-DxhK7-3b.cjs +122 -0
- package/dist/stacks/supabase/index.cjs +76 -1318
- package/dist/stacks/supabase/index.d.cts +29 -30
- package/dist/stacks/supabase/index.d.ts +29 -30
- package/dist/stacks/supabase/index.js +73 -89
- package/dist/stacks/supabase/vite.cjs +258 -287
- 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 +42 -1272
- package/dist/stacks/tanstack/index.d.cts +8 -9
- package/dist/stacks/tanstack/index.d.ts +8 -9
- package/dist/stacks/tanstack/index.js +36 -41
- package/dist/stacks/tanstack/vite.cjs +223 -312
- package/dist/stacks/tanstack/vite.d.cts +80 -81
- package/dist/stacks/tanstack/vite.d.ts +80 -81
- package/dist/stacks/tanstack/vite.js +216 -282
- package/dist/types-BYdYYTjk.d.cts +321 -0
- package/dist/types-BYdYYTjk.d.ts +321 -0
- package/package.json +4 -4
- package/dist/authorize-BMeXd_Sh.d.ts +0 -25
- package/dist/base-CM-KCpp6.d.ts +0 -28
- package/dist/chunk-5HVSJCKE.js +0 -114
- package/dist/chunk-6DXGZZA4.js +0 -6
- package/dist/chunk-6QFZYYUV.js +0 -11
- package/dist/chunk-6SZOFKGH.js +0 -58
- package/dist/chunk-H37EB22A.js +0 -125
- package/dist/chunk-IFDWUM7L.js +0 -741
- package/dist/chunk-IXZIFYO6.js +0 -79
- package/dist/chunk-MA5H6PSF.js +0 -46
- package/dist/chunk-TJN33K5U.js +0 -141
- package/dist/chunk-UQK5UO6C.js +0 -26
- package/dist/chunk-XQWJN6DC.js +0 -14
- package/dist/chunk-Y3ZFPEQH.js +0 -8
- package/dist/chunk-ZQXSWTPU.js +0 -6
- package/dist/types-qqrmJ736.d.ts +0 -321
|
@@ -1,140 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
12
|
+
return p.split(node_path.sep).join("/");
|
|
45
13
|
}
|
|
46
14
|
function assertContains(parent, child, label) {
|
|
47
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
61
|
+
return `${assertUrlPathShape(urlPath)}.ts`;
|
|
100
62
|
}
|
|
101
63
|
function assertMetadataPathShape(metadataPath) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
72
|
+
return `/${urlPath.replace(/^\/+/, "").replace(/\/+$/, "")}`;
|
|
121
73
|
}
|
|
122
74
|
function relativeImportSpecifier(routeFile, target) {
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
110
|
+
return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
|
|
158
111
|
}
|
|
159
112
|
function writeIfChanged(file, content) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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;
|