@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,5 +1,6 @@
1
1
  import { o as parseSafeUrl, s as trimTrailingSlash, u as resolveMetricsConfig } from "./logger-CpLgYbCG.js";
2
2
  import { n as validateSkills } from "./format-DKEuO8Tn.js";
3
+ import { c as freezeApp, i as assertAppDefinitionInput, l as freezeToolUi, o as assertToolUi, s as collectApps } from "./apps-CWG3rGhB.js";
3
4
  import { t as jsonSchemaFromDefinition } from "./schema-JK_1KkOa.js";
4
5
  //#region src/core/define.ts
5
6
  function toolRequiresAppContext(tool) {
@@ -16,6 +17,14 @@ function assertAppContextConfiguration(mcp) {
16
17
  if (mcp.createAppContext && !mcp.auth) throw new Error(`@lovable.dev/mcp-js: createAppContext requires auth`);
17
18
  if (!mcp.createAppContext && mcp.tools.some((tool) => tool.enabled || toolRequiresAppContext(tool))) throw new Error(`@lovable.dev/mcp-js: app-context or conditional tools require createAppContext`);
18
19
  }
20
+ function assertLimits(limits) {
21
+ if (limits === void 0) return;
22
+ if (limits === null || typeof limits !== "object" || Array.isArray(limits)) throw new TypeError("@lovable.dev/mcp-js: limits must be an object");
23
+ for (const name of ["maxRequestBodySize", "maxToolInputElements"]) {
24
+ const value = limits[name];
25
+ if (value !== void 0 && (!Number.isSafeInteger(value) || value <= 0)) throw new TypeError(`@lovable.dev/mcp-js: limits.${name} must be a positive safe integer`);
26
+ }
27
+ }
19
28
  function assertNonEmptyString(label, value) {
20
29
  if (value.trim() === "") throw new Error(`@lovable.dev/mcp-js: ${label} must not be empty`);
21
30
  if (value !== value.trim()) throw new Error(`@lovable.dev/mcp-js: ${label} must not have leading or trailing whitespace`);
@@ -128,6 +137,13 @@ const defineTool = Object.assign(defineStaticTool, { withAppContext: () => (def)
128
137
  requiresAppContext: true
129
138
  };
130
139
  } });
140
+ /** MCP Apps is beta with normal semver guarantees.
141
+ * See {@link https://www.npmjs.com/package/@lovable.dev/mcp-js?activeTab=readme | beta policy in the package README}. */
142
+ function defineApp(def) {
143
+ assertAppDefinitionInput(def);
144
+ freezeApp(def);
145
+ return def;
146
+ }
131
147
  /**
132
148
  * Declare the MCP server. `export default` the result from your MCP
133
149
  * entrypoint (default `lib/mcp/index.ts`); the Vite plugin reads it to
@@ -141,12 +157,19 @@ function defineMcp(def) {
141
157
  assertAppContextConfiguration(def);
142
158
  if (def.auth) assertOAuthConfig(def.auth);
143
159
  assertAllowedOrigins(def.allowedOrigins);
160
+ assertLimits(def.limits);
144
161
  assertToolSchemas(def);
162
+ for (const tool of def.tools) assertToolUi(tool);
163
+ collectApps(def.tools);
145
164
  resolveMetricsConfig(def.metrics);
146
165
  freezeAuth(def.auth);
166
+ if (def.limits) Object.freeze(def.limits);
147
167
  if (Array.isArray(def.allowedOrigins)) Object.freeze(def.allowedOrigins);
148
168
  Object.freeze(def.tools);
149
- for (const tool of def.tools) Object.freeze(tool);
169
+ for (const tool of def.tools) {
170
+ freezeToolUi(tool);
171
+ Object.freeze(tool);
172
+ }
150
173
  if (def.skills !== void 0) {
151
174
  if (!Array.isArray(def.skills)) throw new TypeError("@lovable.dev/mcp-js: skills must be an array of ?skill imports");
152
175
  validateSkills(def.skills.map((entry) => {
@@ -273,4 +296,4 @@ function errorSummary(err) {
273
296
  }
274
297
  }
275
298
  //#endregion
276
- export { ToolContext as a, toolRequiresAppContext as c, AuthContext as i, errorSummary as n, defineMcp as o, resolveToolErrorMessage as r, defineTool as s, ToolError as t };
299
+ export { ToolContext as a, defineTool as c, AuthContext as i, toolRequiresAppContext as l, errorSummary as n, defineApp as o, resolveToolErrorMessage as r, defineMcp as s, ToolError as t };
@@ -1,6 +1,7 @@
1
1
  const require_schema = require("./schema-DNMsvJwE.cjs");
2
2
  const require_logger = require("./logger-C-Hdu57K.cjs");
3
3
  const require_format = require("./format-DDzvc92Z.cjs");
4
+ const require_apps = require("./apps-DyoDrwfi.cjs");
4
5
  //#region src/core/define.ts
5
6
  function toolRequiresAppContext(tool) {
6
7
  return "requiresAppContext" in tool && tool.requiresAppContext === true;
@@ -16,6 +17,14 @@ function assertAppContextConfiguration(mcp) {
16
17
  if (mcp.createAppContext && !mcp.auth) throw new Error(`@lovable.dev/mcp-js: createAppContext requires auth`);
17
18
  if (!mcp.createAppContext && mcp.tools.some((tool) => tool.enabled || toolRequiresAppContext(tool))) throw new Error(`@lovable.dev/mcp-js: app-context or conditional tools require createAppContext`);
18
19
  }
20
+ function assertLimits(limits) {
21
+ if (limits === void 0) return;
22
+ if (limits === null || typeof limits !== "object" || Array.isArray(limits)) throw new TypeError("@lovable.dev/mcp-js: limits must be an object");
23
+ for (const name of ["maxRequestBodySize", "maxToolInputElements"]) {
24
+ const value = limits[name];
25
+ if (value !== void 0 && (!Number.isSafeInteger(value) || value <= 0)) throw new TypeError(`@lovable.dev/mcp-js: limits.${name} must be a positive safe integer`);
26
+ }
27
+ }
19
28
  function assertNonEmptyString(label, value) {
20
29
  if (value.trim() === "") throw new Error(`@lovable.dev/mcp-js: ${label} must not be empty`);
21
30
  if (value !== value.trim()) throw new Error(`@lovable.dev/mcp-js: ${label} must not have leading or trailing whitespace`);
@@ -128,6 +137,13 @@ const defineTool = Object.assign(defineStaticTool, { withAppContext: () => (def)
128
137
  requiresAppContext: true
129
138
  };
130
139
  } });
140
+ /** MCP Apps is beta with normal semver guarantees.
141
+ * See {@link https://www.npmjs.com/package/@lovable.dev/mcp-js?activeTab=readme | beta policy in the package README}. */
142
+ function defineApp(def) {
143
+ require_apps.assertAppDefinitionInput(def);
144
+ require_apps.freezeApp(def);
145
+ return def;
146
+ }
131
147
  /**
132
148
  * Declare the MCP server. `export default` the result from your MCP
133
149
  * entrypoint (default `lib/mcp/index.ts`); the Vite plugin reads it to
@@ -141,12 +157,19 @@ function defineMcp(def) {
141
157
  assertAppContextConfiguration(def);
142
158
  if (def.auth) assertOAuthConfig(def.auth);
143
159
  assertAllowedOrigins(def.allowedOrigins);
160
+ assertLimits(def.limits);
144
161
  assertToolSchemas(def);
162
+ for (const tool of def.tools) require_apps.assertToolUi(tool);
163
+ require_apps.collectApps(def.tools);
145
164
  require_logger.resolveMetricsConfig(def.metrics);
146
165
  freezeAuth(def.auth);
166
+ if (def.limits) Object.freeze(def.limits);
147
167
  if (Array.isArray(def.allowedOrigins)) Object.freeze(def.allowedOrigins);
148
168
  Object.freeze(def.tools);
149
- for (const tool of def.tools) Object.freeze(tool);
169
+ for (const tool of def.tools) {
170
+ require_apps.freezeToolUi(tool);
171
+ Object.freeze(tool);
172
+ }
150
173
  if (def.skills !== void 0) {
151
174
  if (!Array.isArray(def.skills)) throw new TypeError("@lovable.dev/mcp-js: skills must be an array of ?skill imports");
152
175
  require_format.validateSkills(def.skills.map((entry) => {
@@ -291,6 +314,12 @@ Object.defineProperty(exports, "ToolError", {
291
314
  return ToolError;
292
315
  }
293
316
  });
317
+ Object.defineProperty(exports, "defineApp", {
318
+ enumerable: true,
319
+ get: function() {
320
+ return defineApp;
321
+ }
322
+ });
294
323
  Object.defineProperty(exports, "defineMcp", {
295
324
  enumerable: true,
296
325
  get: function() {
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_logger = require("./logger-C-Hdu57K.cjs");
3
- const require_errors = require("./errors-DSHt3Jqs.cjs");
3
+ const require_errors = require("./errors-xJ_7Su1K.cjs");
4
4
  //#region src/auth/config.ts
5
5
  function frozenArray(value) {
6
6
  return value === void 0 ? void 0 : Object.freeze([...value]);
@@ -39,6 +39,7 @@ exports.AuthContext = require_errors.AuthContext;
39
39
  exports.ToolContext = require_errors.ToolContext;
40
40
  exports.ToolError = require_errors.ToolError;
41
41
  exports.auth = auth;
42
+ exports.defineApp = require_errors.defineApp;
42
43
  exports.defineMcp = require_errors.defineMcp;
43
44
  exports.defineTool = require_errors.defineTool;
44
45
  exports.setLogLevel = require_logger.setLogLevel;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { A as MetricsOptions, C as ToolHandlerResult, D as ZodSchema, E as ZodRawShape, F as ToolContext, I as JwtClaims, L as McpAuthConfig, M as McpClientInfo, N as McpProtocolEra, O as Skill, P as ProgressUpdate, S as ToolDefinition, T as ZodOutputSchema, _ as ResourceLink, a as ContentAnnotations, b as ToolAnnotations, c as EmbeddedBlobResource, d as ImageContent, f as JsonValue, g as McpDefinitionInput, h as McpDefinition, i as ConditionalSkill, j as AuthContext, k as MetricsConfig, l as EmbeddedResource, m as McpAllowedOrigins, n as AppContextToolDefinitionInput, o as ContentBlock, p as JsonValueInput, r as AudioContent, s as CreateAppContextInput, t as AppContextToolDefinition, u as EmbeddedTextResource, v as ResourceLinkIcon, w as ToolVisibilityContext, x as ToolContent, y as TextContent } from "./types-BtoYHhdt.cjs";
1
+ /// <reference path="./mcp-app.d.ts" />
2
+ import { A as ToolVisibilityContext, B as ProgressUpdate, C as TextContent, D as ToolHandlerResult, E as ToolDefinition, F as MetricsConfig, H as JwtClaims, I as MetricsOptions, L as AuthContext, M as ZodRawShape, N as ZodSchema, O as ToolUiOptions, P as Skill, R as McpClientInfo, S as ResourceLinkIcon, T as ToolContent, U as McpAuthConfig, V as ToolContext, _ as JsonValueInput, a as AppDefinitionInput, b as McpDefinitionInput, c as ConditionalSkill, d as CreateAppContextInput, f as EmbeddedBlobResource, g as JsonValue, h as ImageContent, i as AppDefinition, j as ZodOutputSchema, k as ToolUiVisibility, l as ContentAnnotations, m as EmbeddedTextResource, n as AppContextToolDefinitionInput, o as AppPermissions, p as EmbeddedResource, r as AppCsp, s as AudioContent, t as AppContextToolDefinition, u as ContentBlock, v as McpAllowedOrigins, w as ToolAnnotations, x as ResourceLink, y as McpDefinition, z as McpProtocolEra } from "./types-B_dVw-zM.cjs";
2
3
  //#region src/core/define.d.ts
3
4
  /**
4
5
  * Declare a single MCP tool. Import the result into your MCP definition's
@@ -14,6 +15,9 @@ interface DefineTool {
14
15
  withAppContext<TAppContext>(): <TInput extends ZodRawShape | undefined = undefined, TOutput extends ZodOutputSchema | undefined = undefined>(def: AppContextToolDefinitionInput<TInput, TOutput, TAppContext>) => AppContextToolDefinition<TInput, TOutput, TAppContext>;
15
16
  }
16
17
  declare const defineTool: DefineTool;
18
+ /** MCP Apps is beta with normal semver guarantees.
19
+ * See {@link https://www.npmjs.com/package/@lovable.dev/mcp-js?activeTab=readme | beta policy in the package README}. */
20
+ declare function defineApp(def: AppDefinitionInput): AppDefinition;
17
21
  /**
18
22
  * Declare the MCP server. `export default` the result from your MCP
19
23
  * entrypoint (default `lib/mcp/index.ts`); the Vite plugin reads it to
@@ -76,4 +80,4 @@ type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
76
80
  */
77
81
  declare function setLogLevel(level: LogLevel): LogLevel;
78
82
  //#endregion
79
- export { type AppContextToolDefinition, type AppContextToolDefinitionInput, type AudioContent, AuthContext, type ConditionalSkill, type ContentAnnotations, type ContentBlock, type CreateAppContextInput, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JsonValue, type JsonValueInput, type JwtClaims, type LogLevel, type McpAllowedOrigins, type McpClientInfo, type McpDefinitionInput, type McpProtocolEra, type MetricsConfig, type MetricsOptions, type ProgressUpdate, type ResourceLink, type ResourceLinkIcon, type Skill, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ToolVisibilityContext, type ZodOutputSchema, type ZodRawShape, type ZodSchema, auth, defineMcp, defineTool, setLogLevel };
83
+ export { type AppContextToolDefinition, type AppContextToolDefinitionInput, type AppCsp, type AppDefinition, type AppDefinitionInput, type AppPermissions, type AudioContent, AuthContext, type ConditionalSkill, type ContentAnnotations, type ContentBlock, type CreateAppContextInput, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JsonValue, type JsonValueInput, type JwtClaims, type LogLevel, type McpAllowedOrigins, type McpClientInfo, type McpDefinitionInput, type McpProtocolEra, type MetricsConfig, type MetricsOptions, type ProgressUpdate, type ResourceLink, type ResourceLinkIcon, type Skill, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ToolUiOptions, type ToolUiVisibility, type ToolVisibilityContext, type ZodOutputSchema, type ZodRawShape, type ZodSchema, auth, defineApp, defineMcp, defineTool, setLogLevel };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { A as MetricsOptions, C as ToolHandlerResult, D as ZodSchema, E as ZodRawShape, F as ToolContext, I as JwtClaims, L as McpAuthConfig, M as McpClientInfo, N as McpProtocolEra, O as Skill, P as ProgressUpdate, S as ToolDefinition, T as ZodOutputSchema, _ as ResourceLink, a as ContentAnnotations, b as ToolAnnotations, c as EmbeddedBlobResource, d as ImageContent, f as JsonValue, g as McpDefinitionInput, h as McpDefinition, i as ConditionalSkill, j as AuthContext, k as MetricsConfig, l as EmbeddedResource, m as McpAllowedOrigins, n as AppContextToolDefinitionInput, o as ContentBlock, p as JsonValueInput, r as AudioContent, s as CreateAppContextInput, t as AppContextToolDefinition, u as EmbeddedTextResource, v as ResourceLinkIcon, w as ToolVisibilityContext, x as ToolContent, y as TextContent } from "./types-BtoYHhdt.js";
1
+ /// <reference path="./mcp-app.d.ts" />
2
+ import { A as ToolVisibilityContext, B as ProgressUpdate, C as TextContent, D as ToolHandlerResult, E as ToolDefinition, F as MetricsConfig, H as JwtClaims, I as MetricsOptions, L as AuthContext, M as ZodRawShape, N as ZodSchema, O as ToolUiOptions, P as Skill, R as McpClientInfo, S as ResourceLinkIcon, T as ToolContent, U as McpAuthConfig, V as ToolContext, _ as JsonValueInput, a as AppDefinitionInput, b as McpDefinitionInput, c as ConditionalSkill, d as CreateAppContextInput, f as EmbeddedBlobResource, g as JsonValue, h as ImageContent, i as AppDefinition, j as ZodOutputSchema, k as ToolUiVisibility, l as ContentAnnotations, m as EmbeddedTextResource, n as AppContextToolDefinitionInput, o as AppPermissions, p as EmbeddedResource, r as AppCsp, s as AudioContent, t as AppContextToolDefinition, u as ContentBlock, v as McpAllowedOrigins, w as ToolAnnotations, x as ResourceLink, y as McpDefinition, z as McpProtocolEra } from "./types-B_dVw-zM.js";
2
3
  //#region src/core/define.d.ts
3
4
  /**
4
5
  * Declare a single MCP tool. Import the result into your MCP definition's
@@ -14,6 +15,9 @@ interface DefineTool {
14
15
  withAppContext<TAppContext>(): <TInput extends ZodRawShape | undefined = undefined, TOutput extends ZodOutputSchema | undefined = undefined>(def: AppContextToolDefinitionInput<TInput, TOutput, TAppContext>) => AppContextToolDefinition<TInput, TOutput, TAppContext>;
15
16
  }
16
17
  declare const defineTool: DefineTool;
18
+ /** MCP Apps is beta with normal semver guarantees.
19
+ * See {@link https://www.npmjs.com/package/@lovable.dev/mcp-js?activeTab=readme | beta policy in the package README}. */
20
+ declare function defineApp(def: AppDefinitionInput): AppDefinition;
17
21
  /**
18
22
  * Declare the MCP server. `export default` the result from your MCP
19
23
  * entrypoint (default `lib/mcp/index.ts`); the Vite plugin reads it to
@@ -76,4 +80,4 @@ type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
76
80
  */
77
81
  declare function setLogLevel(level: LogLevel): LogLevel;
78
82
  //#endregion
79
- export { type AppContextToolDefinition, type AppContextToolDefinitionInput, type AudioContent, AuthContext, type ConditionalSkill, type ContentAnnotations, type ContentBlock, type CreateAppContextInput, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JsonValue, type JsonValueInput, type JwtClaims, type LogLevel, type McpAllowedOrigins, type McpClientInfo, type McpDefinitionInput, type McpProtocolEra, type MetricsConfig, type MetricsOptions, type ProgressUpdate, type ResourceLink, type ResourceLinkIcon, type Skill, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ToolVisibilityContext, type ZodOutputSchema, type ZodRawShape, type ZodSchema, auth, defineMcp, defineTool, setLogLevel };
83
+ export { type AppContextToolDefinition, type AppContextToolDefinitionInput, type AppCsp, type AppDefinition, type AppDefinitionInput, type AppPermissions, type AudioContent, AuthContext, type ConditionalSkill, type ContentAnnotations, type ContentBlock, type CreateAppContextInput, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JsonValue, type JsonValueInput, type JwtClaims, type LogLevel, type McpAllowedOrigins, type McpClientInfo, type McpDefinitionInput, type McpProtocolEra, type MetricsConfig, type MetricsOptions, type ProgressUpdate, type ResourceLink, type ResourceLinkIcon, type Skill, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ToolUiOptions, type ToolUiVisibility, type ToolVisibilityContext, type ZodOutputSchema, type ZodRawShape, type ZodSchema, auth, defineApp, defineMcp, defineTool, setLogLevel };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { a as setLogLevel } from "./logger-CpLgYbCG.js";
2
- import { a as ToolContext, i as AuthContext, o as defineMcp, s as defineTool, t as ToolError } from "./errors-D0UPHnG3.js";
2
+ import { a as ToolContext, c as defineTool, i as AuthContext, o as defineApp, s as defineMcp, t as ToolError } from "./errors-CfaxXr2T.js";
3
3
  //#region src/auth/config.ts
4
4
  function frozenArray(value) {
5
5
  return value === void 0 ? void 0 : Object.freeze([...value]);
@@ -34,4 +34,4 @@ function issuer(options) {
34
34
  const oauth = Object.freeze({ issuer });
35
35
  const auth = Object.freeze({ oauth });
36
36
  //#endregion
37
- export { AuthContext, ToolContext, ToolError, auth, defineMcp, defineTool, setLogLevel };
37
+ export { AuthContext, ToolContext, ToolError, auth, defineApp, defineMcp, defineTool, setLogLevel };
@@ -1,4 +1,4 @@
1
- import "./types-BtoYHhdt.js";
1
+ import "./types-B_dVw-zM.js";
2
2
  //#region src/manifest/io.d.ts
3
3
  /**
4
4
  * Shape every MCP Vite plugin exposes on its `api` so `runExtract` can read
@@ -1,5 +1,5 @@
1
1
  import { t as jsonSchemaFromDefinition } from "./schema-JK_1KkOa.js";
2
- import { t as version } from "./package-DV8zBoEy.js";
2
+ import { t as version$1 } from "./package-N4he-Z_i.js";
3
3
  import { a as isFileMissing, i as readSupabaseProjectRef, r as skillImportVitePlugin } from "./hooks-BOdDe251.js";
4
4
  import { lstatSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
5
5
  import { dirname, resolve } from "node:path";
@@ -71,7 +71,7 @@ function manifestFromDefinition(definition, urlPath, source = "the MCP entry") {
71
71
  if (issuer !== void 0 && hasBlankIssuerHost(issuer)) throw new Error(`@lovable.dev/mcp-js: ${source} resolves its OAuth issuer to "${issuer}", which has no project host. Set VITE_SUPABASE_PROJECT_ID or the top-level project_id in supabase/config.toml, then extract the manifest again.`);
72
72
  return {
73
73
  version: 1,
74
- sdk_version: version,
74
+ sdk_version: version$1,
75
75
  path: urlPath,
76
76
  auth: manifestAuth(def.auth),
77
77
  mcp: buildMcpListing(def)
@@ -79,6 +79,16 @@ function manifestFromDefinition(definition, urlPath, source = "the MCP entry") {
79
79
  }
80
80
  //#endregion
81
81
  //#region src/manifest/ssr-loader.ts
82
+ const stubMcpAppImports = {
83
+ name: "@lovable.dev/mcp-js:manifest-mcp-app-stub",
84
+ enforce: "pre",
85
+ resolveId(source) {
86
+ return source.endsWith("?mcp-app") ? `\0mcp-app-stub:${source}` : null;
87
+ },
88
+ load(id) {
89
+ return id.startsWith("\0mcp-app-stub:") ? "export default \"<!doctype html>\";\n" : null;
90
+ }
91
+ };
82
92
  async function produceViaSsr(projectRoot, alias, ssr, entryAbs, urlPath) {
83
93
  const server = await createServer({
84
94
  configFile: false,
@@ -91,7 +101,7 @@ async function produceViaSsr(projectRoot, alias, ssr, entryAbs, urlPath) {
91
101
  },
92
102
  optimizeDeps: { noDiscovery: true },
93
103
  resolve: { alias },
94
- plugins: [skillImportVitePlugin({ report: () => {} })],
104
+ plugins: [skillImportVitePlugin({ report: () => {} }), stubMcpAppImports],
95
105
  ssr
96
106
  });
97
107
  try {
@@ -1,5 +1,5 @@
1
1
  const require_schema = require("./schema-DNMsvJwE.cjs");
2
- const require_package = require("./package-DL4uNmL0.cjs");
2
+ const require_package = require("./package-Cu_ynl05.cjs");
3
3
  const require_hooks = require("./hooks-xQl3EkDa.cjs");
4
4
  let node_fs = require("node:fs");
5
5
  let node_path = require("node:path");
@@ -79,6 +79,16 @@ function manifestFromDefinition(definition, urlPath, source = "the MCP entry") {
79
79
  }
80
80
  //#endregion
81
81
  //#region src/manifest/ssr-loader.ts
82
+ const stubMcpAppImports = {
83
+ name: "@lovable.dev/mcp-js:manifest-mcp-app-stub",
84
+ enforce: "pre",
85
+ resolveId(source) {
86
+ return source.endsWith("?mcp-app") ? `\0mcp-app-stub:${source}` : null;
87
+ },
88
+ load(id) {
89
+ return id.startsWith("\0mcp-app-stub:") ? "export default \"<!doctype html>\";\n" : null;
90
+ }
91
+ };
82
92
  async function produceViaSsr(projectRoot, alias, ssr, entryAbs, urlPath) {
83
93
  const server = await (0, vite.createServer)({
84
94
  configFile: false,
@@ -91,7 +101,7 @@ async function produceViaSsr(projectRoot, alias, ssr, entryAbs, urlPath) {
91
101
  },
92
102
  optimizeDeps: { noDiscovery: true },
93
103
  resolve: { alias },
94
- plugins: [require_hooks.skillImportVitePlugin({ report: () => {} })],
104
+ plugins: [require_hooks.skillImportVitePlugin({ report: () => {} }), stubMcpAppImports],
95
105
  ssr
96
106
  });
97
107
  try {
@@ -1,4 +1,4 @@
1
- import "./types-BtoYHhdt.cjs";
1
+ import "./types-B_dVw-zM.cjs";
2
2
  //#region src/manifest/io.d.ts
3
3
  /**
4
4
  * Shape every MCP Vite plugin exposes on its `api` so `runExtract` can read
@@ -1,10 +1,11 @@
1
1
  import { i as log, r as describeError } from "./logger-CpLgYbCG.js";
2
+ import { n as UI_EXTENSION_ID, r as appResourceUri, s as collectApps, t as APP_RESOURCE_MIME_TYPE } from "./apps-CWG3rGhB.js";
2
3
  import { n as schemaFromDefinition, t as jsonSchemaFromDefinition } from "./schema-JK_1KkOa.js";
3
- import { a as ToolContext, c as toolRequiresAppContext, i as AuthContext, n as errorSummary, r as resolveToolErrorMessage } from "./errors-D0UPHnG3.js";
4
- import { d as nowMs, i as normalizeHttpMethod, l as emitBeforeResponse, n as createRequestAuthorizer, p as finalizeWireResponse, t as evaluateCors, u as createNoopRecorder } from "./cors-COjc9O73.js";
5
- import { t as finalizeToolResult } from "./tool-result-DcNioyiI.js";
4
+ import { a as ToolContext, i as AuthContext, l as toolRequiresAppContext, n as errorSummary, r as resolveToolErrorMessage } from "./errors-CfaxXr2T.js";
5
+ import { d as nowMs, i as normalizeHttpMethod, l as emitBeforeResponse, n as createRequestAuthorizer, p as finalizeWireResponse, t as evaluateCors, u as createNoopRecorder } from "./cors-M68siADv.js";
6
+ import { t as finalizeToolResult } from "./tool-result-BG-HsSQu.js";
6
7
  import { safeParseAsync } from "@modelcontextprotocol/sdk/server/zod-compat.js";
7
- import { CLIENT_CAPABILITIES_META_KEY, CLIENT_INFO_META_KEY, McpServer, ProtocolError, ProtocolErrorCode, createMcpHandler } from "@modelcontextprotocol/server";
8
+ import { CLIENT_CAPABILITIES_META_KEY, CLIENT_INFO_META_KEY, McpServer, ProtocolError, ProtocolErrorCode, createMcpHandler, readRequestBody } from "@modelcontextprotocol/server";
8
9
  //#region src/core/content.ts
9
10
  /** Join the text of a result's `type: "text"` blocks into one string, dropping
10
11
  * binary/resource blocks. Used to surface a `tool_error` message in the local
@@ -116,18 +117,18 @@ function createGatedHandler(gate) {
116
117
  const MODERN_PROTOCOL_VERSION = "2026-07-28";
117
118
  const NO_OPERATIONS = {
118
119
  listTools: false,
120
+ exposeApps: false,
119
121
  calledTools: /* @__PURE__ */ new Set()
120
122
  };
121
- function collectRequestOperations(value, calledTools) {
123
+ function collectRequestOperations(value, operations) {
122
124
  if (Array.isArray(value)) {
123
- let listTools = false;
124
- for (const item of value) listTools = collectRequestOperations(item, calledTools) || listTools;
125
- return listTools;
125
+ for (const item of value) collectRequestOperations(item, operations);
126
+ return;
126
127
  }
127
- if (!isPlainObject(value)) return false;
128
- if (value.method === "tools/list") return true;
129
- if (value.method === "tools/call" && isPlainObject(value.params) && typeof value.params.name === "string") calledTools.add(value.params.name);
130
- return false;
128
+ if (!isPlainObject(value)) return;
129
+ if (value.method === "tools/list") operations.listTools = true;
130
+ if (value.method === "initialize" || value.method === "server/discover" || value.method === "resources/list" || value.method === "resources/read" && isPlainObject(value.params) && typeof value.params.uri === "string" && URL.canParse(value.params.uri) && new URL(value.params.uri).protocol === "ui:") operations.exposeApps = true;
131
+ if (value.method === "tools/call" && isPlainObject(value.params) && typeof value.params.name === "string") operations.calledTools.add(value.params.name);
131
132
  }
132
133
  /** Marks a failure in app-owned `createAppContext` or `enabled` code so telemetry
133
134
  * can attribute it to the author rather than to the transport. */
@@ -144,15 +145,19 @@ async function withAppContextError(run) {
144
145
  throw new AppContextError(cause);
145
146
  }
146
147
  }
147
- async function classifyRequest(request) {
148
+ async function classifyRequest(request, maxRequestBodySize) {
148
149
  try {
149
- const parsedBody = await request.clone().json();
150
- const calledTools = /* @__PURE__ */ new Set();
150
+ const body = await readRequestBody(request, maxRequestBodySize);
151
+ if (body.tooLarge) return { operations: NO_OPERATIONS };
152
+ const parsedBody = JSON.parse(body.text);
153
+ const operations = {
154
+ listTools: false,
155
+ exposeApps: false,
156
+ calledTools: /* @__PURE__ */ new Set()
157
+ };
158
+ collectRequestOperations(parsedBody, operations);
151
159
  return {
152
- operations: {
153
- listTools: collectRequestOperations(parsedBody, calledTools),
154
- calledTools
155
- },
160
+ operations,
156
161
  parsedBody
157
162
  };
158
163
  } catch {
@@ -322,11 +327,50 @@ function adaptToolCallback(tool, auth, recorder, protocol, appContext) {
322
327
  return {
323
328
  content: result.content ?? [],
324
329
  structuredContent: result.structuredContent,
325
- isError: result.isError
330
+ isError: result.isError,
331
+ _meta: result._meta
326
332
  };
327
333
  };
328
334
  }
329
- const SKILL_CACHE = {
335
+ function appResourceMeta(app) {
336
+ const ui = {};
337
+ if (app.csp) ui.csp = app.csp;
338
+ if (app.permissions) ui.permissions = app.permissions;
339
+ if (app.domain !== void 0) ui.domain = app.domain;
340
+ if (app.prefersBorder !== void 0) ui.prefersBorder = app.prefersBorder;
341
+ return Object.keys(ui).length > 0 ? { ui } : void 0;
342
+ }
343
+ function registerApps(server, apps) {
344
+ for (const app of apps) {
345
+ const uri = appResourceUri(app.name);
346
+ const meta = appResourceMeta(app);
347
+ const withMeta = meta ? { _meta: meta } : {};
348
+ server.registerResource(app.name, uri, {
349
+ title: app.title,
350
+ description: app.description,
351
+ mimeType: APP_RESOURCE_MIME_TYPE,
352
+ cacheHint: PRIVATE_CACHE,
353
+ ...withMeta
354
+ }, () => ({ contents: [{
355
+ uri,
356
+ mimeType: APP_RESOURCE_MIME_TYPE,
357
+ text: app.html,
358
+ ...withMeta
359
+ }] }));
360
+ }
361
+ }
362
+ function toolUiMeta(tool) {
363
+ if (!tool.ui) return void 0;
364
+ const resourceUri = tool.ui.app ? appResourceUri(tool.ui.app.name) : void 0;
365
+ return {
366
+ ui: {
367
+ ...resourceUri ? { resourceUri } : {},
368
+ ...tool.ui.visibility ? { visibility: tool.ui.visibility } : {}
369
+ },
370
+ ...resourceUri ? { "ui/resourceUri": resourceUri } : {}
371
+ };
372
+ }
373
+ const PRIVATE_CACHE = {
330
374
  ttlMs: 0,
331
375
  cacheScope: "private"
332
376
  };
@@ -358,14 +402,14 @@ function skillEntry(skill) {
358
402
  function registerSkills(server, skills, era) {
359
403
  const resultMetadata = era === "modern" ? {
360
404
  resultType: "complete",
361
- ...SKILL_CACHE
405
+ ...PRIVATE_CACHE
362
406
  } : {};
363
407
  for (const file of skills.files.values()) {
364
408
  const owner = skills.skillsByUri.get(file.uri);
365
409
  server.registerResource(owner ? owner.frontmatter.name : file.uri, file.uri, {
366
410
  mimeType: file.mimeType,
367
411
  ...owner ? { description: owner.frontmatter.description } : {},
368
- cacheHint: SKILL_CACHE
412
+ cacheHint: PRIVATE_CACHE
369
413
  }, async () => ({ contents: [{
370
414
  uri: file.uri,
371
415
  mimeType: file.mimeType,
@@ -386,16 +430,27 @@ function registerSkills(server, skills, era) {
386
430
  });
387
431
  }
388
432
  async function buildServer(mcp, auth, recorder, era, signal, operations, skills) {
433
+ const hasApps = mcp.tools.some((tool) => tool.ui?.app !== void 0);
389
434
  const calledTools = operations ? mcp.tools.filter((tool) => operations.calledTools.has(tool.name)) : mcp.tools;
390
435
  const selectedTools = !operations || operations.listTools ? mcp.tools : calledTools;
391
- const hasConditionalTools = mcp.tools.some((tool) => tool.enabled !== void 0);
392
- const needsAppContext = skills !== void 0 && skills.prepared === void 0 || operations?.listTools === true && hasConditionalTools || calledTools.some((tool) => tool.enabled !== void 0 || toolRequiresAppContext(tool));
436
+ const exposureTools = operations?.exposeApps ? mcp.tools.filter((tool) => tool.ui?.app !== void 0 || selectedTools.includes(tool)) : selectedTools;
437
+ const needsAppContext = skills !== void 0 && skills.prepared === void 0 || exposureTools.some((tool) => tool.enabled !== void 0) || calledTools.some(toolRequiresAppContext);
393
438
  const { createAppContext } = mcp;
394
439
  const appContext = needsAppContext && createAppContext ? await withAppContextError(() => createAppContext({
395
440
  auth: new AuthContext(auth),
396
441
  signal
397
442
  })) : void 0;
398
443
  const visibilityContext = Object.freeze({ appContext });
444
+ const enabledTools = /* @__PURE__ */ new Set();
445
+ for (const tool of exposureTools) if (await withAppContextError(() => {
446
+ const value = tool.enabled ? tool.enabled(visibilityContext) : true;
447
+ if (typeof value !== "boolean") {
448
+ Promise.resolve(value).catch(() => {});
449
+ throw new TypeError(`@lovable.dev/mcp-js: tool "${tool.name}" enabled must return a boolean synchronously`);
450
+ }
451
+ return value;
452
+ })) enabledTools.add(tool);
453
+ const apps = collectApps([...enabledTools]);
399
454
  let preparedSkills = skills?.prepared;
400
455
  if (skills && !preparedSkills) {
401
456
  const enabledSkills = await withAppContextError(() => mcp.skills.flatMap((entry) => {
@@ -414,15 +469,21 @@ async function buildServer(mcp, auth, recorder, era, signal, operations, skills)
414
469
  version: mcp.version,
415
470
  title: mcp.title
416
471
  }, {
472
+ maxToolInputElements: mcp.limits?.maxToolInputElements ?? 1e4,
417
473
  instructions: preparedSkills ? composeInstructions(mcp.instructions, preparedSkills, skills.declared) : mcp.instructions,
418
- capabilities: skills ? {
474
+ capabilities: {
419
475
  tools: { listChanged: false },
420
- resources: {
421
- listChanged: false,
422
- subscribe: false
423
- },
424
- extensions: { [SKILLS_EXTENSION_ID]: {} }
425
- } : { tools: { listChanged: false } },
476
+ ...hasApps || skills ? {
477
+ resources: {
478
+ listChanged: false,
479
+ subscribe: false
480
+ },
481
+ extensions: {
482
+ ...apps.length > 0 ? { [UI_EXTENSION_ID]: { mimeTypes: [APP_RESOURCE_MIME_TYPE] } } : {},
483
+ ...skills ? { [SKILLS_EXTENSION_ID]: {} } : {}
484
+ }
485
+ } : {}
486
+ },
426
487
  cacheHints: {
427
488
  "tools/list": {
428
489
  ttlMs: 0,
@@ -432,26 +493,22 @@ async function buildServer(mcp, auth, recorder, era, signal, operations, skills)
432
493
  ttlMs: 0,
433
494
  cacheScope: "private"
434
495
  },
435
- ...skills ? {
436
- "resources/list": SKILL_CACHE,
437
- "resources/read": SKILL_CACHE
496
+ ...hasApps || skills ? {
497
+ "resources/list": PRIVATE_CACHE,
498
+ "resources/read": PRIVATE_CACHE
438
499
  } : {}
439
500
  }
440
501
  });
502
+ registerApps(server, apps);
441
503
  if (preparedSkills) registerSkills(server, preparedSkills, era);
442
504
  for (const tool of selectedTools) {
443
- if (tool.enabled) {
444
- const { enabled } = tool;
445
- if (!await withAppContextError(() => {
446
- const value = enabled(visibilityContext);
447
- if (typeof value !== "boolean") throw new TypeError(`@lovable.dev/mcp-js: tool "${tool.name}" enabled must return a boolean synchronously`);
448
- return value;
449
- })) continue;
450
- }
505
+ if (!enabledTools.has(tool)) continue;
506
+ const _meta = toolUiMeta(tool);
451
507
  const config = {
452
508
  title: tool.title,
453
509
  description: tool.description,
454
510
  annotations: tool.annotations,
511
+ ..._meta ? { _meta } : {},
455
512
  ...tool.outputSchema ? { outputSchema: standardSchemaFromDefinition(tool.outputSchema, false) } : {}
456
513
  };
457
514
  const callback = adaptToolCallback(tool, auth, recorder, era === "legacy" ? "legacy" : MODERN_PROTOCOL_VERSION, appContext);
@@ -472,6 +529,7 @@ async function buildServer(mcp, auth, recorder, era, signal, operations, skills)
472
529
  */
473
530
  function createMcpProtocolHandler(mcp, options = {}) {
474
531
  const authorizer = createRequestAuthorizer(mcp, options);
532
+ const maxRequestBodySize = mcp.limits?.maxRequestBodySize ?? 1024 * 1024;
475
533
  const hasSkills = mcp.skills !== void 0 && mcp.skills.length > 0;
476
534
  const preparedSkills = mcp.skills?.length && mcp.skills.every((entry) => !("skill" in entry)) ? prepareSkills(mcp.name, mcp.skills) : void 0;
477
535
  const handle = async (request, authResult, recorder) => {
@@ -490,20 +548,26 @@ function createMcpProtocolHandler(mcp, options = {}) {
490
548
  outcome: "500 internal error"
491
549
  });
492
550
  };
551
+ let classificationRequest;
493
552
  try {
494
- const classified = mcp.createAppContext || hasSkills ? await classifyRequest(request) : void 0;
495
- const operations = mcp.createAppContext ? classified?.operations : void 0;
496
- const skills = hasSkills ? {
497
- prepared: preparedSkills,
498
- declared: declaresSkillsSupport(classified?.parsedBody)
499
- } : void 0;
500
- const response = await createMcpHandler(({ era, requestInfo }) => buildServer(mcp, authResult.auth, recorder, era, requestInfo?.signal ?? request.signal, operations, skills), {
553
+ classificationRequest = mcp.createAppContext || hasSkills ? request.clone() : void 0;
554
+ const response = await createMcpHandler(async ({ era, requestInfo }) => {
555
+ const classified = classificationRequest ? await classifyRequest(classificationRequest, maxRequestBodySize) : void 0;
556
+ const operations = mcp.createAppContext ? classified?.operations : void 0;
557
+ const skills = hasSkills ? {
558
+ prepared: preparedSkills,
559
+ declared: declaresSkillsSupport(classified?.parsedBody)
560
+ } : void 0;
561
+ return buildServer(mcp, authResult.auth, recorder, era, requestInfo?.signal ?? request.signal, operations, skills);
562
+ }, {
501
563
  legacy: "stateless",
564
+ maxRequestBodySize,
502
565
  maxSubscriptions: 0,
503
566
  onerror: (error) => {
504
567
  protocolError = error;
505
568
  }
506
- }).fetch(request, classified?.parsedBody === void 0 ? void 0 : { parsedBody: classified.parsedBody });
569
+ }).fetch(request);
570
+ response.headers.append("Cache-Control", "no-store");
507
571
  if (response.status >= 500) await reportTransportError(protocolError);
508
572
  return response;
509
573
  } catch (err) {
@@ -516,6 +580,8 @@ function createMcpProtocolHandler(mcp, options = {}) {
516
580
  message: "internal error"
517
581
  }
518
582
  }, { status: 500 });
583
+ } finally {
584
+ if (classificationRequest?.body && !classificationRequest.bodyUsed) classificationRequest.body.cancel().catch(() => {});
519
585
  }
520
586
  };
521
587
  return createGatedHandler({