@lovable.dev/mcp-js 0.29.0-rc.1 → 0.29.0-rc.3

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.internal.md +22 -31
  2. package/README.md +23 -13
  3. package/dist/{authorize-BjNE3LPr.d.ts → authorize-9hTTG-qJ.d.cts} +2 -5
  4. package/dist/{authorize-BzZFS0zi.d.cts → authorize-DNUlPT7k.d.ts} +2 -5
  5. package/dist/{base-C8osWdMU.d.cts → base-7cq6HCPO.d.ts} +3 -2
  6. package/dist/{base-C8osWdMU.d.ts → base-CHNFFrMG.d.cts} +3 -2
  7. package/dist/cli/extract-manifest.cjs +25 -3
  8. package/dist/cli/extract-manifest.js +24 -2
  9. package/dist/{cors-BRv5KXKQ.cjs → cors-BDv7pyfD.cjs} +26 -30
  10. package/dist/{cors-BDTQQJE2.js → cors-kKiIJSyL.js} +21 -25
  11. package/dist/{errors-DSe96Ffd.js → errors-Bwd1L0Rf.js} +23 -8
  12. package/dist/{errors-CN6Da8iz.cjs → errors-Cr95rSkB.cjs} +23 -8
  13. package/dist/forwarded-Bnrwxbuj.js +25 -0
  14. package/dist/forwarded-OdBzzCMF.cjs +30 -0
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.d.cts +2 -2
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.js +1 -1
  19. package/dist/{io-BYUyNFdn.d.ts → io-CDV3mud0.d.cts} +1 -1
  20. package/dist/{io-B_YLNWDL.d.cts → io-D_5cuaEL.d.ts} +1 -1
  21. package/dist/mcp-BSNdmnJl.cjs +353 -0
  22. package/dist/mcp-GT9WU7nd.js +348 -0
  23. package/dist/{package-BI5r4uGM.js → package-2ZppkCKf.js} +1 -1
  24. package/dist/{package-ClCIqol1.cjs → package-DAQNwT8T.cjs} +1 -1
  25. package/dist/protocols/mcp/index.cjs +1 -1
  26. package/dist/protocols/mcp/index.d.cts +3 -3
  27. package/dist/protocols/mcp/index.d.ts +3 -3
  28. package/dist/protocols/mcp/index.js +1 -1
  29. package/dist/protocols/oauth-metadata.cjs +18 -3
  30. package/dist/protocols/oauth-metadata.d.cts +4 -3
  31. package/dist/protocols/oauth-metadata.d.ts +4 -3
  32. package/dist/protocols/oauth-metadata.js +18 -3
  33. package/dist/stacks/supabase/index.cjs +7 -36
  34. package/dist/stacks/supabase/index.d.cts +1 -4
  35. package/dist/stacks/supabase/index.d.ts +1 -4
  36. package/dist/stacks/supabase/index.js +7 -36
  37. package/dist/stacks/supabase/vite.cjs +1 -1
  38. package/dist/stacks/supabase/vite.d.cts +1 -1
  39. package/dist/stacks/supabase/vite.d.ts +1 -1
  40. package/dist/stacks/supabase/vite.js +1 -1
  41. package/dist/stacks/tanstack/index.cjs +4 -25
  42. package/dist/stacks/tanstack/index.d.cts +3 -20
  43. package/dist/stacks/tanstack/index.d.ts +3 -20
  44. package/dist/stacks/tanstack/index.js +5 -24
  45. package/dist/stacks/tanstack/vite.cjs +5 -33
  46. package/dist/stacks/tanstack/vite.d.cts +5 -28
  47. package/dist/stacks/tanstack/vite.d.ts +5 -28
  48. package/dist/stacks/tanstack/vite.js +5 -33
  49. package/dist/{types-D1cgsnPu.d.cts → types-3CZPz364.d.cts} +54 -26
  50. package/dist/{types-D1cgsnPu.d.ts → types-3CZPz364.d.ts} +54 -26
  51. package/package.json +4 -11
  52. package/dist/forwarded-B3EBjHnA.js +0 -43
  53. package/dist/forwarded-BC_RHnn5.cjs +0 -48
  54. package/dist/gate-CAJSRt_t.cjs +0 -26
  55. package/dist/gate-uCVrbDBb.js +0 -21
  56. package/dist/list-tools-C1OiTDR9.js +0 -37
  57. package/dist/list-tools-C3AoI2Zw.d.cts +0 -8
  58. package/dist/list-tools-DES10avA.cjs +0 -48
  59. package/dist/list-tools-DXqSPvNY.d.ts +0 -8
  60. package/dist/mcp-C9B7o75m.cjs +0 -345
  61. package/dist/mcp-HDkUr85V.js +0 -340
  62. package/dist/protocols/rest/index.cjs +0 -5
  63. package/dist/protocols/rest/index.d.cts +0 -9
  64. package/dist/protocols/rest/index.d.ts +0 -9
  65. package/dist/protocols/rest/index.js +0 -3
  66. package/dist/rest-BBdfHMGh.cjs +0 -134
  67. package/dist/rest-Cr7NhxL3.js +0 -129
  68. package/dist/tool-result-CK6hXO43.cjs +0 -89
  69. package/dist/tool-result-DfCk445b.js +0 -78
@@ -85,16 +85,49 @@ interface McpAuthConfig {
85
85
  }
86
86
  //#endregion
87
87
  //#region src/auth/context.d.ts
88
- /**
89
- * The auth surface passed to every tool handler as its second argument. It wraps
90
- * the verified per-request auth context in a private field, so the context — and
91
- * the bearer token inside it can't be read, enumerated, spread, or
92
- * `JSON.stringify`'d off the instance; the accessors below are the only way out.
93
- * `getToken()` is the single intentional escape hatch for the raw bearer.
94
- */
88
+ /** Protocol era of an in-flight request: self-describing `2026-07-28` or the
89
+ * initialization-era `legacy` fallback. */
90
+ type McpProtocolEra = "2026-07-28" | "legacy";
91
+ /** What the client declared about itself on the in-flight request. Unverified
92
+ * client input a hint, never an authorization signal (use the auth accessors). */
93
+ interface McpClientInfo {
94
+ /** Protocol era of the in-flight request. */
95
+ protocol: McpProtocolEra;
96
+ /** Client name/version from the request envelope (`2026-07-28` era only). */
97
+ info?: {
98
+ name: string;
99
+ version: string;
100
+ title?: string;
101
+ };
102
+ /** Client capabilities from the request envelope (`2026-07-28` era only). */
103
+ capabilities?: Record<string, unknown>;
104
+ /** Extension declarations (`capabilities.extensions`), keyed by extension id. */
105
+ extensions?: Record<string, Record<string, unknown>>;
106
+ }
107
+ /** A progress notification payload. `progress` should increase monotonically. */
108
+ interface ProgressUpdate {
109
+ progress: number;
110
+ total?: number;
111
+ message?: string;
112
+ }
113
+ /** Per-request runtime surface threaded into `ToolContext` by the protocol layer. */
114
+ interface ToolRequestContext {
115
+ signal?: AbortSignal;
116
+ client?: McpClientInfo;
117
+ sendProgress?: (update: ProgressUpdate) => Promise<void>;
118
+ }
119
+ /** The per-request context passed to every tool handler as its second argument. The
120
+ * auth context lives in a private field so the accessors are the only way out; `getToken()` is the sole bearer escape hatch. */
95
121
  declare class ToolContext {
96
122
  #private;
97
- constructor(auth: McpAuthContext | undefined);
123
+ constructor(auth: McpAuthContext | undefined, request?: ToolRequestContext);
124
+ /** Aborts when the client cancels the request or disconnects. */
125
+ get signal(): AbortSignal;
126
+ /** What the client declared about itself on this request. Unverified input. */
127
+ get client(): McpClientInfo;
128
+ /** Send a progress notification for this call. A no-op when the client
129
+ * didn't request progress (no `progressToken` on the request). */
130
+ progress(update: ProgressUpdate): Promise<void>;
98
131
  /** Whether the in-flight tool call carries a verified auth context. */
99
132
  isAuthenticated(): boolean;
100
133
  /** The verified bearer token, or `undefined` when unauthenticated. Pass it to downstream APIs; never return or log it. */
@@ -148,11 +181,8 @@ type MetricsConfig = boolean | MetricsOptions;
148
181
  * `inputSchema`, use `ZodRawShape`.
149
182
  */
150
183
  type ZodSchema = ZodType;
151
- /**
152
- * A raw zod shape (`{ text: z.string(), n: z.number() }`) — the format
153
- * `defineTool`'s `inputSchema` expects and the object shorthand accepted by
154
- * `outputSchema`.
155
- */
184
+ /** A raw zod shape (`{ text: z.string() }`) — the format `defineTool`'s
185
+ * `inputSchema` expects and the object shorthand accepted by `outputSchema`. */
156
186
  type ZodRawShape$1 = ZodRawShape;
157
187
  type ZodOutputSchema = ZodSchema | ZodRawShape$1;
158
188
  /**
@@ -246,6 +276,11 @@ type ToolContent = ContentBlock[];
246
276
  type JsonValue = null | boolean | number | string | JsonValue[] | {
247
277
  [key: string]: JsonValue;
248
278
  };
279
+ /** Handler-input relaxation of `JsonValue`: object properties may be `undefined`
280
+ * (they serialize away, matching `JSON.stringify` semantics). */
281
+ type JsonValueInput = null | boolean | number | string | JsonValueInput[] | {
282
+ [key: string]: JsonValueInput | undefined;
283
+ };
249
284
  type McpAllowedOrigins = "any" | readonly string[];
250
285
  /**
251
286
  * Per-tool client hints (not enforcement). `annotations.title` is
@@ -264,7 +299,7 @@ interface ToolAnnotations {
264
299
  }
265
300
  interface ToolHandlerResult {
266
301
  content?: ToolContent;
267
- structuredContent?: JsonValue;
302
+ structuredContent?: JsonValueInput;
268
303
  isError?: boolean;
269
304
  }
270
305
  interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined, TOutput extends ZodOutputSchema | undefined = ZodOutputSchema | undefined> {
@@ -278,10 +313,8 @@ interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$
278
313
  readonly annotations?: ToolAnnotations;
279
314
  readonly handler: TInput extends ZodRawShape$1 ? (args: ShapeOutput<TInput>, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult> : (args: Record<string, never> | undefined, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
280
315
  }
281
- /**
282
- * Type-erased element of `McpDefinition.tools`. Per-tool generic typing
283
- * happens at the `defineTool` call site; see README §6 for the rationale.
284
- */
316
+ /** Type-erased element of `McpDefinition.tools`; per-tool generic typing
317
+ * happens at the `defineTool` call site. */
285
318
  interface AnyToolDefinition {
286
319
  readonly name: string;
287
320
  readonly title: string;
@@ -291,13 +324,8 @@ interface AnyToolDefinition {
291
324
  readonly annotations?: ToolAnnotations;
292
325
  readonly handler: (args: any, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
293
326
  }
294
- /**
295
- * Fields a caller supplies when constructing an MCP definition. Pass this
296
- * shape to `defineMcp(...)` — its return type is the branded `McpDefinition`,
297
- * which is the type every internal factory (`createInvokeToolHandler`,
298
- * `createMcpProtocolHandler`, …) consumes. The brand forces consumers
299
- * through `defineMcp`'s `assertUniqueNames` + freeze.
300
- */
327
+ /** Input shape for `defineMcp(...)`, whose branded `McpDefinition` return type is what
328
+ * `createMcpProtocolHandler` consumes the brand forces validation + freeze. */
301
329
  interface McpDefinitionInput {
302
330
  readonly name: string;
303
331
  /** Human-readable display name shown to MCP clients. Required. */
@@ -326,4 +354,4 @@ type McpDefinition = McpDefinitionInput & {
326
354
  readonly [McpDefinitionBrand]: never;
327
355
  };
328
356
  //#endregion
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 };
357
+ export { McpAuthConfig as A, MetricsConfig as C, ProgressUpdate as D, McpProtocolEra as E, ToolContext as O, ZodSchema as S, McpClientInfo as T, ToolContent as _, EmbeddedResource as a, ZodOutputSchema as b, JsonValue as c, McpDefinition as d, McpDefinitionInput as f, ToolAnnotations as g, TextContent as h, EmbeddedBlobResource as i, JwtClaims as k, JsonValueInput as l, ResourceLinkIcon as m, ContentAnnotations as n, EmbeddedTextResource as o, ResourceLink as p, ContentBlock as r, ImageContent as s, AudioContent as t, McpAllowedOrigins as u, ToolDefinition as v, MetricsOptions as w, ZodRawShape$1 as x, ToolHandlerResult as y };
@@ -85,16 +85,49 @@ interface McpAuthConfig {
85
85
  }
86
86
  //#endregion
87
87
  //#region src/auth/context.d.ts
88
- /**
89
- * The auth surface passed to every tool handler as its second argument. It wraps
90
- * the verified per-request auth context in a private field, so the context — and
91
- * the bearer token inside it can't be read, enumerated, spread, or
92
- * `JSON.stringify`'d off the instance; the accessors below are the only way out.
93
- * `getToken()` is the single intentional escape hatch for the raw bearer.
94
- */
88
+ /** Protocol era of an in-flight request: self-describing `2026-07-28` or the
89
+ * initialization-era `legacy` fallback. */
90
+ type McpProtocolEra = "2026-07-28" | "legacy";
91
+ /** What the client declared about itself on the in-flight request. Unverified
92
+ * client input a hint, never an authorization signal (use the auth accessors). */
93
+ interface McpClientInfo {
94
+ /** Protocol era of the in-flight request. */
95
+ protocol: McpProtocolEra;
96
+ /** Client name/version from the request envelope (`2026-07-28` era only). */
97
+ info?: {
98
+ name: string;
99
+ version: string;
100
+ title?: string;
101
+ };
102
+ /** Client capabilities from the request envelope (`2026-07-28` era only). */
103
+ capabilities?: Record<string, unknown>;
104
+ /** Extension declarations (`capabilities.extensions`), keyed by extension id. */
105
+ extensions?: Record<string, Record<string, unknown>>;
106
+ }
107
+ /** A progress notification payload. `progress` should increase monotonically. */
108
+ interface ProgressUpdate {
109
+ progress: number;
110
+ total?: number;
111
+ message?: string;
112
+ }
113
+ /** Per-request runtime surface threaded into `ToolContext` by the protocol layer. */
114
+ interface ToolRequestContext {
115
+ signal?: AbortSignal;
116
+ client?: McpClientInfo;
117
+ sendProgress?: (update: ProgressUpdate) => Promise<void>;
118
+ }
119
+ /** The per-request context passed to every tool handler as its second argument. The
120
+ * auth context lives in a private field so the accessors are the only way out; `getToken()` is the sole bearer escape hatch. */
95
121
  declare class ToolContext {
96
122
  #private;
97
- constructor(auth: McpAuthContext | undefined);
123
+ constructor(auth: McpAuthContext | undefined, request?: ToolRequestContext);
124
+ /** Aborts when the client cancels the request or disconnects. */
125
+ get signal(): AbortSignal;
126
+ /** What the client declared about itself on this request. Unverified input. */
127
+ get client(): McpClientInfo;
128
+ /** Send a progress notification for this call. A no-op when the client
129
+ * didn't request progress (no `progressToken` on the request). */
130
+ progress(update: ProgressUpdate): Promise<void>;
98
131
  /** Whether the in-flight tool call carries a verified auth context. */
99
132
  isAuthenticated(): boolean;
100
133
  /** The verified bearer token, or `undefined` when unauthenticated. Pass it to downstream APIs; never return or log it. */
@@ -148,11 +181,8 @@ type MetricsConfig = boolean | MetricsOptions;
148
181
  * `inputSchema`, use `ZodRawShape`.
149
182
  */
150
183
  type ZodSchema = ZodType;
151
- /**
152
- * A raw zod shape (`{ text: z.string(), n: z.number() }`) — the format
153
- * `defineTool`'s `inputSchema` expects and the object shorthand accepted by
154
- * `outputSchema`.
155
- */
184
+ /** A raw zod shape (`{ text: z.string() }`) — the format `defineTool`'s
185
+ * `inputSchema` expects and the object shorthand accepted by `outputSchema`. */
156
186
  type ZodRawShape$1 = ZodRawShape;
157
187
  type ZodOutputSchema = ZodSchema | ZodRawShape$1;
158
188
  /**
@@ -246,6 +276,11 @@ type ToolContent = ContentBlock[];
246
276
  type JsonValue = null | boolean | number | string | JsonValue[] | {
247
277
  [key: string]: JsonValue;
248
278
  };
279
+ /** Handler-input relaxation of `JsonValue`: object properties may be `undefined`
280
+ * (they serialize away, matching `JSON.stringify` semantics). */
281
+ type JsonValueInput = null | boolean | number | string | JsonValueInput[] | {
282
+ [key: string]: JsonValueInput | undefined;
283
+ };
249
284
  type McpAllowedOrigins = "any" | readonly string[];
250
285
  /**
251
286
  * Per-tool client hints (not enforcement). `annotations.title` is
@@ -264,7 +299,7 @@ interface ToolAnnotations {
264
299
  }
265
300
  interface ToolHandlerResult {
266
301
  content?: ToolContent;
267
- structuredContent?: JsonValue;
302
+ structuredContent?: JsonValueInput;
268
303
  isError?: boolean;
269
304
  }
270
305
  interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$1 | undefined, TOutput extends ZodOutputSchema | undefined = ZodOutputSchema | undefined> {
@@ -278,10 +313,8 @@ interface ToolDefinition<TInput extends ZodRawShape$1 | undefined = ZodRawShape$
278
313
  readonly annotations?: ToolAnnotations;
279
314
  readonly handler: TInput extends ZodRawShape$1 ? (args: ShapeOutput<TInput>, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult> : (args: Record<string, never> | undefined, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
280
315
  }
281
- /**
282
- * Type-erased element of `McpDefinition.tools`. Per-tool generic typing
283
- * happens at the `defineTool` call site; see README §6 for the rationale.
284
- */
316
+ /** Type-erased element of `McpDefinition.tools`; per-tool generic typing
317
+ * happens at the `defineTool` call site. */
285
318
  interface AnyToolDefinition {
286
319
  readonly name: string;
287
320
  readonly title: string;
@@ -291,13 +324,8 @@ interface AnyToolDefinition {
291
324
  readonly annotations?: ToolAnnotations;
292
325
  readonly handler: (args: any, ctx: ToolContext) => ToolHandlerResult | Promise<ToolHandlerResult>;
293
326
  }
294
- /**
295
- * Fields a caller supplies when constructing an MCP definition. Pass this
296
- * shape to `defineMcp(...)` — its return type is the branded `McpDefinition`,
297
- * which is the type every internal factory (`createInvokeToolHandler`,
298
- * `createMcpProtocolHandler`, …) consumes. The brand forces consumers
299
- * through `defineMcp`'s `assertUniqueNames` + freeze.
300
- */
327
+ /** Input shape for `defineMcp(...)`, whose branded `McpDefinition` return type is what
328
+ * `createMcpProtocolHandler` consumes the brand forces validation + freeze. */
301
329
  interface McpDefinitionInput {
302
330
  readonly name: string;
303
331
  /** Human-readable display name shown to MCP clients. Required. */
@@ -326,4 +354,4 @@ type McpDefinition = McpDefinitionInput & {
326
354
  readonly [McpDefinitionBrand]: never;
327
355
  };
328
356
  //#endregion
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 };
357
+ export { McpAuthConfig as A, MetricsConfig as C, ProgressUpdate as D, McpProtocolEra as E, ToolContext as O, ZodSchema as S, McpClientInfo as T, ToolContent as _, EmbeddedResource as a, ZodOutputSchema as b, JsonValue as c, McpDefinition as d, McpDefinitionInput as f, ToolAnnotations as g, TextContent as h, EmbeddedBlobResource as i, JwtClaims as k, JsonValueInput as l, ResourceLinkIcon as m, ContentAnnotations as n, EmbeddedTextResource as o, ResourceLink as p, ContentBlock as r, ImageContent as s, AudioContent as t, McpAllowedOrigins as u, ToolDefinition as v, MetricsOptions as w, ZodRawShape$1 as x, ToolHandlerResult as y };
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@lovable.dev/mcp-js",
3
- "version": "0.29.0-rc.1",
3
+ "version": "0.29.0-rc.3",
4
+ "engines": {
5
+ "node": ">=20"
6
+ },
4
7
  "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
8
  "type": "module",
6
9
  "repository": {
@@ -49,16 +52,6 @@
49
52
  "default": "./dist/protocols/oauth-metadata.cjs"
50
53
  }
51
54
  },
52
- "./protocols/rest": {
53
- "import": {
54
- "types": "./dist/protocols/rest/index.d.ts",
55
- "default": "./dist/protocols/rest/index.js"
56
- },
57
- "require": {
58
- "types": "./dist/protocols/rest/index.d.cts",
59
- "default": "./dist/protocols/rest/index.cjs"
60
- }
61
- },
62
55
  "./stacks/tanstack": {
63
56
  "import": {
64
57
  "types": "./dist/stacks/tanstack/index.d.ts",
@@ -1,43 +0,0 @@
1
- //#region src/core/forwarded.ts
2
- /**
3
- * Rewrites a request's URL to the public origin a reverse proxy forwards via
4
- * `X-Forwarded-*`, so SDK-derived OAuth `resource`/metadata/`WWW-Authenticate`
5
- * URLs name the host the client actually connected to — not the internal
6
- * backend origin the proxy rewrites `Host` to. Without this, an app on a custom
7
- * domain advertises its internal `*.lovable.dev`/`*.supabase.co` host and every
8
- * MCP call 401s on an audience the client can't satisfy.
9
- *
10
- * Each header is trusted independently, because a forwarded value is only as
11
- * trustworthy as the proxy that sets it:
12
- * - `X-Forwarded-Host` can redirect the advertised resource to an attacker
13
- * origin (the threat `auth/resource.ts` guards against), so it is honored only
14
- * when `trustForwardedHost` is set — enabled on emit paths that sit behind a
15
- * proxy which *overwrites* the header (Lovable's web-proxy does), never by a
16
- * bare SDK consumer.
17
- * - `X-Forwarded-Proto` only selects http/https, so it is gated separately:
18
- * Supabase's gateway stamps it (that stack always trusts it), and Lovable's
19
- * preview proxy overwrites it before the TanStack dev server, so the TanStack
20
- * Vite plugin emits the flag by default.
21
- */
22
- function applyForwardedOrigin(request, options) {
23
- const proto = options.trustForwardedProto ? firstForwardedValue(request, "x-forwarded-proto") : void 0;
24
- const host = options.trustForwardedHost ? firstForwardedValue(request, "x-forwarded-host") : void 0;
25
- if (proto === void 0 && host === void 0) return request;
26
- const url = new URL(request.url);
27
- let changed = false;
28
- if (proto !== void 0 && `${proto}:` !== url.protocol) {
29
- url.protocol = `${proto}:`;
30
- changed = true;
31
- }
32
- if (host !== void 0 && host !== url.host) {
33
- url.host = host;
34
- changed = true;
35
- }
36
- return changed ? new Request(url.href, request) : request;
37
- }
38
- function firstForwardedValue(request, header) {
39
- const value = request.headers.get(header)?.split(",")[0]?.trim();
40
- return value ? value : void 0;
41
- }
42
- //#endregion
43
- export { applyForwardedOrigin as t };
@@ -1,48 +0,0 @@
1
- //#region src/core/forwarded.ts
2
- /**
3
- * Rewrites a request's URL to the public origin a reverse proxy forwards via
4
- * `X-Forwarded-*`, so SDK-derived OAuth `resource`/metadata/`WWW-Authenticate`
5
- * URLs name the host the client actually connected to — not the internal
6
- * backend origin the proxy rewrites `Host` to. Without this, an app on a custom
7
- * domain advertises its internal `*.lovable.dev`/`*.supabase.co` host and every
8
- * MCP call 401s on an audience the client can't satisfy.
9
- *
10
- * Each header is trusted independently, because a forwarded value is only as
11
- * trustworthy as the proxy that sets it:
12
- * - `X-Forwarded-Host` can redirect the advertised resource to an attacker
13
- * origin (the threat `auth/resource.ts` guards against), so it is honored only
14
- * when `trustForwardedHost` is set — enabled on emit paths that sit behind a
15
- * proxy which *overwrites* the header (Lovable's web-proxy does), never by a
16
- * bare SDK consumer.
17
- * - `X-Forwarded-Proto` only selects http/https, so it is gated separately:
18
- * Supabase's gateway stamps it (that stack always trusts it), and Lovable's
19
- * preview proxy overwrites it before the TanStack dev server, so the TanStack
20
- * Vite plugin emits the flag by default.
21
- */
22
- function applyForwardedOrigin(request, options) {
23
- const proto = options.trustForwardedProto ? firstForwardedValue(request, "x-forwarded-proto") : void 0;
24
- const host = options.trustForwardedHost ? firstForwardedValue(request, "x-forwarded-host") : void 0;
25
- if (proto === void 0 && host === void 0) return request;
26
- const url = new URL(request.url);
27
- let changed = false;
28
- if (proto !== void 0 && `${proto}:` !== url.protocol) {
29
- url.protocol = `${proto}:`;
30
- changed = true;
31
- }
32
- if (host !== void 0 && host !== url.host) {
33
- url.host = host;
34
- changed = true;
35
- }
36
- return changed ? new Request(url.href, request) : request;
37
- }
38
- function firstForwardedValue(request, header) {
39
- const value = request.headers.get(header)?.split(",")[0]?.trim();
40
- return value ? value : void 0;
41
- }
42
- //#endregion
43
- Object.defineProperty(exports, "applyForwardedOrigin", {
44
- enumerable: true,
45
- get: function() {
46
- return applyForwardedOrigin;
47
- }
48
- });
@@ -1,26 +0,0 @@
1
- const require_cors = require("./cors-BRv5KXKQ.cjs");
2
- //#region src/protocols/gate.ts
3
- function createGatedHandler(gate) {
4
- const allow = [...gate.methods, "OPTIONS"].join(", ");
5
- const respond = async (request, recorder, ...extra) => {
6
- const authResult = await gate.authorizer.authorize(request, recorder);
7
- if (!authResult.ok) return authResult.response;
8
- if (!gate.methods.includes(request.method)) return gate.methodNotAllowed(allow);
9
- return gate.handle(request, authResult, recorder, ...extra);
10
- };
11
- return async (request, recorder = require_cors.createNoopRecorder(), ...extra) => {
12
- const cors = require_cors.evaluateCors(request, gate.allowedOrigins);
13
- if (!cors.ok) return require_cors.finalizeWireResponse(request, cors.response);
14
- if (request.method === "OPTIONS") return cors.preflight(allow);
15
- const final = require_cors.finalizeWireResponse(request, cors.withHeaders(await respond(request, recorder, ...extra)));
16
- if (!final.headers.has("Cache-Control")) final.headers.set("Cache-Control", "no-store");
17
- return final;
18
- };
19
- }
20
- //#endregion
21
- Object.defineProperty(exports, "createGatedHandler", {
22
- enumerable: true,
23
- get: function() {
24
- return createGatedHandler;
25
- }
26
- });
@@ -1,21 +0,0 @@
1
- import { f as finalizeWireResponse, l as createNoopRecorder, t as evaluateCors } from "./cors-BDTQQJE2.js";
2
- //#region src/protocols/gate.ts
3
- function createGatedHandler(gate) {
4
- const allow = [...gate.methods, "OPTIONS"].join(", ");
5
- const respond = async (request, recorder, ...extra) => {
6
- const authResult = await gate.authorizer.authorize(request, recorder);
7
- if (!authResult.ok) return authResult.response;
8
- if (!gate.methods.includes(request.method)) return gate.methodNotAllowed(allow);
9
- return gate.handle(request, authResult, recorder, ...extra);
10
- };
11
- return async (request, recorder = createNoopRecorder(), ...extra) => {
12
- const cors = evaluateCors(request, gate.allowedOrigins);
13
- if (!cors.ok) return finalizeWireResponse(request, cors.response);
14
- if (request.method === "OPTIONS") return cors.preflight(allow);
15
- const final = finalizeWireResponse(request, cors.withHeaders(await respond(request, recorder, ...extra)));
16
- if (!final.headers.has("Cache-Control")) final.headers.set("Cache-Control", "no-store");
17
- return final;
18
- };
19
- }
20
- //#endregion
21
- export { createGatedHandler as t };
@@ -1,37 +0,0 @@
1
- import { t as jsonSchemaFromDefinition } from "./schema-CW1jKvio.js";
2
- import { n as assertRestResourceBinding, p as methodNotAllowed, r as createRequestAuthorizer } from "./cors-BDTQQJE2.js";
3
- import { t as createGatedHandler } from "./gate-uCVrbDBb.js";
4
- //#region src/protocols/rest/list-tools.ts
5
- function schemaToJsonSchema(definition, pipeStrategy) {
6
- if (!definition) return null;
7
- return jsonSchemaFromDefinition(definition, pipeStrategy);
8
- }
9
- function buildMcpListing(mcp) {
10
- return {
11
- server: {
12
- name: mcp.name,
13
- version: mcp.version,
14
- title: mcp.title
15
- },
16
- tools: mcp.tools.map((tool) => ({
17
- name: tool.name,
18
- title: tool.title,
19
- description: tool.description,
20
- annotations: tool.annotations,
21
- inputSchema: schemaToJsonSchema(tool.inputSchema, "input"),
22
- outputSchema: schemaToJsonSchema(tool.outputSchema, "output")
23
- }))
24
- };
25
- }
26
- function createListToolsHandler(mcp, options = {}) {
27
- assertRestResourceBinding(mcp, options);
28
- return createGatedHandler({
29
- authorizer: createRequestAuthorizer(mcp, options),
30
- allowedOrigins: mcp.allowedOrigins,
31
- methods: ["GET", "HEAD"],
32
- methodNotAllowed,
33
- handle: async () => Response.json(buildMcpListing(mcp))
34
- });
35
- }
36
- //#endregion
37
- export { createListToolsHandler as n, buildMcpListing as t };
@@ -1,8 +0,0 @@
1
- import { u as McpDefinition } from "./types-D1cgsnPu.cjs";
2
- import { t as MetricsRecorder } from "./base-C8osWdMU.cjs";
3
- import { t as McpRuntimeOptions } from "./authorize-BzZFS0zi.cjs";
4
- //#region src/protocols/rest/list-tools.d.ts
5
- type RestListToolsHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
6
- declare function createListToolsHandler(mcp: McpDefinition, options?: McpRuntimeOptions): RestListToolsHandler;
7
- //#endregion
8
- export { createListToolsHandler as n, RestListToolsHandler as t };
@@ -1,48 +0,0 @@
1
- const require_schema = require("./schema-D3vClxb7.cjs");
2
- const require_cors = require("./cors-BRv5KXKQ.cjs");
3
- const require_gate = require("./gate-CAJSRt_t.cjs");
4
- //#region src/protocols/rest/list-tools.ts
5
- function schemaToJsonSchema(definition, pipeStrategy) {
6
- if (!definition) return null;
7
- return require_schema.jsonSchemaFromDefinition(definition, pipeStrategy);
8
- }
9
- function buildMcpListing(mcp) {
10
- return {
11
- server: {
12
- name: mcp.name,
13
- version: mcp.version,
14
- title: mcp.title
15
- },
16
- tools: mcp.tools.map((tool) => ({
17
- name: tool.name,
18
- title: tool.title,
19
- description: tool.description,
20
- annotations: tool.annotations,
21
- inputSchema: schemaToJsonSchema(tool.inputSchema, "input"),
22
- outputSchema: schemaToJsonSchema(tool.outputSchema, "output")
23
- }))
24
- };
25
- }
26
- function createListToolsHandler(mcp, options = {}) {
27
- require_cors.assertRestResourceBinding(mcp, options);
28
- return require_gate.createGatedHandler({
29
- authorizer: require_cors.createRequestAuthorizer(mcp, options),
30
- allowedOrigins: mcp.allowedOrigins,
31
- methods: ["GET", "HEAD"],
32
- methodNotAllowed: require_cors.methodNotAllowed,
33
- handle: async () => Response.json(buildMcpListing(mcp))
34
- });
35
- }
36
- //#endregion
37
- Object.defineProperty(exports, "buildMcpListing", {
38
- enumerable: true,
39
- get: function() {
40
- return buildMcpListing;
41
- }
42
- });
43
- Object.defineProperty(exports, "createListToolsHandler", {
44
- enumerable: true,
45
- get: function() {
46
- return createListToolsHandler;
47
- }
48
- });
@@ -1,8 +0,0 @@
1
- import { u as McpDefinition } from "./types-D1cgsnPu.js";
2
- import { t as MetricsRecorder } from "./base-C8osWdMU.js";
3
- import { t as McpRuntimeOptions } from "./authorize-BjNE3LPr.js";
4
- //#region src/protocols/rest/list-tools.d.ts
5
- type RestListToolsHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
6
- declare function createListToolsHandler(mcp: McpDefinition, options?: McpRuntimeOptions): RestListToolsHandler;
7
- //#endregion
8
- export { createListToolsHandler as n, RestListToolsHandler as t };