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