@lovable.dev/mcp-js 3.3.0 → 3.4.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 (78) hide show
  1. package/README.internal.md +38 -12
  2. package/README.md +144 -12
  3. package/dist/THIRD_PARTY_NOTICES +75 -0
  4. package/dist/apps-CWG3rGhB.js +132 -0
  5. package/dist/apps-DyoDrwfi.cjs +185 -0
  6. package/dist/{authorize-r6jB-Gl2.d.cts → authorize--W1XtwdB.d.cts} +1 -1
  7. package/dist/{authorize-DxnyFNHv.d.ts → authorize-DpNYioXM.d.ts} +1 -1
  8. package/dist/{base-ff0LwIA2.d.ts → base-Ce9JYirF.d.ts} +1 -1
  9. package/dist/{base-CzPzbI3q.d.cts → base-qEX8YVcD.d.cts} +1 -1
  10. package/dist/cli/check-server.cjs +1 -1
  11. package/dist/cli/check-server.js +1 -1
  12. package/dist/cli/extract-manifest.cjs +1 -1
  13. package/dist/cli/extract-manifest.js +1 -1
  14. package/dist/{cors-Bjo6NPjV.cjs → cors-DcWb13LI.cjs} +1 -1
  15. package/dist/{cors-COjc9O73.js → cors-M68siADv.js} +1 -1
  16. package/dist/dist-CIu-UFye.js +6738 -0
  17. package/dist/dist-CqY2qXpc.cjs +6738 -0
  18. package/dist/{errors-D0UPHnG3.js → errors-CfaxXr2T.js} +25 -2
  19. package/dist/{errors-DSHt3Jqs.cjs → errors-xJ_7Su1K.cjs} +30 -1
  20. package/dist/index.cjs +2 -1
  21. package/dist/index.d.cts +6 -2
  22. package/dist/index.d.ts +6 -2
  23. package/dist/index.js +2 -2
  24. package/dist/{io-CQ60Nc2J.d.ts → io-BEpyfk4G.d.ts} +1 -1
  25. package/dist/{io-DTz7efSK.js → io-CICYQJSM.js} +13 -3
  26. package/dist/{io-Dzy5Bu6h.cjs → io-DGeqWc6m.cjs} +12 -2
  27. package/dist/{io-DnRCu_HX.d.cts → io-Di5ljvZY.d.cts} +1 -1
  28. package/dist/{mcp-DIR9MCwQ.js → mcp-BT9dcts8.js} +117 -51
  29. package/dist/{mcp-Buu1riaY.cjs → mcp-DAUFwQ80.cjs} +116 -50
  30. package/dist/mcp-app.d.ts +4 -0
  31. package/dist/{package-DL4uNmL0.cjs → package-Cu_ynl05.cjs} +1 -1
  32. package/dist/{package-DV8zBoEy.js → package-N4he-Z_i.js} +1 -1
  33. package/dist/protocols/mcp/index.cjs +1 -1
  34. package/dist/protocols/mcp/index.d.cts +3 -3
  35. package/dist/protocols/mcp/index.d.ts +3 -3
  36. package/dist/protocols/mcp/index.js +1 -1
  37. package/dist/protocols/oauth-metadata.cjs +1 -1
  38. package/dist/protocols/oauth-metadata.d.cts +3 -3
  39. package/dist/protocols/oauth-metadata.d.ts +3 -3
  40. package/dist/protocols/oauth-metadata.js +1 -1
  41. package/dist/src-D7RtXSV0.cjs +311 -0
  42. package/dist/src-sWQwyLwS.js +310 -0
  43. package/dist/stacks/supabase/index.cjs +2 -2
  44. package/dist/stacks/supabase/index.d.cts +1 -1
  45. package/dist/stacks/supabase/index.d.ts +1 -1
  46. package/dist/stacks/supabase/index.js +2 -2
  47. package/dist/stacks/supabase/vite.cjs +10 -1
  48. package/dist/stacks/supabase/vite.d.cts +1 -1
  49. package/dist/stacks/supabase/vite.d.ts +1 -1
  50. package/dist/stacks/supabase/vite.js +21 -12
  51. package/dist/stacks/tanstack/index.cjs +33 -2
  52. package/dist/stacks/tanstack/index.d.cts +7 -4
  53. package/dist/stacks/tanstack/index.d.ts +7 -4
  54. package/dist/stacks/tanstack/index.js +33 -2
  55. package/dist/stacks/tanstack/vite.cjs +995 -15
  56. package/dist/stacks/tanstack/vite.d.cts +1 -1
  57. package/dist/stacks/tanstack/vite.d.ts +1 -1
  58. package/dist/stacks/tanstack/vite.js +1001 -21
  59. package/dist/testing/browser/LICENSE.ext-apps +218 -0
  60. package/dist/testing/browser/host.ts +151 -0
  61. package/dist/testing/browser/sandbox.ts +137 -0
  62. package/dist/testing/browser.cjs +382 -0
  63. package/dist/testing/browser.d.cts +46 -0
  64. package/dist/testing/browser.d.ts +46 -0
  65. package/dist/testing/browser.js +381 -0
  66. package/dist/testing/index.cjs +2 -1
  67. package/dist/testing/index.d.cts +2 -1
  68. package/dist/testing/index.d.ts +2 -1
  69. package/dist/testing/index.js +2 -1
  70. package/dist/testing/server.cjs +36 -0
  71. package/dist/testing/server.d.cts +6 -2
  72. package/dist/testing/server.d.ts +6 -2
  73. package/dist/testing/server.js +36 -1
  74. package/dist/{tool-result-DcNioyiI.js → tool-result-BG-HsSQu.js} +8 -1
  75. package/dist/{tool-result-rU-PpNNi.cjs → tool-result-BQcr7VV-.cjs} +8 -1
  76. package/dist/{types-BtoYHhdt.d.cts → types-B_dVw-zM.d.cts} +59 -1
  77. package/dist/{types-BtoYHhdt.d.ts → types-B_dVw-zM.d.ts} +59 -1
  78. package/package.json +67 -26
@@ -1,4 +1,4 @@
1
- import { t as McpPluginApi } from "../../io-CQ60Nc2J.js";
1
+ import { t as McpPluginApi } from "../../io-BEpyfk4G.js";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/stacks/supabase/vite.d.ts
4
4
  interface McpPluginOptions {
@@ -1,10 +1,10 @@
1
- import { t as version } from "../../package-DV8zBoEy.js";
1
+ import { t as version$1 } from "../../package-N4he-Z_i.js";
2
2
  import { a as isFileMissing, i as readSupabaseProjectRef, n as skillImportEsbuildPlugin, t as isSkillImportInput } from "../../hooks-BOdDe251.js";
3
3
  import { n as assertFunctionName, t as FUNCTIONS_MOUNT_PREFIX } from "../../paths-IS65L6TA.js";
4
4
  import { lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, unlinkSync, writeFileSync } from "node:fs";
5
5
  import { dirname, join, relative, resolve, sep } from "node:path";
6
6
  import { loadEnv } from "vite";
7
- import { build } from "esbuild";
7
+ import { build as build$1 } from "esbuild";
8
8
  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.";
9
9
  const GENERATED_JSON_MARKER_KEY = "_lovableMcpGenerated";
10
10
  function fileExists(path) {
@@ -57,10 +57,10 @@ function readProjectDependencyVersions(projectRoot) {
57
57
  function npmSpecifierFor(bare, versions) {
58
58
  const pkg = bare.startsWith("@") ? bare.split("/").slice(0, 2).join("/") : bare.split("/")[0];
59
59
  const subpath = bare.slice(pkg.length);
60
- if (pkg === "@lovable.dev/mcp-js") return `npm:${pkg}@${version}${subpath}`;
60
+ if (pkg === "@lovable.dev/mcp-js") return `npm:${pkg}@${version$1}${subpath}`;
61
61
  const range = versions[pkg];
62
- const version$1 = range && /^[\dv^~>=]|^latest$/.test(range) ? range : void 0;
63
- return version$1 ? `npm:${pkg}@${version$1}${subpath}` : `npm:${pkg}${subpath}`;
62
+ const version = range && /^[\dv^~>=]|^latest$/.test(range) ? range : void 0;
63
+ return version ? `npm:${pkg}@${version}${subpath}` : `npm:${pkg}${subpath}`;
64
64
  }
65
65
  function externalizeBareAsNpm(versions) {
66
66
  return {
@@ -116,6 +116,14 @@ function applyViteAliases(importee, aliases) {
116
116
  if (find.test(importee)) return importee.replace(find, replacement);
117
117
  } else if (importee === find || importee.startsWith(find + "/")) return replacement + importee.slice(find.length);
118
118
  }
119
+ function rejectMcpAppImports() {
120
+ return {
121
+ name: "lovable-mcp-reject-mcp-app",
122
+ setup(pluginBuild) {
123
+ pluginBuild.onResolve({ filter: /\?mcp-app$/ }, (args) => ({ errors: [{ text: `MCP Apps are not supported on the Supabase stack (${JSON.stringify(args.path)}). Remove the \`ui\` option and the import, or host this MCP server on the TanStack stack.` }] }));
124
+ }
125
+ };
126
+ }
119
127
  function resolveViteAliases(aliases) {
120
128
  return {
121
129
  name: "lovable-mcp-resolve-vite-aliases",
@@ -147,7 +155,7 @@ async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName, optio
147
155
  const wrapper = `import mcp from ${JSON.stringify(mcpEntryAbs)};\nimport { createSupabaseHandler } from "@lovable.dev/mcp-js/stacks/supabase";\nDeno.serve(createSupabaseHandler(mcp, { functionName: ${JSON.stringify(functionName)} }));\n`;
148
156
  const skillFiles = [];
149
157
  const skillDirs = [];
150
- const result = await build({
158
+ const result = await build$1({
151
159
  stdin: {
152
160
  contents: wrapper,
153
161
  resolveDir: projectRoot,
@@ -164,6 +172,7 @@ async function bundleFunctionEntry(projectRoot, mcpEntryAbs, functionName, optio
164
172
  logLevel: "silent",
165
173
  define: importMetaEnvDefines(options.inlineEnv),
166
174
  plugins: [
175
+ rejectMcpAppImports(),
167
176
  skillImportEsbuildPlugin((compilation) => {
168
177
  skillFiles.push(...compilation.watchFiles);
169
178
  skillDirs.push(...compilation.watchDirs);
@@ -256,7 +265,7 @@ function cleanupOrphans(functionDir, expected, removed) {
256
265
  }
257
266
  //#endregion
258
267
  //#region src/stacks/supabase/vite.ts
259
- function normalizePath(p) {
268
+ function normalizePath$1(p) {
260
269
  return p.split(sep).join("/");
261
270
  }
262
271
  function productionImportMetaEnv(config) {
@@ -318,13 +327,13 @@ function mcpPlugin(options = {}) {
318
327
  inlineEnv,
319
328
  aliases,
320
329
  onSkillDirectory(directory) {
321
- const normalized = normalizePath(directory);
330
+ const normalized = normalizePath$1(directory);
322
331
  if (!watchedSkillDirs.includes(normalized)) watchedSkillDirs.push(normalized);
323
332
  devServer?.watcher.add(directory);
324
333
  }
325
334
  });
326
- watchedInputs = new Set(inputs.map(normalizePath));
327
- watchedSkillDirs = (skillDirs ?? []).map(normalizePath);
335
+ watchedInputs = new Set(inputs.map(normalizePath$1));
336
+ watchedSkillDirs = (skillDirs ?? []).map(normalizePath$1);
328
337
  };
329
338
  return {
330
339
  name: "@lovable.dev/mcp-js/supabase",
@@ -348,9 +357,9 @@ function mcpPlugin(options = {}) {
348
357
  devServer = server;
349
358
  server.watcher.add(watchedSkillDirs);
350
359
  const onChange = (file) => {
351
- const norm = normalizePath(file);
360
+ const norm = normalizePath$1(file);
352
361
  const inSkillDir = watchedSkillDirs.some((dir) => norm.startsWith(`${dir}/`));
353
- if (norm !== normalizePath(mcpEntryAbs) && !watchedInputs.has(norm) && !inSkillDir) return;
362
+ if (norm !== normalizePath$1(mcpEntryAbs) && !watchedInputs.has(norm) && !inSkillDir) return;
354
363
  regenerate().catch((err) => {
355
364
  const message = `[@lovable.dev/mcp-js] failed to regenerate the Supabase function: ${err instanceof Error ? err.message : String(err)}`;
356
365
  if (server.config?.logger?.error) server.config.logger.error(message);
@@ -1,10 +1,29 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_cors = require("../../cors-Bjo6NPjV.cjs");
3
- const require_mcp = require("../../mcp-Buu1riaY.cjs");
2
+ const require_logger = require("../../logger-C-Hdu57K.cjs");
3
+ const require_cors = require("../../cors-DcWb13LI.cjs");
4
+ const require_mcp = require("../../mcp-DAUFwQ80.cjs");
4
5
  const require_protocols_oauth_metadata = require("../../protocols/oauth-metadata.cjs");
5
6
  const require_forwarded = require("../../forwarded-B37IdmMX.cjs");
6
7
  //#region src/stacks/tanstack/handlers.ts
7
8
  const STACK = "tanstack";
9
+ function resolveHandler(source, create, errorResponse) {
10
+ let cached;
11
+ return async (ctx) => {
12
+ let handler;
13
+ try {
14
+ const { default: mcp } = await source();
15
+ if (cached?.mcp !== mcp) cached = {
16
+ mcp,
17
+ handler: create(mcp)
18
+ };
19
+ handler = cached.handler;
20
+ } catch {
21
+ require_logger.log.error("mcp.route_load_error", { outcome: "500 internal error" });
22
+ return require_cors.finalizeWireResponse(ctx.request, errorResponse());
23
+ }
24
+ return handler(ctx);
25
+ };
26
+ }
8
27
  function getScheduleBackground(request) {
9
28
  const waitUntil = request.waitUntil;
10
29
  if (typeof waitUntil !== "function") return void 0;
@@ -15,6 +34,17 @@ function getScheduleBackground(request) {
15
34
  * (`POST /mcp`). Assignable directly to a route's `ANY` handler.
16
35
  */
17
36
  function createTanStackMcpHandler(mcp, options = {}) {
37
+ if (typeof mcp === "function") return resolveHandler(mcp, (definition) => createTanStackMcpHandler(definition, options), () => Response.json({
38
+ jsonrpc: "2.0",
39
+ id: null,
40
+ error: {
41
+ code: -32603,
42
+ message: "internal error"
43
+ }
44
+ }, {
45
+ status: 500,
46
+ headers: { "Cache-Control": "no-store" }
47
+ }));
18
48
  const handler = require_mcp.createMcpProtocolHandler(mcp, options);
19
49
  return ({ request }) => handler(require_forwarded.applyForwardedOrigin(request, options), require_cors.createRecorderForRuntime(mcp, { stack: STACK }), getScheduleBackground(request));
20
50
  }
@@ -23,6 +53,7 @@ function createTanStackMcpHandler(mcp, options = {}) {
23
53
  * When the MCP definition has no OAuth auth config the handler returns 404.
24
54
  */
25
55
  function createTanStackOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
56
+ if (typeof mcp === "function") return resolveHandler(mcp, (definition) => createTanStackOAuthProtectedResourceMetadataHandler(definition, options), require_cors.oauthConfigurationErrorResponse);
26
57
  const handler = require_protocols_oauth_metadata.createOAuthProtectedResourceMetadataHandler(mcp, options);
27
58
  return ({ request }) => handler(require_forwarded.applyForwardedOrigin(request, options), require_cors.createRecorderForRuntime(mcp, { stack: STACK }), getScheduleBackground(request));
28
59
  }
@@ -1,5 +1,5 @@
1
- import { h as McpDefinition } from "../../types-BtoYHhdt.cjs";
2
- import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-r6jB-Gl2.cjs";
1
+ import { y as McpDefinition } from "../../types-B_dVw-zM.cjs";
2
+ import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize--W1XtwdB.cjs";
3
3
  //#region src/stacks/tanstack/handlers.d.ts
4
4
  interface TanStackRequest extends Request {
5
5
  waitUntil?: ScheduleBackground;
@@ -9,15 +9,18 @@ interface TanStackRouteCtx {
9
9
  }
10
10
  type TanStackMcpHandler = (ctx: TanStackRouteCtx) => Promise<Response>;
11
11
  type TanStackOAuthProtectedResourceMetadataHandler = (ctx: TanStackRouteCtx) => Promise<Response>;
12
+ type McpSource = McpDefinition | (() => Promise<{
13
+ default: McpDefinition;
14
+ }>);
12
15
  /**
13
16
  * Build a TanStack Start handler for the MCP protocol endpoint
14
17
  * (`POST /mcp`). Assignable directly to a route's `ANY` handler.
15
18
  */
16
- declare function createTanStackMcpHandler(mcp: McpDefinition, options?: McpRuntimeOptions): TanStackMcpHandler;
19
+ declare function createTanStackMcpHandler(mcp: McpSource, options?: McpRuntimeOptions): TanStackMcpHandler;
17
20
  /**
18
21
  * Build a TanStack Start handler for `GET /.well-known/oauth-protected-resource`.
19
22
  * When the MCP definition has no OAuth auth config the handler returns 404.
20
23
  */
21
- declare function createTanStackOAuthProtectedResourceMetadataHandler(mcp: McpDefinition, options?: McpRuntimeOptions): TanStackOAuthProtectedResourceMetadataHandler;
24
+ declare function createTanStackOAuthProtectedResourceMetadataHandler(mcp: McpSource, options?: McpRuntimeOptions): TanStackOAuthProtectedResourceMetadataHandler;
22
25
  //#endregion
23
26
  export { type TanStackMcpHandler, type TanStackOAuthProtectedResourceMetadataHandler, createTanStackMcpHandler, createTanStackOAuthProtectedResourceMetadataHandler };
@@ -1,5 +1,5 @@
1
- import { h as McpDefinition } from "../../types-BtoYHhdt.js";
2
- import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-DxnyFNHv.js";
1
+ import { y as McpDefinition } from "../../types-B_dVw-zM.js";
2
+ import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-DpNYioXM.js";
3
3
  //#region src/stacks/tanstack/handlers.d.ts
4
4
  interface TanStackRequest extends Request {
5
5
  waitUntil?: ScheduleBackground;
@@ -9,15 +9,18 @@ interface TanStackRouteCtx {
9
9
  }
10
10
  type TanStackMcpHandler = (ctx: TanStackRouteCtx) => Promise<Response>;
11
11
  type TanStackOAuthProtectedResourceMetadataHandler = (ctx: TanStackRouteCtx) => Promise<Response>;
12
+ type McpSource = McpDefinition | (() => Promise<{
13
+ default: McpDefinition;
14
+ }>);
12
15
  /**
13
16
  * Build a TanStack Start handler for the MCP protocol endpoint
14
17
  * (`POST /mcp`). Assignable directly to a route's `ANY` handler.
15
18
  */
16
- declare function createTanStackMcpHandler(mcp: McpDefinition, options?: McpRuntimeOptions): TanStackMcpHandler;
19
+ declare function createTanStackMcpHandler(mcp: McpSource, options?: McpRuntimeOptions): TanStackMcpHandler;
17
20
  /**
18
21
  * Build a TanStack Start handler for `GET /.well-known/oauth-protected-resource`.
19
22
  * When the MCP definition has no OAuth auth config the handler returns 404.
20
23
  */
21
- declare function createTanStackOAuthProtectedResourceMetadataHandler(mcp: McpDefinition, options?: McpRuntimeOptions): TanStackOAuthProtectedResourceMetadataHandler;
24
+ declare function createTanStackOAuthProtectedResourceMetadataHandler(mcp: McpSource, options?: McpRuntimeOptions): TanStackOAuthProtectedResourceMetadataHandler;
22
25
  //#endregion
23
26
  export { type TanStackMcpHandler, type TanStackOAuthProtectedResourceMetadataHandler, createTanStackMcpHandler, createTanStackOAuthProtectedResourceMetadataHandler };
@@ -1,9 +1,28 @@
1
- import { c as createRecorderForRuntime } from "../../cors-COjc9O73.js";
2
- import { t as createMcpProtocolHandler } from "../../mcp-DIR9MCwQ.js";
1
+ import { i as log } from "../../logger-CpLgYbCG.js";
2
+ import { a as oauthConfigurationErrorResponse, c as createRecorderForRuntime, p as finalizeWireResponse } from "../../cors-M68siADv.js";
3
+ import { t as createMcpProtocolHandler } from "../../mcp-BT9dcts8.js";
3
4
  import { createOAuthProtectedResourceMetadataHandler } from "../../protocols/oauth-metadata.js";
4
5
  import { t as applyForwardedOrigin } from "../../forwarded-BBXvFeh6.js";
5
6
  //#region src/stacks/tanstack/handlers.ts
6
7
  const STACK = "tanstack";
8
+ function resolveHandler(source, create, errorResponse) {
9
+ let cached;
10
+ return async (ctx) => {
11
+ let handler;
12
+ try {
13
+ const { default: mcp } = await source();
14
+ if (cached?.mcp !== mcp) cached = {
15
+ mcp,
16
+ handler: create(mcp)
17
+ };
18
+ handler = cached.handler;
19
+ } catch {
20
+ log.error("mcp.route_load_error", { outcome: "500 internal error" });
21
+ return finalizeWireResponse(ctx.request, errorResponse());
22
+ }
23
+ return handler(ctx);
24
+ };
25
+ }
7
26
  function getScheduleBackground(request) {
8
27
  const waitUntil = request.waitUntil;
9
28
  if (typeof waitUntil !== "function") return void 0;
@@ -14,6 +33,17 @@ function getScheduleBackground(request) {
14
33
  * (`POST /mcp`). Assignable directly to a route's `ANY` handler.
15
34
  */
16
35
  function createTanStackMcpHandler(mcp, options = {}) {
36
+ if (typeof mcp === "function") return resolveHandler(mcp, (definition) => createTanStackMcpHandler(definition, options), () => Response.json({
37
+ jsonrpc: "2.0",
38
+ id: null,
39
+ error: {
40
+ code: -32603,
41
+ message: "internal error"
42
+ }
43
+ }, {
44
+ status: 500,
45
+ headers: { "Cache-Control": "no-store" }
46
+ }));
17
47
  const handler = createMcpProtocolHandler(mcp, options);
18
48
  return ({ request }) => handler(applyForwardedOrigin(request, options), createRecorderForRuntime(mcp, { stack: STACK }), getScheduleBackground(request));
19
49
  }
@@ -22,6 +52,7 @@ function createTanStackMcpHandler(mcp, options = {}) {
22
52
  * When the MCP definition has no OAuth auth config the handler returns 404.
23
53
  */
24
54
  function createTanStackOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
55
+ if (typeof mcp === "function") return resolveHandler(mcp, (definition) => createTanStackOAuthProtectedResourceMetadataHandler(definition, options), oauthConfigurationErrorResponse);
25
56
  const handler = createOAuthProtectedResourceMetadataHandler(mcp, options);
26
57
  return ({ request }) => handler(applyForwardedOrigin(request, options), createRecorderForRuntime(mcp, { stack: STACK }), getScheduleBackground(request));
27
58
  }