@lovable.dev/mcp-js 0.21.1-rc.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authorize-BMeXd_Sh.d.ts +25 -0
- package/dist/base-CM-KCpp6.d.ts +28 -0
- package/dist/chunk-4EHZUUS5.js +141 -0
- package/dist/chunk-6DXGZZA4.js +6 -0
- package/dist/chunk-6KNM7RGD.js +79 -0
- package/dist/chunk-6QFZYYUV.js +11 -0
- package/dist/chunk-EOFPMSND.js +6 -0
- package/dist/chunk-H37EB22A.js +125 -0
- package/dist/chunk-MA5H6PSF.js +46 -0
- package/dist/chunk-P43FIUMZ.js +114 -0
- package/dist/chunk-RK62EMPY.js +741 -0
- package/dist/chunk-RLE4UE63.js +58 -0
- package/dist/chunk-UQK5UO6C.js +26 -0
- package/dist/chunk-XQWJN6DC.js +14 -0
- package/dist/chunk-Y3ZFPEQH.js +8 -0
- package/dist/cli/extract-manifest.cjs +201 -116
- package/dist/cli/extract-manifest.d.cts +1 -1
- package/dist/cli/extract-manifest.d.ts +1 -1
- package/dist/cli/extract-manifest.js +156 -117
- package/dist/index.cjs +329 -129
- package/dist/index.d.cts +26 -26
- package/dist/index.d.ts +26 -26
- package/dist/index.js +177 -118
- package/dist/{io-CS4UL6_A.d.ts → io-D4srzRKc.d.ts} +4 -6
- package/dist/protocols/mcp/index.cjs +750 -3
- package/dist/protocols/mcp/index.d.cts +7 -6
- package/dist/protocols/mcp/index.d.ts +7 -6
- package/dist/protocols/mcp/index.js +12 -2
- package/dist/protocols/oauth-metadata.cjs +539 -48
- package/dist/protocols/oauth-metadata.d.cts +6 -5
- package/dist/protocols/oauth-metadata.d.ts +6 -5
- package/dist/protocols/oauth-metadata.js +10 -52
- package/dist/protocols/rest/index.cjs +843 -5
- package/dist/protocols/rest/index.d.cts +10 -7
- package/dist/protocols/rest/index.d.ts +10 -7
- package/dist/protocols/rest/index.js +16 -3
- package/dist/stacks/supabase/index.cjs +1318 -76
- package/dist/stacks/supabase/index.d.cts +30 -29
- package/dist/stacks/supabase/index.d.ts +30 -29
- package/dist/stacks/supabase/index.js +89 -73
- package/dist/stacks/supabase/vite.cjs +287 -258
- package/dist/stacks/supabase/vite.d.cts +24 -24
- package/dist/stacks/supabase/vite.d.ts +24 -24
- package/dist/stacks/supabase/vite.js +252 -252
- package/dist/stacks/tanstack/index.cjs +1272 -42
- package/dist/stacks/tanstack/index.d.cts +9 -8
- package/dist/stacks/tanstack/index.d.ts +9 -8
- package/dist/stacks/tanstack/index.js +41 -36
- package/dist/stacks/tanstack/vite.cjs +312 -223
- package/dist/stacks/tanstack/vite.d.cts +81 -80
- package/dist/stacks/tanstack/vite.d.ts +81 -80
- package/dist/stacks/tanstack/vite.js +282 -216
- package/dist/types-qqrmJ736.d.ts +321 -0
- package/package.json +28 -71
- package/dist/authorize-CumVyk7p.d.cts +0 -27
- package/dist/authorize-D6p4-9_D.d.ts +0 -27
- package/dist/base-CoIFvAmS.d.cts +0 -26
- package/dist/base-CoIFvAmS.d.ts +0 -26
- package/dist/content-D5LJAHyM.js +0 -12
- package/dist/content-NCYIGgOb.cjs +0 -17
- package/dist/context-BweeEcoA.cjs +0 -56
- package/dist/context-CIpPzN7P.js +0 -51
- package/dist/cors-B7CTXIHD.js +0 -829
- package/dist/cors-BebjKPrc.cjs +0 -912
- package/dist/forwarded--h4efJy-.js +0 -43
- package/dist/forwarded-Pi8Hs5Ps.cjs +0 -48
- package/dist/fs-errors-CWNzOV75.cjs +0 -11
- package/dist/fs-errors-PA2t1TIp.js +0 -6
- package/dist/io-CbbUbPY3.d.cts +0 -15
- package/dist/list-tools-CBCuS1Tv.cjs +0 -57
- package/dist/list-tools-CsWgiRy1.d.ts +0 -8
- package/dist/list-tools-CtZHOuPv.d.cts +0 -8
- package/dist/list-tools-D75RGtgs.js +0 -46
- package/dist/logger-2OXtfiIW.js +0 -141
- package/dist/logger-BqPOa_E1.cjs +0 -194
- package/dist/mcp-Cdj0AYst.cjs +0 -123
- package/dist/mcp-GngXbcqN.js +0 -118
- package/dist/metadata-path-CAkNcfyY.js +0 -12
- package/dist/metadata-path-zd7NSNoa.cjs +0 -17
- package/dist/package-7EUptuSJ.js +0 -4
- package/dist/package-BwCGVRcB.cjs +0 -9
- package/dist/paths-IS65L6TA.js +0 -7
- package/dist/paths-OP318a6c.cjs +0 -18
- package/dist/rest-CXH6-zv9.js +0 -113
- package/dist/rest-CyV8LHeB.cjs +0 -118
- package/dist/types-BYdYYTjk.d.cts +0 -321
- package/dist/types-BYdYYTjk.d.ts +0 -321
|
@@ -1,89 +1,140 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/stacks/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
|
|
4
28
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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.";
|
|
11
43
|
function normalizePath(p) {
|
|
12
|
-
|
|
44
|
+
return p.split(import_node_path.sep).join("/");
|
|
13
45
|
}
|
|
14
46
|
function assertContains(parent, child, label) {
|
|
15
|
-
|
|
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
|
+
}
|
|
16
50
|
}
|
|
17
51
|
function wellKnownRouteFile(routesDir, urlPath) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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);
|
|
23
58
|
}
|
|
24
59
|
function resolveRestRoutes(routesDir, mcpUrlPath) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
};
|
|
34
69
|
}
|
|
35
70
|
function resolveAllRoutes(projectRoot, routesDirOption, routeFileName, mcpUrlPath, metadataUrlPath) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
routesDir,
|
|
47
|
-
mcpRouteFile,
|
|
48
|
-
metadataRouteFile,
|
|
49
|
-
...rest
|
|
50
|
-
};
|
|
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 };
|
|
51
81
|
}
|
|
52
82
|
function assertUrlPathShape(urlPath) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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;
|
|
59
97
|
}
|
|
60
98
|
function deriveRouteFileName(urlPath) {
|
|
61
|
-
|
|
99
|
+
return `${assertUrlPathShape(urlPath)}.ts`;
|
|
62
100
|
}
|
|
63
101
|
function assertMetadataPathShape(metadataPath) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
+
}
|
|
70
118
|
}
|
|
71
119
|
function canonicalUrlPath(urlPath) {
|
|
72
|
-
|
|
120
|
+
return `/${urlPath.replace(/^\/+/, "").replace(/\/+$/, "")}`;
|
|
73
121
|
}
|
|
74
122
|
function relativeImportSpecifier(routeFile, target) {
|
|
75
|
-
|
|
76
|
-
|
|
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}`;
|
|
77
126
|
}
|
|
78
127
|
function buildRouteSource(route, resourcePath, metadataPath, trustForwardedHost, mcpEntry, projectRoot) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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}
|
|
87
138
|
// route: ${route.routeLiteral}
|
|
88
139
|
// emitted to: ${routeRel}
|
|
89
140
|
|
|
@@ -102,172 +153,210 @@ ${note} ANY: ${route.handlerFactory}(mcp, ${runtimeOptions}),
|
|
|
102
153
|
});
|
|
103
154
|
`;
|
|
104
155
|
}
|
|
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
|
-
*/
|
|
109
156
|
function hasGeneratedBanner(content) {
|
|
110
|
-
|
|
157
|
+
return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
|
|
111
158
|
}
|
|
112
159
|
function writeIfChanged(file, content) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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;
|
|
126
179
|
}
|
|
127
180
|
function fileStartsWithBanner(file) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
+
}
|
|
134
188
|
}
|
|
135
189
|
function findAdoptedFiles(routesDir) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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;
|
|
160
219
|
}
|
|
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
|
-
*/
|
|
173
220
|
function mcpPlugin(options = {}) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
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
|
+
};
|
|
267
354
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
exports
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
+
});
|