@lovable.dev/mcp-js 0.28.0 → 0.29.0-rc.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 (69) hide show
  1. package/README.md +7 -1
  2. package/dist/{authorize-Cs1yyLrq.d.ts → authorize-BjNE3LPr.d.ts} +1 -1
  3. package/dist/{authorize-BcNuNPtP.d.cts → authorize-BzZFS0zi.d.cts} +1 -1
  4. package/dist/{base-CUkmyaXJ.d.cts → base-DSH8NnPj.d.cts} +4 -0
  5. package/dist/{base-CUkmyaXJ.d.ts → base-DSH8NnPj.d.ts} +4 -0
  6. package/dist/cli/extract-manifest.cjs +2 -2
  7. package/dist/cli/extract-manifest.js +2 -2
  8. package/dist/{authorize-ChY44o_1.cjs → cors-CmKzDN7k.cjs} +73 -29
  9. package/dist/{authorize--rUeMOGU.js → cors-D4YbODs-.js} +68 -24
  10. package/dist/{forwarded-BlLF3dfc.js → forwarded-B3EBjHnA.js} +3 -3
  11. package/dist/{forwarded-Bhwcj22u.cjs → forwarded-BC_RHnn5.cjs} +3 -3
  12. package/dist/{gate-CGZl0gjJ.cjs → gate-n_HX6eQ5.cjs} +6 -4
  13. package/dist/{gate-BiM6EBeA.js → gate-pGsVlY_4.js} +5 -3
  14. package/dist/index.cjs +37 -0
  15. package/dist/index.d.cts +3 -3
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.js +37 -0
  18. package/dist/{io-VBHO8YH_.d.cts → io-BEwvgN8s.d.cts} +1 -1
  19. package/dist/{io-SMlD5WeX.d.ts → io-CvALf9NE.d.ts} +1 -1
  20. package/dist/list-tools-Dkyyje7j.cjs +48 -0
  21. package/dist/{list-tools-BLGr7mot.js → list-tools-ePP9tXND.js} +9 -13
  22. package/dist/{list-tools-BAqQVIHk.d.ts → list-tools-qIvVJeWZ.d.ts} +3 -3
  23. package/dist/{list-tools-BN97L2Yv.d.cts → list-tools-zagoI477.d.cts} +3 -3
  24. package/dist/mcp-Cs4zfvSi.js +336 -0
  25. package/dist/mcp-DQ1Vdv4v.cjs +341 -0
  26. package/dist/{package-CGLPZwz-.cjs → package-C3YVYgxp.cjs} +1 -1
  27. package/dist/{package-DgiA0xuY.js → package-DzB_5Hur.js} +1 -1
  28. package/dist/protocols/mcp/index.cjs +1 -1
  29. package/dist/protocols/mcp/index.d.cts +3 -3
  30. package/dist/protocols/mcp/index.d.ts +3 -3
  31. package/dist/protocols/mcp/index.js +1 -1
  32. package/dist/protocols/oauth-metadata.cjs +11 -9
  33. package/dist/protocols/oauth-metadata.d.cts +2 -2
  34. package/dist/protocols/oauth-metadata.d.ts +2 -2
  35. package/dist/protocols/oauth-metadata.js +5 -3
  36. package/dist/protocols/rest/index.cjs +2 -2
  37. package/dist/protocols/rest/index.d.cts +4 -4
  38. package/dist/protocols/rest/index.d.ts +4 -4
  39. package/dist/protocols/rest/index.js +2 -2
  40. package/dist/{rest-BS7bBOd9.js → rest-DSclWpIt.js} +13 -12
  41. package/dist/{rest-BE05MUNS.cjs → rest-P6XZWP42.cjs} +28 -27
  42. package/dist/schema-CW1jKvio.js +65 -0
  43. package/dist/schema-D3vClxb7.cjs +76 -0
  44. package/dist/stacks/supabase/index.cjs +7 -7
  45. package/dist/stacks/supabase/index.d.cts +1 -1
  46. package/dist/stacks/supabase/index.d.ts +1 -1
  47. package/dist/stacks/supabase/index.js +5 -5
  48. package/dist/stacks/supabase/vite.cjs +1 -1
  49. package/dist/stacks/supabase/vite.d.cts +1 -1
  50. package/dist/stacks/supabase/vite.d.ts +1 -1
  51. package/dist/stacks/supabase/vite.js +1 -1
  52. package/dist/stacks/tanstack/index.cjs +8 -8
  53. package/dist/stacks/tanstack/index.d.cts +2 -2
  54. package/dist/stacks/tanstack/index.d.ts +2 -2
  55. package/dist/stacks/tanstack/index.js +5 -5
  56. package/dist/stacks/tanstack/vite.cjs +8 -4
  57. package/dist/stacks/tanstack/vite.d.cts +11 -1
  58. package/dist/stacks/tanstack/vite.d.ts +11 -1
  59. package/dist/stacks/tanstack/vite.js +8 -4
  60. package/dist/tool-result-CK6hXO43.cjs +89 -0
  61. package/dist/tool-result-DfCk445b.js +78 -0
  62. package/dist/{types-C0Wgm9zp.d.cts → types-D1cgsnPu.d.cts} +15 -7
  63. package/dist/{types-C0Wgm9zp.d.ts → types-D1cgsnPu.d.ts} +15 -7
  64. package/package.json +2 -1
  65. package/dist/content-D5LJAHyM.js +0 -12
  66. package/dist/content-NCYIGgOb.cjs +0 -17
  67. package/dist/list-tools-DCF6G4fn.cjs +0 -52
  68. package/dist/mcp-CUGwXkxb.cjs +0 -153
  69. package/dist/mcp-Czp-hHjN.js +0 -148
@@ -0,0 +1,89 @@
1
+ const require_schema = require("./schema-D3vClxb7.cjs");
2
+ let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
3
+ //#region src/core/content.ts
4
+ /** Join the text of a result's `type: "text"` blocks into one string, dropping
5
+ * binary/resource blocks. Used to surface a `tool_error` message in the local
6
+ * log; never sent over the telemetry wire. Returns undefined when there is no
7
+ * text to show. */
8
+ function extractTextContent(content) {
9
+ if (!content) return void 0;
10
+ const text = content.filter((block) => block.type === "text").map((block) => block.text).join("\n").trim();
11
+ return text.length > 0 ? text : void 0;
12
+ }
13
+ //#endregion
14
+ //#region src/core/tool-result.ts
15
+ function normalizeResourceLinkIcon(icon) {
16
+ if (typeof icon.sizes !== "string") return icon;
17
+ const { sizes, ...rest } = icon;
18
+ const normalized = sizes.trim();
19
+ return normalized === "" ? rest : {
20
+ ...rest,
21
+ sizes: normalized.split(/\s+/)
22
+ };
23
+ }
24
+ function normalizeToolContent(content) {
25
+ return (content ?? []).map((block) => {
26
+ if (block.type !== "resource_link" || block.icons === void 0) return block;
27
+ return {
28
+ ...block,
29
+ icons: block.icons.map(normalizeResourceLinkIcon)
30
+ };
31
+ });
32
+ }
33
+ function outputValidationError(text) {
34
+ return {
35
+ content: [{
36
+ type: "text",
37
+ text
38
+ }],
39
+ isError: true
40
+ };
41
+ }
42
+ function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
43
+ if (value === null || typeof value === "boolean" || typeof value === "string") return true;
44
+ if (typeof value === "number") return Number.isFinite(value);
45
+ if (typeof value !== "object" || ancestors.has(value)) return false;
46
+ const prototype = Object.getPrototypeOf(value);
47
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return false;
48
+ ancestors.add(value);
49
+ const valid = Object.values(value).every((entry) => isJsonValue(entry, ancestors));
50
+ ancestors.delete(value);
51
+ return valid;
52
+ }
53
+ async function finalizeToolResult(tool, result) {
54
+ const content = normalizeToolContent(result.content);
55
+ let structuredContent = result.structuredContent;
56
+ if (tool.outputSchema && !result.isError) {
57
+ if (structuredContent === void 0) return outputValidationError(`Output validation error: Tool ${tool.name} has an output schema but no structured content was provided`);
58
+ try {
59
+ const parsed = await (0, _modelcontextprotocol_sdk_server_zod_compat_js.safeParseAsync)(require_schema.schemaFromDefinition(tool.outputSchema), structuredContent);
60
+ if (!parsed.success) return outputValidationError(`Output validation error: Invalid structured content for tool ${tool.name}: ${(0, _modelcontextprotocol_sdk_server_zod_compat_js.getParseErrorMessage)(parsed.error)}`);
61
+ structuredContent = parsed.data;
62
+ } catch {
63
+ return outputValidationError(`Output validation error: Could not validate structured content for tool ${tool.name}`);
64
+ }
65
+ }
66
+ if (structuredContent !== void 0 && !isJsonValue(structuredContent)) return outputValidationError(`Output validation error: Tool ${tool.name} returned a non-JSON structured value`);
67
+ if (structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent)) && !content.some((block) => block.type === "text")) content.push({
68
+ type: "text",
69
+ text: JSON.stringify(structuredContent)
70
+ });
71
+ return {
72
+ content,
73
+ structuredContent,
74
+ isError: result.isError
75
+ };
76
+ }
77
+ //#endregion
78
+ Object.defineProperty(exports, "extractTextContent", {
79
+ enumerable: true,
80
+ get: function() {
81
+ return extractTextContent;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "finalizeToolResult", {
85
+ enumerable: true,
86
+ get: function() {
87
+ return finalizeToolResult;
88
+ }
89
+ });
@@ -0,0 +1,78 @@
1
+ import { n as schemaFromDefinition } from "./schema-CW1jKvio.js";
2
+ import { getParseErrorMessage, safeParseAsync } from "@modelcontextprotocol/sdk/server/zod-compat.js";
3
+ //#region src/core/content.ts
4
+ /** Join the text of a result's `type: "text"` blocks into one string, dropping
5
+ * binary/resource blocks. Used to surface a `tool_error` message in the local
6
+ * log; never sent over the telemetry wire. Returns undefined when there is no
7
+ * text to show. */
8
+ function extractTextContent(content) {
9
+ if (!content) return void 0;
10
+ const text = content.filter((block) => block.type === "text").map((block) => block.text).join("\n").trim();
11
+ return text.length > 0 ? text : void 0;
12
+ }
13
+ //#endregion
14
+ //#region src/core/tool-result.ts
15
+ function normalizeResourceLinkIcon(icon) {
16
+ if (typeof icon.sizes !== "string") return icon;
17
+ const { sizes, ...rest } = icon;
18
+ const normalized = sizes.trim();
19
+ return normalized === "" ? rest : {
20
+ ...rest,
21
+ sizes: normalized.split(/\s+/)
22
+ };
23
+ }
24
+ function normalizeToolContent(content) {
25
+ return (content ?? []).map((block) => {
26
+ if (block.type !== "resource_link" || block.icons === void 0) return block;
27
+ return {
28
+ ...block,
29
+ icons: block.icons.map(normalizeResourceLinkIcon)
30
+ };
31
+ });
32
+ }
33
+ function outputValidationError(text) {
34
+ return {
35
+ content: [{
36
+ type: "text",
37
+ text
38
+ }],
39
+ isError: true
40
+ };
41
+ }
42
+ function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
43
+ if (value === null || typeof value === "boolean" || typeof value === "string") return true;
44
+ if (typeof value === "number") return Number.isFinite(value);
45
+ if (typeof value !== "object" || ancestors.has(value)) return false;
46
+ const prototype = Object.getPrototypeOf(value);
47
+ if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return false;
48
+ ancestors.add(value);
49
+ const valid = Object.values(value).every((entry) => isJsonValue(entry, ancestors));
50
+ ancestors.delete(value);
51
+ return valid;
52
+ }
53
+ async function finalizeToolResult(tool, result) {
54
+ const content = normalizeToolContent(result.content);
55
+ let structuredContent = result.structuredContent;
56
+ if (tool.outputSchema && !result.isError) {
57
+ if (structuredContent === void 0) return outputValidationError(`Output validation error: Tool ${tool.name} has an output schema but no structured content was provided`);
58
+ try {
59
+ const parsed = await safeParseAsync(schemaFromDefinition(tool.outputSchema), structuredContent);
60
+ if (!parsed.success) return outputValidationError(`Output validation error: Invalid structured content for tool ${tool.name}: ${getParseErrorMessage(parsed.error)}`);
61
+ structuredContent = parsed.data;
62
+ } catch {
63
+ return outputValidationError(`Output validation error: Could not validate structured content for tool ${tool.name}`);
64
+ }
65
+ }
66
+ if (structuredContent !== void 0 && !isJsonValue(structuredContent)) return outputValidationError(`Output validation error: Tool ${tool.name} returned a non-JSON structured value`);
67
+ if (structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent)) && !content.some((block) => block.type === "text")) content.push({
68
+ type: "text",
69
+ text: JSON.stringify(structuredContent)
70
+ });
71
+ return {
72
+ content,
73
+ structuredContent,
74
+ isError: result.isError
75
+ };
76
+ }
77
+ //#endregion
78
+ export { extractTextContent as n, finalizeToolResult as t };
@@ -150,9 +150,11 @@ type MetricsConfig = boolean | MetricsOptions;
150
150
  type ZodSchema = ZodType;
151
151
  /**
152
152
  * A raw zod shape (`{ text: z.string(), n: z.number() }`) — the format
153
- * `defineTool`'s `inputSchema`/`outputSchema` expects.
153
+ * `defineTool`'s `inputSchema` expects and the object shorthand accepted by
154
+ * `outputSchema`.
154
155
  */
155
156
  type ZodRawShape$1 = ZodRawShape;
157
+ type ZodOutputSchema = ZodSchema | ZodRawShape$1;
156
158
  /**
157
159
  * Infer the parsed-output type of a zod raw shape — given
158
160
  * `{ text: ZodString, n: ZodNumber }`, produces `{ text: string, n: number }`.
@@ -217,8 +219,8 @@ type EmbeddedResource = EmbeddedTextResource | EmbeddedBlobResource;
217
219
  interface ResourceLinkIcon {
218
220
  src: string;
219
221
  mimeType?: string;
220
- /** Space-separated dimension string, HTML `<link sizes>` convention (e.g. `"16x16 32x32"`). */
221
- sizes?: string;
222
+ /** Array per MCP 2026-07-28; legacy space-separated strings remain accepted. */
223
+ sizes?: string | string[];
222
224
  theme?: "light" | "dark";
223
225
  }
224
226
  interface ResourceLink extends ContentBlockBase {
@@ -241,6 +243,10 @@ type ContentBlock = TextContent | ImageContent | AudioContent | EmbeddedResource
241
243
  * the tool returns to the caller.
242
244
  */
243
245
  type ToolContent = ContentBlock[];
246
+ type JsonValue = null | boolean | number | string | JsonValue[] | {
247
+ [key: string]: JsonValue;
248
+ };
249
+ type McpAllowedOrigins = "any" | readonly string[];
244
250
  /**
245
251
  * Per-tool client hints (not enforcement). `annotations.title` is
246
252
  * intentionally omitted — use `ToolDefinition.title`, which the MCP
@@ -258,10 +264,10 @@ interface ToolAnnotations {
258
264
  }
259
265
  interface ToolHandlerResult {
260
266
  content?: ToolContent;
261
- structuredContent?: Record<string, unknown>;
267
+ structuredContent?: JsonValue;
262
268
  isError?: boolean;
263
269
  }
264
- interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined, TOutput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined> {
270
+ interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined, TOutput extends ZodOutputSchema | undefined = ZodOutputSchema | undefined> {
265
271
  readonly name: string;
266
272
  /** Human-readable display name shown to the user in MCP clients. Required. */
267
273
  readonly title: string;
@@ -281,7 +287,7 @@ interface AnyToolDefinition {
281
287
  readonly title: string;
282
288
  readonly description: string;
283
289
  readonly inputSchema?: ZodRawShape$1;
284
- readonly outputSchema?: ZodRawShape$1;
290
+ readonly outputSchema?: ZodOutputSchema;
285
291
  readonly annotations?: ToolAnnotations;
286
292
  readonly handler: (args: any, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
287
293
  }
@@ -298,6 +304,8 @@ interface McpDefinitionInput {
298
304
  readonly title: string;
299
305
  readonly version: string;
300
306
  readonly auth?: McpAuthConfig;
307
+ /** Cross-origin browser access. Omit to allow only same-origin and non-browser requests. */
308
+ readonly allowedOrigins?: McpAllowedOrigins;
301
309
  /**
302
310
  * Server-level prose the LLM reads as context for all tools on this server.
303
311
  * Required for the same reason `ToolDefinition.description` is — optional
@@ -318,4 +326,4 @@ type McpDefinition = McpDefinitionInput & {
318
326
  readonly [McpDefinitionBrand]: never;
319
327
  };
320
328
  //#endregion
321
- export { McpAuthConfig as C, JwtClaims as S, ZodRawShape$1 as _, EmbeddedResource as a, MetricsOptions as b, McpDefinition as c, ResourceLinkIcon as d, TextContent as f, ToolHandlerResult as g, ToolDefinition as h, EmbeddedBlobResource as i, McpDefinitionInput as l, ToolContent as m, ContentAnnotations as n, EmbeddedTextResource as o, ToolAnnotations as p, ContentBlock as r, ImageContent as s, AudioContent as t, ResourceLink as u, ZodSchema as v, ToolContext as x, MetricsConfig as y };
329
+ export { MetricsOptions as C, McpAuthConfig as E, MetricsConfig as S, JwtClaims as T, ToolDefinition as _, EmbeddedResource as a, ZodRawShape$1 as b, JsonValue as c, McpDefinitionInput as d, ResourceLink as f, ToolContent as g, ToolAnnotations as h, EmbeddedBlobResource as i, McpAllowedOrigins as l, TextContent as m, ContentAnnotations as n, EmbeddedTextResource as o, ResourceLinkIcon as p, ContentBlock as r, ImageContent as s, AudioContent as t, McpDefinition as u, ToolHandlerResult as v, ToolContext as w, ZodSchema as x, ZodOutputSchema as y };
@@ -150,9 +150,11 @@ type MetricsConfig = boolean | MetricsOptions;
150
150
  type ZodSchema = ZodType;
151
151
  /**
152
152
  * A raw zod shape (`{ text: z.string(), n: z.number() }`) — the format
153
- * `defineTool`'s `inputSchema`/`outputSchema` expects.
153
+ * `defineTool`'s `inputSchema` expects and the object shorthand accepted by
154
+ * `outputSchema`.
154
155
  */
155
156
  type ZodRawShape$1 = ZodRawShape;
157
+ type ZodOutputSchema = ZodSchema | ZodRawShape$1;
156
158
  /**
157
159
  * Infer the parsed-output type of a zod raw shape — given
158
160
  * `{ text: ZodString, n: ZodNumber }`, produces `{ text: string, n: number }`.
@@ -217,8 +219,8 @@ type EmbeddedResource = EmbeddedTextResource | EmbeddedBlobResource;
217
219
  interface ResourceLinkIcon {
218
220
  src: string;
219
221
  mimeType?: string;
220
- /** Space-separated dimension string, HTML `<link sizes>` convention (e.g. `"16x16 32x32"`). */
221
- sizes?: string;
222
+ /** Array per MCP 2026-07-28; legacy space-separated strings remain accepted. */
223
+ sizes?: string | string[];
222
224
  theme?: "light" | "dark";
223
225
  }
224
226
  interface ResourceLink extends ContentBlockBase {
@@ -241,6 +243,10 @@ type ContentBlock = TextContent | ImageContent | AudioContent | EmbeddedResource
241
243
  * the tool returns to the caller.
242
244
  */
243
245
  type ToolContent = ContentBlock[];
246
+ type JsonValue = null | boolean | number | string | JsonValue[] | {
247
+ [key: string]: JsonValue;
248
+ };
249
+ type McpAllowedOrigins = "any" | readonly string[];
244
250
  /**
245
251
  * Per-tool client hints (not enforcement). `annotations.title` is
246
252
  * intentionally omitted — use `ToolDefinition.title`, which the MCP
@@ -258,10 +264,10 @@ interface ToolAnnotations {
258
264
  }
259
265
  interface ToolHandlerResult {
260
266
  content?: ToolContent;
261
- structuredContent?: Record<string, unknown>;
267
+ structuredContent?: JsonValue;
262
268
  isError?: boolean;
263
269
  }
264
- interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined, TOutput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined> {
270
+ interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined, TOutput extends ZodOutputSchema | undefined = ZodOutputSchema | undefined> {
265
271
  readonly name: string;
266
272
  /** Human-readable display name shown to the user in MCP clients. Required. */
267
273
  readonly title: string;
@@ -281,7 +287,7 @@ interface AnyToolDefinition {
281
287
  readonly title: string;
282
288
  readonly description: string;
283
289
  readonly inputSchema?: ZodRawShape$1;
284
- readonly outputSchema?: ZodRawShape$1;
290
+ readonly outputSchema?: ZodOutputSchema;
285
291
  readonly annotations?: ToolAnnotations;
286
292
  readonly handler: (args: any, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
287
293
  }
@@ -298,6 +304,8 @@ interface McpDefinitionInput {
298
304
  readonly title: string;
299
305
  readonly version: string;
300
306
  readonly auth?: McpAuthConfig;
307
+ /** Cross-origin browser access. Omit to allow only same-origin and non-browser requests. */
308
+ readonly allowedOrigins?: McpAllowedOrigins;
301
309
  /**
302
310
  * Server-level prose the LLM reads as context for all tools on this server.
303
311
  * Required for the same reason `ToolDefinition.description` is — optional
@@ -318,4 +326,4 @@ type McpDefinition = McpDefinitionInput & {
318
326
  readonly [McpDefinitionBrand]: never;
319
327
  };
320
328
  //#endregion
321
- export { McpAuthConfig as C, JwtClaims as S, ZodRawShape$1 as _, EmbeddedResource as a, MetricsOptions as b, McpDefinition as c, ResourceLinkIcon as d, TextContent as f, ToolHandlerResult as g, ToolDefinition as h, EmbeddedBlobResource as i, McpDefinitionInput as l, ToolContent as m, ContentAnnotations as n, EmbeddedTextResource as o, ToolAnnotations as p, ContentBlock as r, ImageContent as s, AudioContent as t, ResourceLink as u, ZodSchema as v, ToolContext as x, MetricsConfig as y };
329
+ export { MetricsOptions as C, McpAuthConfig as E, MetricsConfig as S, JwtClaims as T, ToolDefinition as _, EmbeddedResource as a, ZodRawShape$1 as b, JsonValue as c, McpDefinitionInput as d, ResourceLink as f, ToolContent as g, ToolAnnotations as h, EmbeddedBlobResource as i, McpAllowedOrigins as l, TextContent as m, ContentAnnotations as n, EmbeddedTextResource as o, ResourceLinkIcon as p, ContentBlock as r, ImageContent as s, AudioContent as t, McpDefinition as u, ToolHandlerResult as v, ToolContext as w, ZodSchema as x, ZodOutputSchema as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/mcp-js",
3
- "version": "0.28.0",
3
+ "version": "0.29.0-rc.0",
4
4
  "description": "Author MCP servers for Lovable apps. Declare tools with defineTool, register them in defineMcp, and a framework adapter (TanStack or Supabase Edge Functions) emits the route(s) at build time.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -116,6 +116,7 @@
116
116
  "license": "MIT",
117
117
  "dependencies": {
118
118
  "@modelcontextprotocol/sdk": "1.28.0",
119
+ "@modelcontextprotocol/server": "2.0.0",
119
120
  "esbuild": "^0.27.0",
120
121
  "jose": "^6.2.2"
121
122
  },
@@ -1,12 +0,0 @@
1
- //#region src/core/content.ts
2
- /** Join the text of a result's `type: "text"` blocks into one string, dropping
3
- * binary/resource blocks. Used to surface a `tool_error` message in the local
4
- * log; never sent over the telemetry wire. Returns undefined when there is no
5
- * text to show. */
6
- function extractTextContent(content) {
7
- if (!content) return void 0;
8
- const text = content.filter((block) => block.type === "text").map((block) => block.text).join("\n").trim();
9
- return text.length > 0 ? text : void 0;
10
- }
11
- //#endregion
12
- export { extractTextContent as t };
@@ -1,17 +0,0 @@
1
- //#region src/core/content.ts
2
- /** Join the text of a result's `type: "text"` blocks into one string, dropping
3
- * binary/resource blocks. Used to surface a `tool_error` message in the local
4
- * log; never sent over the telemetry wire. Returns undefined when there is no
5
- * text to show. */
6
- function extractTextContent(content) {
7
- if (!content) return void 0;
8
- const text = content.filter((block) => block.type === "text").map((block) => block.text).join("\n").trim();
9
- return text.length > 0 ? text : void 0;
10
- }
11
- //#endregion
12
- Object.defineProperty(exports, "extractTextContent", {
13
- enumerable: true,
14
- get: function() {
15
- return extractTextContent;
16
- }
17
- });
@@ -1,52 +0,0 @@
1
- const require_authorize = require("./authorize-ChY44o_1.cjs");
2
- const require_gate = require("./gate-CGZl0gjJ.cjs");
3
- let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
4
- let _modelcontextprotocol_sdk_server_zod_json_schema_compat_js = require("@modelcontextprotocol/sdk/server/zod-json-schema-compat.js");
5
- //#region src/protocols/rest/list-tools.ts
6
- function shapeToJsonSchema(shape) {
7
- if (!shape) return null;
8
- try {
9
- return (0, _modelcontextprotocol_sdk_server_zod_json_schema_compat_js.toJsonSchemaCompat)((0, _modelcontextprotocol_sdk_server_zod_compat_js.objectFromShape)(shape));
10
- } catch {
11
- return null;
12
- }
13
- }
14
- function buildMcpListing(mcp) {
15
- return {
16
- server: {
17
- name: mcp.name,
18
- version: mcp.version,
19
- title: mcp.title
20
- },
21
- tools: mcp.tools.map((tool) => ({
22
- name: tool.name,
23
- title: tool.title,
24
- description: tool.description,
25
- annotations: tool.annotations,
26
- inputSchema: shapeToJsonSchema(tool.inputSchema),
27
- outputSchema: shapeToJsonSchema(tool.outputSchema)
28
- }))
29
- };
30
- }
31
- function createListToolsHandler(mcp, options = {}) {
32
- require_authorize.assertRestResourceBinding(mcp, options);
33
- return require_gate.createGatedHandler({
34
- authorizer: require_authorize.createRequestAuthorizer(mcp, options),
35
- methods: ["GET", "HEAD"],
36
- methodNotAllowed: require_authorize.methodNotAllowed,
37
- handle: async () => Response.json(buildMcpListing(mcp))
38
- });
39
- }
40
- //#endregion
41
- Object.defineProperty(exports, "buildMcpListing", {
42
- enumerable: true,
43
- get: function() {
44
- return buildMcpListing;
45
- }
46
- });
47
- Object.defineProperty(exports, "createListToolsHandler", {
48
- enumerable: true,
49
- get: function() {
50
- return createListToolsHandler;
51
- }
52
- });
@@ -1,153 +0,0 @@
1
- const require_logger = require("./logger-CN1q-KNn.cjs");
2
- const require_errors = require("./errors-CN6Da8iz.cjs");
3
- const require_authorize = require("./authorize-ChY44o_1.cjs");
4
- const require_content = require("./content-NCYIGgOb.cjs");
5
- const require_gate = require("./gate-CGZl0gjJ.cjs");
6
- let _modelcontextprotocol_sdk_server_mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
7
- let _modelcontextprotocol_sdk_server_webStandardStreamableHttp_js = require("@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js");
8
- //#region src/protocols/mcp/protocol.ts
9
- function statelessMethodNotAllowed(allow) {
10
- return Response.json({
11
- jsonrpc: "2.0",
12
- id: null,
13
- error: {
14
- code: -32e3,
15
- message: "Method not allowed: stateless server offers no standalone SSE stream (GET) or session (DELETE)."
16
- }
17
- }, {
18
- status: 405,
19
- headers: { Allow: allow }
20
- });
21
- }
22
- /**
23
- * Adapt a Lovable tool to the SDK's tool callback. The boundary cast bridges
24
- * our SDK-decoupled content-block types to the SDK's; they match structurally.
25
- */
26
- function adaptToolToSdkCallback(tool, auth, recorder) {
27
- const endUserId = auth?.principal.sub;
28
- return (async (first) => {
29
- const args = tool.inputSchema ? first ?? {} : {};
30
- const start = require_authorize.nowMs();
31
- let result;
32
- try {
33
- result = await tool.handler(args, new require_errors.ToolContext(auth));
34
- } catch (err) {
35
- const callerMessage = require_errors.resolveToolErrorMessage(err);
36
- if (callerMessage === void 0) {
37
- await recorder.emit({
38
- tool: tool.name,
39
- method: "tools/call",
40
- outcome: "handler_error",
41
- durationMs: require_authorize.nowMs() - start,
42
- errorText: require_errors.errorSummary(err),
43
- endUserId
44
- });
45
- return {
46
- content: [{
47
- type: "text",
48
- text: "tool execution failed"
49
- }],
50
- isError: true
51
- };
52
- }
53
- result = {
54
- content: [{
55
- type: "text",
56
- text: callerMessage
57
- }],
58
- isError: true
59
- };
60
- }
61
- if (result == null) {
62
- await recorder.emit({
63
- tool: tool.name,
64
- method: "tools/call",
65
- outcome: "handler_error",
66
- durationMs: require_authorize.nowMs() - start,
67
- endUserId
68
- });
69
- return {
70
- content: [{
71
- type: "text",
72
- text: `tool "${tool.name}" returned no result`
73
- }],
74
- isError: true
75
- };
76
- }
77
- await recorder.emit({
78
- tool: tool.name,
79
- method: "tools/call",
80
- outcome: result.isError ? "tool_error" : "ok",
81
- durationMs: require_authorize.nowMs() - start,
82
- errorText: result.isError ? require_content.extractTextContent(result.content) : void 0,
83
- endUserId
84
- });
85
- return {
86
- content: result.content ?? [],
87
- structuredContent: result.structuredContent,
88
- isError: result.isError
89
- };
90
- });
91
- }
92
- /**
93
- * Build a Web-Standard request handler that serves the MCP protocol over
94
- * streamable HTTP. A fresh `McpServer` + transport is constructed per
95
- * request — the transport is stateless, so this is cheap and there is no
96
- * cross-request state to leak. The per-request `recorder` is supplied by the
97
- * caller (the stack handler) so telemetry reads the runtime env in-flight.
98
- */
99
- function createMcpProtocolHandler(mcp, options = {}) {
100
- const authorizer = require_authorize.createRequestAuthorizer(mcp, options);
101
- const handle = async (request, authResult, recorder) => {
102
- try {
103
- const server = new _modelcontextprotocol_sdk_server_mcp_js.McpServer({
104
- name: mcp.name,
105
- version: mcp.version,
106
- title: mcp.title
107
- }, { instructions: mcp.instructions });
108
- for (const tool of mcp.tools) server.registerTool(tool.name, {
109
- title: tool.title,
110
- description: tool.description,
111
- inputSchema: tool.inputSchema,
112
- outputSchema: tool.outputSchema,
113
- annotations: tool.annotations
114
- }, adaptToolToSdkCallback(tool, authResult.auth, recorder));
115
- const transport = new _modelcontextprotocol_sdk_server_webStandardStreamableHttp_js.WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
116
- await server.connect(transport);
117
- return await transport.handleRequest(request);
118
- } catch (err) {
119
- await recorder.emit({
120
- tool: null,
121
- method: "transport",
122
- outcome: "transport_error",
123
- durationMs: 0,
124
- endUserId: authResult.auth?.principal.sub
125
- });
126
- require_logger.log.error("mcp.transport_error", {
127
- ...require_logger.describeError(err),
128
- outcome: "500 internal error"
129
- });
130
- return Response.json({
131
- jsonrpc: "2.0",
132
- id: null,
133
- error: {
134
- code: -32603,
135
- message: "internal error"
136
- }
137
- }, { status: 500 });
138
- }
139
- };
140
- return require_gate.createGatedHandler({
141
- authorizer,
142
- methods: ["POST"],
143
- methodNotAllowed: statelessMethodNotAllowed,
144
- handle
145
- });
146
- }
147
- //#endregion
148
- Object.defineProperty(exports, "createMcpProtocolHandler", {
149
- enumerable: true,
150
- get: function() {
151
- return createMcpProtocolHandler;
152
- }
153
- });