@lovable.dev/mcp-js 0.26.2 → 0.27.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 (55) hide show
  1. package/dist/{authorize-D3zzoTAG.d.cts → authorize-BcNuNPtP.d.cts} +15 -3
  2. package/dist/{authorize-Y6Jm8GhR.d.ts → authorize-Cs1yyLrq.d.ts} +15 -3
  3. package/dist/{cors-DPRJFY-U.cjs → authorize-FZydvyMU.cjs} +36 -35
  4. package/dist/{cors-DnU41czH.js → authorize-KzrdWb2-.js} +33 -26
  5. package/dist/cli/extract-manifest.cjs +2 -2
  6. package/dist/cli/extract-manifest.js +2 -2
  7. package/dist/{forwarded-Pi8Hs5Ps.cjs → forwarded-Bhwcj22u.cjs} +2 -2
  8. package/dist/{forwarded--h4efJy-.js → forwarded-BlLF3dfc.js} +2 -2
  9. package/dist/gate-Blmxv8t2.cjs +24 -0
  10. package/dist/gate-Cclvf6xn.js +19 -0
  11. package/dist/index.cjs +1 -1
  12. package/dist/index.d.cts +2 -1
  13. package/dist/index.d.ts +2 -1
  14. package/dist/index.js +1 -1
  15. package/dist/{io-B-fV6rsM.d.ts → io--MeYrWG7.d.ts} +1 -1
  16. package/dist/{io-Bd58IeVb.d.cts → io-BzTGjG_c.d.cts} +1 -1
  17. package/dist/{list-tools-C6u8G4iq.d.ts → list-tools-Bku6XkVc.d.ts} +1 -1
  18. package/dist/{list-tools-DCs034XG.js → list-tools-CCGzOMpC.js} +8 -13
  19. package/dist/{list-tools-DOBMd4AE.d.cts → list-tools-Cn7tpE0V.d.cts} +1 -1
  20. package/dist/{list-tools-ka32VIXt.cjs → list-tools-DDhzQZRL.cjs} +9 -14
  21. package/dist/{logger-BSKbuM66.cjs → logger-BkMMCFTv.cjs} +3 -0
  22. package/dist/{logger-3-kwsF-5.js → logger-rGakBvJ1.js} +3 -0
  23. package/dist/{mcp-C9fh9I8u.cjs → mcp-BLYbUCO5.cjs} +17 -18
  24. package/dist/{mcp-DlcYgsv9.js → mcp-Di8hVnwC.js} +12 -13
  25. package/dist/{package-CBvVzH3w.cjs → package-9XZJumh0.cjs} +1 -1
  26. package/dist/{package-Bbg8XwRW.js → package-BmhaKMyb.js} +1 -1
  27. package/dist/protocols/mcp/index.cjs +1 -1
  28. package/dist/protocols/mcp/index.d.cts +1 -1
  29. package/dist/protocols/mcp/index.d.ts +1 -1
  30. package/dist/protocols/mcp/index.js +1 -1
  31. package/dist/protocols/oauth-metadata.cjs +25 -17
  32. package/dist/protocols/oauth-metadata.d.cts +1 -1
  33. package/dist/protocols/oauth-metadata.d.ts +1 -1
  34. package/dist/protocols/oauth-metadata.js +21 -13
  35. package/dist/protocols/rest/index.cjs +2 -2
  36. package/dist/protocols/rest/index.d.cts +2 -2
  37. package/dist/protocols/rest/index.d.ts +2 -2
  38. package/dist/protocols/rest/index.js +2 -2
  39. package/dist/{rest-Di-HJGi6.js → rest-DUQqIlzT.js} +11 -11
  40. package/dist/{rest-BpFG5VRY.cjs → rest-Hr1H57re.cjs} +23 -23
  41. package/dist/stacks/supabase/index.cjs +16 -15
  42. package/dist/stacks/supabase/index.js +14 -13
  43. package/dist/stacks/supabase/vite.cjs +1 -1
  44. package/dist/stacks/supabase/vite.d.cts +1 -1
  45. package/dist/stacks/supabase/vite.d.ts +1 -1
  46. package/dist/stacks/supabase/vite.js +1 -1
  47. package/dist/stacks/tanstack/index.cjs +9 -12
  48. package/dist/stacks/tanstack/index.d.cts +1 -1
  49. package/dist/stacks/tanstack/index.d.ts +1 -1
  50. package/dist/stacks/tanstack/index.js +9 -12
  51. package/dist/stacks/tanstack/vite.cjs +6 -2
  52. package/dist/stacks/tanstack/vite.d.cts +1 -1
  53. package/dist/stacks/tanstack/vite.d.ts +1 -1
  54. package/dist/stacks/tanstack/vite.js +6 -2
  55. package/package.json +1 -1
@@ -17,11 +17,23 @@ interface McpRuntimeOptions {
17
17
  metadataPath?: string;
18
18
  /**
19
19
  * Derive the request origin (and thus the advertised `resource`/metadata URLs)
20
- * from `X-Forwarded-Host` rather than the rewritten `Host`. Stack adapters read
21
- * this before invoking the handler, so the OAuth runtime never sees it; safe
22
- * only behind a proxy that overwrites the header (see `core/forwarded.ts`).
20
+ * from `X-Forwarded-Host` rather than the rewritten `Host`. Stack adapters
21
+ * apply the URL rewrite before invoking the handler (see `core/forwarded.ts`);
22
+ * the metadata handler reads the flag only to extend `Vary`.
23
23
  */
24
24
  trustForwardedHost?: boolean;
25
+ /**
26
+ * Same as `trustForwardedHost` for `X-Forwarded-Proto`; the Supabase adapter
27
+ * always sets it because the gateway stamps that header.
28
+ */
29
+ trustForwardedProto?: boolean;
30
+ /**
31
+ * @internal Attests that a proxy the deployer controls overwrites
32
+ * `X-Forwarded-Host`; set by the TanStack Vite plugin's emitted metadata
33
+ * route. Setting it yourself takes responsibility for that proxy — it
34
+ * silences the unpinned-resource warning, nothing else.
35
+ */
36
+ forwardedHostTrustedByPlatform?: boolean;
25
37
  }
26
38
  //#endregion
27
39
  export { McpRuntimeOptions as t };
@@ -17,11 +17,23 @@ interface McpRuntimeOptions {
17
17
  metadataPath?: string;
18
18
  /**
19
19
  * Derive the request origin (and thus the advertised `resource`/metadata URLs)
20
- * from `X-Forwarded-Host` rather than the rewritten `Host`. Stack adapters read
21
- * this before invoking the handler, so the OAuth runtime never sees it; safe
22
- * only behind a proxy that overwrites the header (see `core/forwarded.ts`).
20
+ * from `X-Forwarded-Host` rather than the rewritten `Host`. Stack adapters
21
+ * apply the URL rewrite before invoking the handler (see `core/forwarded.ts`);
22
+ * the metadata handler reads the flag only to extend `Vary`.
23
23
  */
24
24
  trustForwardedHost?: boolean;
25
+ /**
26
+ * Same as `trustForwardedHost` for `X-Forwarded-Proto`; the Supabase adapter
27
+ * always sets it because the gateway stamps that header.
28
+ */
29
+ trustForwardedProto?: boolean;
30
+ /**
31
+ * @internal Attests that a proxy the deployer controls overwrites
32
+ * `X-Forwarded-Host`; set by the TanStack Vite plugin's emitted metadata
33
+ * route. Setting it yourself takes responsibility for that proxy — it
34
+ * silences the unpinned-resource warning, nothing else.
35
+ */
36
+ forwardedHostTrustedByPlatform?: boolean;
25
37
  }
26
38
  //#endregion
27
39
  export { McpRuntimeOptions as t };
@@ -1,7 +1,28 @@
1
- const require_logger = require("./logger-BSKbuM66.cjs");
2
- const require_package = require("./package-CBvVzH3w.cjs");
1
+ const require_logger = require("./logger-BkMMCFTv.cjs");
2
+ const require_package = require("./package-9XZJumh0.cjs");
3
3
  require("./metadata-path-zd7NSNoa.cjs");
4
4
  let jose = require("jose");
5
+ //#region src/core/cors.ts
6
+ const EXPOSE_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
7
+ const ALLOW_HEADERS = "Authorization, Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID";
8
+ /** Add permissive CORS to a built response, preserving its other headers. */
9
+ function withCors(response) {
10
+ response.headers.set("Access-Control-Allow-Origin", "*");
11
+ response.headers.set("Access-Control-Expose-Headers", EXPOSE_HEADERS);
12
+ return response;
13
+ }
14
+ function corsPreflightResponse(allowMethods) {
15
+ return new Response(null, {
16
+ status: 204,
17
+ headers: {
18
+ "Access-Control-Allow-Origin": "*",
19
+ "Access-Control-Allow-Methods": allowMethods,
20
+ "Access-Control-Allow-Headers": ALLOW_HEADERS,
21
+ "Access-Control-Max-Age": "86400"
22
+ }
23
+ });
24
+ }
25
+ //#endregion
5
26
  //#region src/core/http.ts
6
27
  const JSON_HEADERS = { "Content-Type": "application/json" };
7
28
  /** Strip the body from a built response, preserving status and headers, for HEAD. */
@@ -12,12 +33,16 @@ function headResponse(response) {
12
33
  headers: response.headers
13
34
  });
14
35
  }
36
+ function finalizeWireResponse(request, response) {
37
+ return withCors(request.method === "HEAD" ? headResponse(response) : response);
38
+ }
15
39
  function methodNotAllowed(allow) {
16
40
  return new Response(JSON.stringify({ error: "method not allowed" }), {
17
41
  status: 405,
18
42
  headers: {
19
43
  ...JSON_HEADERS,
20
- Allow: allow
44
+ Allow: allow,
45
+ "Cache-Control": "no-store"
21
46
  }
22
47
  });
23
48
  }
@@ -766,7 +791,10 @@ function getOAuthRuntime(mcp, options = {}) {
766
791
  if (options.metadataPath !== void 0) assertResourcePathShape(options.metadataPath, "metadataPath");
767
792
  const stableOptions = {
768
793
  resourcePath: options.resourcePath,
769
- metadataPath: options.metadataPath
794
+ metadataPath: options.metadataPath,
795
+ trustForwardedHost: options.trustForwardedHost,
796
+ trustForwardedProto: options.trustForwardedProto,
797
+ forwardedHostTrustedByPlatform: options.forwardedHostTrustedByPlatform
770
798
  };
771
799
  const auth = mcp.auth?.type === "oauth" ? mcp.auth : void 0;
772
800
  if (!auth) return {
@@ -880,27 +908,6 @@ function createRequestAuthorizer(mcp, options = {}) {
880
908
  } };
881
909
  }
882
910
  //#endregion
883
- //#region src/core/cors.ts
884
- const EXPOSE_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
885
- const ALLOW_HEADERS = "Authorization, Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID";
886
- /** Add permissive CORS to a built response, preserving its other headers. */
887
- function withCors(response) {
888
- response.headers.set("Access-Control-Allow-Origin", "*");
889
- response.headers.set("Access-Control-Expose-Headers", EXPOSE_HEADERS);
890
- return response;
891
- }
892
- function corsPreflightResponse(allowMethods) {
893
- return new Response(null, {
894
- status: 204,
895
- headers: {
896
- "Access-Control-Allow-Origin": "*",
897
- "Access-Control-Allow-Methods": allowMethods,
898
- "Access-Control-Allow-Headers": ALLOW_HEADERS,
899
- "Access-Control-Max-Age": "86400"
900
- }
901
- });
902
- }
903
- //#endregion
904
911
  Object.defineProperty(exports, "JSON_HEADERS", {
905
912
  enumerable: true,
906
913
  get: function() {
@@ -943,16 +950,16 @@ Object.defineProperty(exports, "createRequestAuthorizer", {
943
950
  return createRequestAuthorizer;
944
951
  }
945
952
  });
946
- Object.defineProperty(exports, "getOAuthRuntime", {
953
+ Object.defineProperty(exports, "finalizeWireResponse", {
947
954
  enumerable: true,
948
955
  get: function() {
949
- return getOAuthRuntime;
956
+ return finalizeWireResponse;
950
957
  }
951
958
  });
952
- Object.defineProperty(exports, "headResponse", {
959
+ Object.defineProperty(exports, "getOAuthRuntime", {
953
960
  enumerable: true,
954
961
  get: function() {
955
- return headResponse;
962
+ return getOAuthRuntime;
956
963
  }
957
964
  });
958
965
  Object.defineProperty(exports, "methodNotAllowed", {
@@ -979,9 +986,3 @@ Object.defineProperty(exports, "resolveProtectedResource", {
979
986
  return resolveProtectedResource;
980
987
  }
981
988
  });
982
- Object.defineProperty(exports, "withCors", {
983
- enumerable: true,
984
- get: function() {
985
- return withCors;
986
- }
987
- });
@@ -1,7 +1,28 @@
1
- import { i as log, n as applyLogLevelFromEnv, o as parseSafeUrl, r as describeError, s as trimTrailingSlash, t as LOG_LEVEL_ENV_VAR, u as resolveMetricsConfig } from "./logger-3-kwsF-5.js";
2
- import { t as version } from "./package-Bbg8XwRW.js";
1
+ import { i as log, n as applyLogLevelFromEnv, o as parseSafeUrl, r as describeError, s as trimTrailingSlash, t as LOG_LEVEL_ENV_VAR, u as resolveMetricsConfig } from "./logger-rGakBvJ1.js";
2
+ import { t as version } from "./package-BmhaKMyb.js";
3
3
  import "./metadata-path-CAkNcfyY.js";
4
4
  import { createLocalJWKSet, decodeProtectedHeader, jwtVerify } from "jose";
5
+ //#region src/core/cors.ts
6
+ const EXPOSE_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
7
+ const ALLOW_HEADERS = "Authorization, Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID";
8
+ /** Add permissive CORS to a built response, preserving its other headers. */
9
+ function withCors(response) {
10
+ response.headers.set("Access-Control-Allow-Origin", "*");
11
+ response.headers.set("Access-Control-Expose-Headers", EXPOSE_HEADERS);
12
+ return response;
13
+ }
14
+ function corsPreflightResponse(allowMethods) {
15
+ return new Response(null, {
16
+ status: 204,
17
+ headers: {
18
+ "Access-Control-Allow-Origin": "*",
19
+ "Access-Control-Allow-Methods": allowMethods,
20
+ "Access-Control-Allow-Headers": ALLOW_HEADERS,
21
+ "Access-Control-Max-Age": "86400"
22
+ }
23
+ });
24
+ }
25
+ //#endregion
5
26
  //#region src/core/http.ts
6
27
  const JSON_HEADERS = { "Content-Type": "application/json" };
7
28
  /** Strip the body from a built response, preserving status and headers, for HEAD. */
@@ -12,12 +33,16 @@ function headResponse(response) {
12
33
  headers: response.headers
13
34
  });
14
35
  }
36
+ function finalizeWireResponse(request, response) {
37
+ return withCors(request.method === "HEAD" ? headResponse(response) : response);
38
+ }
15
39
  function methodNotAllowed(allow) {
16
40
  return new Response(JSON.stringify({ error: "method not allowed" }), {
17
41
  status: 405,
18
42
  headers: {
19
43
  ...JSON_HEADERS,
20
- Allow: allow
44
+ Allow: allow,
45
+ "Cache-Control": "no-store"
21
46
  }
22
47
  });
23
48
  }
@@ -766,7 +791,10 @@ function getOAuthRuntime(mcp, options = {}) {
766
791
  if (options.metadataPath !== void 0) assertResourcePathShape(options.metadataPath, "metadataPath");
767
792
  const stableOptions = {
768
793
  resourcePath: options.resourcePath,
769
- metadataPath: options.metadataPath
794
+ metadataPath: options.metadataPath,
795
+ trustForwardedHost: options.trustForwardedHost,
796
+ trustForwardedProto: options.trustForwardedProto,
797
+ forwardedHostTrustedByPlatform: options.forwardedHostTrustedByPlatform
770
798
  };
771
799
  const auth = mcp.auth?.type === "oauth" ? mcp.auth : void 0;
772
800
  if (!auth) return {
@@ -880,25 +908,4 @@ function createRequestAuthorizer(mcp, options = {}) {
880
908
  } };
881
909
  }
882
910
  //#endregion
883
- //#region src/core/cors.ts
884
- const EXPOSE_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
885
- const ALLOW_HEADERS = "Authorization, Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID";
886
- /** Add permissive CORS to a built response, preserving its other headers. */
887
- function withCors(response) {
888
- response.headers.set("Access-Control-Allow-Origin", "*");
889
- response.headers.set("Access-Control-Expose-Headers", EXPOSE_HEADERS);
890
- return response;
891
- }
892
- function corsPreflightResponse(allowMethods) {
893
- return new Response(null, {
894
- status: 204,
895
- headers: {
896
- "Access-Control-Allow-Origin": "*",
897
- "Access-Control-Allow-Methods": allowMethods,
898
- "Access-Control-Allow-Headers": ALLOW_HEADERS,
899
- "Access-Control-Max-Age": "86400"
900
- }
901
- });
902
- }
903
- //#endregion
904
- export { getOAuthRuntime as a, resolveProtectedResource as c, nowMs as d, JSON_HEADERS as f, createRequestAuthorizer as i, createRecorderForRuntime as l, methodNotAllowed as m, withCors as n, oauthConfigurationErrorResponse as o, headResponse as p, assertRestResourceBinding as r, assertResourcePathShape as s, corsPreflightResponse as t, createNoopRecorder as u };
911
+ export { assertResourcePathShape as a, createNoopRecorder as c, finalizeWireResponse as d, methodNotAllowed as f, oauthConfigurationErrorResponse as i, nowMs as l, createRequestAuthorizer as n, resolveProtectedResource as o, corsPreflightResponse as p, getOAuthRuntime as r, createRecorderForRuntime as s, assertRestResourceBinding as t, JSON_HEADERS as u };
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- const require_package = require("../package-CBvVzH3w.cjs");
3
- const require_list_tools = require("../list-tools-ka32VIXt.cjs");
2
+ const require_package = require("../package-9XZJumh0.cjs");
3
+ const require_list_tools = require("../list-tools-DDhzQZRL.cjs");
4
4
  const require_fs_errors = require("../fs-errors-CWNzOV75.cjs");
5
5
  let node_fs = require("node:fs");
6
6
  let node_path = require("node:path");
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { t as version } from "../package-Bbg8XwRW.js";
3
- import { t as buildMcpListing } from "../list-tools-DCs034XG.js";
2
+ import { t as version } from "../package-BmhaKMyb.js";
3
+ import { t as buildMcpListing } from "../list-tools-CCGzOMpC.js";
4
4
  import { t as isFileMissing } from "../fs-errors-PA2t1TIp.js";
5
5
  import { lstatSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
6
6
  import { dirname, resolve } from "node:path";
@@ -16,8 +16,8 @@
16
16
  * bare SDK consumer.
17
17
  * - `X-Forwarded-Proto` only selects http/https, so it is gated separately:
18
18
  * Supabase terminates TLS upstream and forwards over http with a
19
- * gateway-stamped proto, so that stack trusts it; the TanStack proxy does not
20
- * sanitize proto, so that stack leaves it alone.
19
+ * gateway-stamped proto, so that stack always trusts it; the TanStack proxy
20
+ * does not sanitize proto, so its Vite plugin never emits the flag.
21
21
  */
22
22
  function applyForwardedOrigin(request, options) {
23
23
  const proto = options.trustForwardedProto ? firstForwardedValue(request, "x-forwarded-proto") : void 0;
@@ -16,8 +16,8 @@
16
16
  * bare SDK consumer.
17
17
  * - `X-Forwarded-Proto` only selects http/https, so it is gated separately:
18
18
  * Supabase terminates TLS upstream and forwards over http with a
19
- * gateway-stamped proto, so that stack trusts it; the TanStack proxy does not
20
- * sanitize proto, so that stack leaves it alone.
19
+ * gateway-stamped proto, so that stack always trusts it; the TanStack proxy
20
+ * does not sanitize proto, so its Vite plugin never emits the flag.
21
21
  */
22
22
  function applyForwardedOrigin(request, options) {
23
23
  const proto = options.trustForwardedProto ? firstForwardedValue(request, "x-forwarded-proto") : void 0;
@@ -0,0 +1,24 @@
1
+ const require_authorize = require("./authorize-FZydvyMU.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_authorize.createNoopRecorder(), ...extra) => {
12
+ if (request.method === "OPTIONS") return require_authorize.corsPreflightResponse(allow);
13
+ const final = require_authorize.finalizeWireResponse(request, await respond(request, recorder, ...extra));
14
+ if (!final.headers.has("Cache-Control")) final.headers.set("Cache-Control", "no-store");
15
+ return final;
16
+ };
17
+ }
18
+ //#endregion
19
+ Object.defineProperty(exports, "createGatedHandler", {
20
+ enumerable: true,
21
+ get: function() {
22
+ return createGatedHandler;
23
+ }
24
+ });
@@ -0,0 +1,19 @@
1
+ import { c as createNoopRecorder, d as finalizeWireResponse, p as corsPreflightResponse } from "./authorize-KzrdWb2-.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
+ if (request.method === "OPTIONS") return corsPreflightResponse(allow);
13
+ const final = finalizeWireResponse(request, await respond(request, recorder, ...extra));
14
+ if (!final.headers.has("Cache-Control")) final.headers.set("Cache-Control", "no-store");
15
+ return final;
16
+ };
17
+ }
18
+ //#endregion
19
+ export { createGatedHandler as t };
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_logger = require("./logger-BSKbuM66.cjs");
2
+ const require_logger = require("./logger-BkMMCFTv.cjs");
3
3
  const require_errors = require("./errors-CN6Da8iz.cjs");
4
4
  //#region src/core/define.ts
5
5
  function assertUniqueNames(mcp) {
package/dist/index.d.cts CHANGED
@@ -67,7 +67,8 @@ type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
67
67
  * Set the runtime log level programmatically. Use this when the deployment can't
68
68
  * surface `LOVABLE_MCP_LOG_LEVEL` to the package (e.g. a Cloudflare Worker that
69
69
  * passes vars via bindings): call `setLogLevel("debug")` once at server startup.
70
+ * @returns the previous level, so a scoped override can restore it.
70
71
  */
71
- declare function setLogLevel(level: LogLevel): void;
72
+ declare function setLogLevel(level: LogLevel): LogLevel;
72
73
  //#endregion
73
74
  export { type AudioContent, type ContentAnnotations, type ContentBlock, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JwtClaims, type LogLevel, type McpDefinitionInput, type MetricsConfig, type MetricsOptions, type ResourceLink, type ResourceLinkIcon, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ZodRawShape, type ZodSchema, auth, defineMcp, defineTool, setLogLevel };
package/dist/index.d.ts CHANGED
@@ -67,7 +67,8 @@ type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
67
67
  * Set the runtime log level programmatically. Use this when the deployment can't
68
68
  * surface `LOVABLE_MCP_LOG_LEVEL` to the package (e.g. a Cloudflare Worker that
69
69
  * passes vars via bindings): call `setLogLevel("debug")` once at server startup.
70
+ * @returns the previous level, so a scoped override can restore it.
70
71
  */
71
- declare function setLogLevel(level: LogLevel): void;
72
+ declare function setLogLevel(level: LogLevel): LogLevel;
72
73
  //#endregion
73
74
  export { type AudioContent, type ContentAnnotations, type ContentBlock, type EmbeddedBlobResource, type EmbeddedResource, type EmbeddedTextResource, type ImageContent, type IssuerOAuthOptions, type JwtClaims, type LogLevel, type McpDefinitionInput, type MetricsConfig, type MetricsOptions, type ResourceLink, type ResourceLinkIcon, type TextContent, type ToolAnnotations, type ToolContent, ToolContext, type ToolDefinition, ToolError, type ToolHandlerResult, type ZodRawShape, type ZodSchema, auth, defineMcp, defineTool, setLogLevel };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as setLogLevel, o as parseSafeUrl, s as trimTrailingSlash, u as resolveMetricsConfig } from "./logger-3-kwsF-5.js";
1
+ import { a as setLogLevel, o as parseSafeUrl, s as trimTrailingSlash, u as resolveMetricsConfig } from "./logger-rGakBvJ1.js";
2
2
  import { i as ToolContext, t as ToolError } from "./errors-DSe96Ffd.js";
3
3
  //#region src/core/define.ts
4
4
  function assertUniqueNames(mcp) {
@@ -1,4 +1,4 @@
1
- import "./list-tools-C6u8G4iq.js";
1
+ import "./list-tools-Bku6XkVc.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,4 +1,4 @@
1
- import "./list-tools-DOBMd4AE.cjs";
1
+ import "./list-tools-Cn7tpE0V.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,6 +1,6 @@
1
1
  import { c as McpDefinition } from "./types-C0Wgm9zp.js";
2
2
  import { t as MetricsRecorder } from "./base-CReh7d3E.js";
3
- import { t as McpRuntimeOptions } from "./authorize-Y6Jm8GhR.js";
3
+ import { t as McpRuntimeOptions } from "./authorize-Cs1yyLrq.js";
4
4
  //#region src/protocols/rest/list-tools.d.ts
5
5
  type RestListToolsHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
6
6
  declare function createListToolsHandler(mcp: McpDefinition, options?: McpRuntimeOptions): RestListToolsHandler;
@@ -1,4 +1,5 @@
1
- import { i as createRequestAuthorizer, m as methodNotAllowed, n as withCors, p as headResponse, r as assertRestResourceBinding, t as corsPreflightResponse, u as createNoopRecorder } from "./cors-DnU41czH.js";
1
+ import { f as methodNotAllowed, n as createRequestAuthorizer, t as assertRestResourceBinding } from "./authorize-KzrdWb2-.js";
2
+ import { t as createGatedHandler } from "./gate-Cclvf6xn.js";
2
3
  import { objectFromShape } from "@modelcontextprotocol/sdk/server/zod-compat.js";
3
4
  import { toJsonSchemaCompat } from "@modelcontextprotocol/sdk/server/zod-json-schema-compat.js";
4
5
  //#region src/protocols/rest/list-tools.ts
@@ -29,18 +30,12 @@ function buildMcpListing(mcp) {
29
30
  }
30
31
  function createListToolsHandler(mcp, options = {}) {
31
32
  assertRestResourceBinding(mcp, options);
32
- const authorizer = createRequestAuthorizer(mcp, options);
33
- const handle = async (request, recorder) => {
34
- const authResult = await authorizer.authorize(request, recorder);
35
- if (!authResult.ok) return authResult.response;
36
- if (request.method !== "GET" && request.method !== "HEAD") return methodNotAllowed("GET, HEAD, OPTIONS");
37
- const response = Response.json(buildMcpListing(mcp));
38
- return request.method === "HEAD" ? headResponse(response) : response;
39
- };
40
- return async (request, recorder = createNoopRecorder()) => {
41
- if (request.method === "OPTIONS") return corsPreflightResponse("GET, HEAD, OPTIONS");
42
- return withCors(await handle(request, recorder));
43
- };
33
+ return createGatedHandler({
34
+ authorizer: createRequestAuthorizer(mcp, options),
35
+ methods: ["GET", "HEAD"],
36
+ methodNotAllowed,
37
+ handle: async () => Response.json(buildMcpListing(mcp))
38
+ });
44
39
  }
45
40
  //#endregion
46
41
  export { createListToolsHandler as n, buildMcpListing as t };
@@ -1,6 +1,6 @@
1
1
  import { c as McpDefinition } from "./types-C0Wgm9zp.cjs";
2
2
  import { t as MetricsRecorder } from "./base-CReh7d3E.cjs";
3
- import { t as McpRuntimeOptions } from "./authorize-D3zzoTAG.cjs";
3
+ import { t as McpRuntimeOptions } from "./authorize-BcNuNPtP.cjs";
4
4
  //#region src/protocols/rest/list-tools.d.ts
5
5
  type RestListToolsHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
6
6
  declare function createListToolsHandler(mcp: McpDefinition, options?: McpRuntimeOptions): RestListToolsHandler;
@@ -1,4 +1,5 @@
1
- const require_cors = require("./cors-DPRJFY-U.cjs");
1
+ const require_authorize = require("./authorize-FZydvyMU.cjs");
2
+ const require_gate = require("./gate-Blmxv8t2.cjs");
2
3
  let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
3
4
  let _modelcontextprotocol_sdk_server_zod_json_schema_compat_js = require("@modelcontextprotocol/sdk/server/zod-json-schema-compat.js");
4
5
  //#region src/protocols/rest/list-tools.ts
@@ -28,19 +29,13 @@ function buildMcpListing(mcp) {
28
29
  };
29
30
  }
30
31
  function createListToolsHandler(mcp, options = {}) {
31
- require_cors.assertRestResourceBinding(mcp, options);
32
- const authorizer = require_cors.createRequestAuthorizer(mcp, options);
33
- const handle = async (request, recorder) => {
34
- const authResult = await authorizer.authorize(request, recorder);
35
- if (!authResult.ok) return authResult.response;
36
- if (request.method !== "GET" && request.method !== "HEAD") return require_cors.methodNotAllowed("GET, HEAD, OPTIONS");
37
- const response = Response.json(buildMcpListing(mcp));
38
- return request.method === "HEAD" ? require_cors.headResponse(response) : response;
39
- };
40
- return async (request, recorder = require_cors.createNoopRecorder()) => {
41
- if (request.method === "OPTIONS") return require_cors.corsPreflightResponse("GET, HEAD, OPTIONS");
42
- return require_cors.withCors(await handle(request, recorder));
43
- };
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
+ });
44
39
  }
45
40
  //#endregion
46
41
  Object.defineProperty(exports, "buildMcpListing", {
@@ -95,9 +95,12 @@ let currentLevel = readEnvLevel() ?? "debug";
95
95
  * Set the runtime log level programmatically. Use this when the deployment can't
96
96
  * surface `LOVABLE_MCP_LOG_LEVEL` to the package (e.g. a Cloudflare Worker that
97
97
  * passes vars via bindings): call `setLogLevel("debug")` once at server startup.
98
+ * @returns the previous level, so a scoped override can restore it.
98
99
  */
99
100
  function setLogLevel(level) {
101
+ const previous = currentLevel;
100
102
  currentLevel = level;
103
+ return previous;
101
104
  }
102
105
  /** Parse an env value into a LogLevel, or undefined if it names no valid level. */
103
106
  function parseLogLevel(raw) {
@@ -95,9 +95,12 @@ let currentLevel = readEnvLevel() ?? "debug";
95
95
  * Set the runtime log level programmatically. Use this when the deployment can't
96
96
  * surface `LOVABLE_MCP_LOG_LEVEL` to the package (e.g. a Cloudflare Worker that
97
97
  * passes vars via bindings): call `setLogLevel("debug")` once at server startup.
98
+ * @returns the previous level, so a scoped override can restore it.
98
99
  */
99
100
  function setLogLevel(level) {
101
+ const previous = currentLevel;
100
102
  currentLevel = level;
103
+ return previous;
101
104
  }
102
105
  /** Parse an env value into a LogLevel, or undefined if it names no valid level. */
103
106
  function parseLogLevel(raw) {
@@ -1,12 +1,12 @@
1
- const require_logger = require("./logger-BSKbuM66.cjs");
1
+ const require_logger = require("./logger-BkMMCFTv.cjs");
2
2
  const require_errors = require("./errors-CN6Da8iz.cjs");
3
- const require_cors = require("./cors-DPRJFY-U.cjs");
3
+ const require_authorize = require("./authorize-FZydvyMU.cjs");
4
4
  const require_content = require("./content-NCYIGgOb.cjs");
5
+ const require_gate = require("./gate-Blmxv8t2.cjs");
5
6
  let _modelcontextprotocol_sdk_server_mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
6
7
  let _modelcontextprotocol_sdk_server_webStandardStreamableHttp_js = require("@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js");
7
8
  //#region src/protocols/mcp/protocol.ts
8
- const STATELESS_ALLOW_METHODS = "POST, OPTIONS";
9
- function statelessMethodNotAllowed() {
9
+ function statelessMethodNotAllowed(allow) {
10
10
  return Response.json({
11
11
  jsonrpc: "2.0",
12
12
  id: null,
@@ -16,7 +16,7 @@ function statelessMethodNotAllowed() {
16
16
  }
17
17
  }, {
18
18
  status: 405,
19
- headers: { Allow: STATELESS_ALLOW_METHODS }
19
+ headers: { Allow: allow }
20
20
  });
21
21
  }
22
22
  /**
@@ -27,7 +27,7 @@ function adaptToolToSdkCallback(tool, auth, recorder) {
27
27
  const endUserId = auth?.principal.sub;
28
28
  return (async (first) => {
29
29
  const args = tool.inputSchema ? first ?? {} : {};
30
- const start = require_cors.nowMs();
30
+ const start = require_authorize.nowMs();
31
31
  let result;
32
32
  try {
33
33
  result = await tool.handler(args, new require_errors.ToolContext(auth));
@@ -38,7 +38,7 @@ function adaptToolToSdkCallback(tool, auth, recorder) {
38
38
  tool: tool.name,
39
39
  method: "tools/call",
40
40
  outcome: "handler_error",
41
- durationMs: require_cors.nowMs() - start,
41
+ durationMs: require_authorize.nowMs() - start,
42
42
  errorText: require_errors.errorSummary(err),
43
43
  endUserId
44
44
  });
@@ -63,7 +63,7 @@ function adaptToolToSdkCallback(tool, auth, recorder) {
63
63
  tool: tool.name,
64
64
  method: "tools/call",
65
65
  outcome: "handler_error",
66
- durationMs: require_cors.nowMs() - start,
66
+ durationMs: require_authorize.nowMs() - start,
67
67
  endUserId
68
68
  });
69
69
  return {
@@ -78,7 +78,7 @@ function adaptToolToSdkCallback(tool, auth, recorder) {
78
78
  tool: tool.name,
79
79
  method: "tools/call",
80
80
  outcome: result.isError ? "tool_error" : "ok",
81
- durationMs: require_cors.nowMs() - start,
81
+ durationMs: require_authorize.nowMs() - start,
82
82
  errorText: result.isError ? require_content.extractTextContent(result.content) : void 0,
83
83
  endUserId
84
84
  });
@@ -97,10 +97,8 @@ function adaptToolToSdkCallback(tool, auth, recorder) {
97
97
  * caller (the stack handler) so telemetry reads the runtime env in-flight.
98
98
  */
99
99
  function createMcpProtocolHandler(mcp, options = {}) {
100
- const authorizer = require_cors.createRequestAuthorizer(mcp, options);
101
- const handle = async (request, recorder) => {
102
- const authResult = await authorizer.authorize(request, recorder);
103
- if (!authResult.ok) return authResult.response;
100
+ const authorizer = require_authorize.createRequestAuthorizer(mcp, options);
101
+ const handle = async (request, authResult, recorder) => {
104
102
  try {
105
103
  const server = new _modelcontextprotocol_sdk_server_mcp_js.McpServer({
106
104
  name: mcp.name,
@@ -139,11 +137,12 @@ function createMcpProtocolHandler(mcp, options = {}) {
139
137
  }, { status: 500 });
140
138
  }
141
139
  };
142
- return async (request, recorder = require_cors.createNoopRecorder()) => {
143
- if (request.method === "OPTIONS") return require_cors.corsPreflightResponse(STATELESS_ALLOW_METHODS);
144
- if (request.method !== "POST") return require_cors.withCors(statelessMethodNotAllowed());
145
- return require_cors.withCors(await handle(request, recorder));
146
- };
140
+ return require_gate.createGatedHandler({
141
+ authorizer,
142
+ methods: ["POST"],
143
+ methodNotAllowed: statelessMethodNotAllowed,
144
+ handle
145
+ });
147
146
  }
148
147
  //#endregion
149
148
  Object.defineProperty(exports, "createMcpProtocolHandler", {