@lovable.dev/mcp-js 0.26.3 → 0.27.1

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/{cors-CzTj3-nh.cjs → authorize-CB35c3Wg.cjs} +34 -34
  3. package/dist/{authorize-Y6Jm8GhR.d.ts → authorize-Cs1yyLrq.d.ts} +15 -3
  4. package/dist/{cors-D1m2Ud44.js → authorize-FOlzhxrM.js} +31 -25
  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-B9RSzvoI.cjs +24 -0
  10. package/dist/gate-BeHmyGxk.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-DOBMd4AE.d.cts → list-tools-Cn7tpE0V.d.cts} +1 -1
  19. package/dist/{list-tools-wQ13O3WE.cjs → list-tools-DiMCRunS.cjs} +9 -14
  20. package/dist/{list-tools-CTtFfDLi.js → list-tools-Dt-mhh52.js} +8 -13
  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-DlbNiP7o.js → mcp-DiVQhHIw.js} +11 -15
  24. package/dist/{mcp-CG_9H8CN.cjs → mcp-ECo1Ixk8.cjs} +16 -20
  25. package/dist/{package-oSicfX7m.cjs → package-BdaLbzEh.cjs} +1 -1
  26. package/dist/{package-Cr1oDeFn.js → package-dtiombMt.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-B9OtLlIc.cjs → rest-1Pf9sYNU.cjs} +23 -23
  40. package/dist/{rest-BTK8v5-l.js → rest-Cit2862S.js} +11 -11
  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 +10 -5
  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 +10 -5
  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 };
@@ -1,7 +1,28 @@
1
- const require_logger = require("./logger-BSKbuM66.cjs");
2
- const require_package = require("./package-oSicfX7m.cjs");
1
+ const require_logger = require("./logger-BkMMCFTv.cjs");
2
+ const require_package = require("./package-BdaLbzEh.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,6 +33,9 @@ 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,
@@ -767,7 +791,10 @@ function getOAuthRuntime(mcp, options = {}) {
767
791
  if (options.metadataPath !== void 0) assertResourcePathShape(options.metadataPath, "metadataPath");
768
792
  const stableOptions = {
769
793
  resourcePath: options.resourcePath,
770
- metadataPath: options.metadataPath
794
+ metadataPath: options.metadataPath,
795
+ trustForwardedHost: options.trustForwardedHost,
796
+ trustForwardedProto: options.trustForwardedProto,
797
+ forwardedHostTrustedByPlatform: options.forwardedHostTrustedByPlatform
771
798
  };
772
799
  const auth = mcp.auth?.type === "oauth" ? mcp.auth : void 0;
773
800
  if (!auth) return {
@@ -881,27 +908,6 @@ function createRequestAuthorizer(mcp, options = {}) {
881
908
  } };
882
909
  }
883
910
  //#endregion
884
- //#region src/core/cors.ts
885
- const EXPOSE_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
886
- const ALLOW_HEADERS = "Authorization, Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID";
887
- /** Add permissive CORS to a built response, preserving its other headers. */
888
- function withCors(response) {
889
- response.headers.set("Access-Control-Allow-Origin", "*");
890
- response.headers.set("Access-Control-Expose-Headers", EXPOSE_HEADERS);
891
- return response;
892
- }
893
- function corsPreflightResponse(allowMethods) {
894
- return new Response(null, {
895
- status: 204,
896
- headers: {
897
- "Access-Control-Allow-Origin": "*",
898
- "Access-Control-Allow-Methods": allowMethods,
899
- "Access-Control-Allow-Headers": ALLOW_HEADERS,
900
- "Access-Control-Max-Age": "86400"
901
- }
902
- });
903
- }
904
- //#endregion
905
911
  Object.defineProperty(exports, "JSON_HEADERS", {
906
912
  enumerable: true,
907
913
  get: function() {
@@ -944,16 +950,16 @@ Object.defineProperty(exports, "createRequestAuthorizer", {
944
950
  return createRequestAuthorizer;
945
951
  }
946
952
  });
947
- Object.defineProperty(exports, "getOAuthRuntime", {
953
+ Object.defineProperty(exports, "finalizeWireResponse", {
948
954
  enumerable: true,
949
955
  get: function() {
950
- return getOAuthRuntime;
956
+ return finalizeWireResponse;
951
957
  }
952
958
  });
953
- Object.defineProperty(exports, "headResponse", {
959
+ Object.defineProperty(exports, "getOAuthRuntime", {
954
960
  enumerable: true,
955
961
  get: function() {
956
- return headResponse;
962
+ return getOAuthRuntime;
957
963
  }
958
964
  });
959
965
  Object.defineProperty(exports, "methodNotAllowed", {
@@ -980,9 +986,3 @@ Object.defineProperty(exports, "resolveProtectedResource", {
980
986
  return resolveProtectedResource;
981
987
  }
982
988
  });
983
- Object.defineProperty(exports, "withCors", {
984
- enumerable: true,
985
- get: function() {
986
- return withCors;
987
- }
988
- });
@@ -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
- 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-Cr1oDeFn.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-dtiombMt.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,6 +33,9 @@ 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,
@@ -767,7 +791,10 @@ function getOAuthRuntime(mcp, options = {}) {
767
791
  if (options.metadataPath !== void 0) assertResourcePathShape(options.metadataPath, "metadataPath");
768
792
  const stableOptions = {
769
793
  resourcePath: options.resourcePath,
770
- metadataPath: options.metadataPath
794
+ metadataPath: options.metadataPath,
795
+ trustForwardedHost: options.trustForwardedHost,
796
+ trustForwardedProto: options.trustForwardedProto,
797
+ forwardedHostTrustedByPlatform: options.forwardedHostTrustedByPlatform
771
798
  };
772
799
  const auth = mcp.auth?.type === "oauth" ? mcp.auth : void 0;
773
800
  if (!auth) return {
@@ -881,25 +908,4 @@ function createRequestAuthorizer(mcp, options = {}) {
881
908
  } };
882
909
  }
883
910
  //#endregion
884
- //#region src/core/cors.ts
885
- const EXPOSE_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
886
- const ALLOW_HEADERS = "Authorization, Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID";
887
- /** Add permissive CORS to a built response, preserving its other headers. */
888
- function withCors(response) {
889
- response.headers.set("Access-Control-Allow-Origin", "*");
890
- response.headers.set("Access-Control-Expose-Headers", EXPOSE_HEADERS);
891
- return response;
892
- }
893
- function corsPreflightResponse(allowMethods) {
894
- return new Response(null, {
895
- status: 204,
896
- headers: {
897
- "Access-Control-Allow-Origin": "*",
898
- "Access-Control-Allow-Methods": allowMethods,
899
- "Access-Control-Allow-Headers": ALLOW_HEADERS,
900
- "Access-Control-Max-Age": "86400"
901
- }
902
- });
903
- }
904
- //#endregion
905
- 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-oSicfX7m.cjs");
3
- const require_list_tools = require("../list-tools-wQ13O3WE.cjs");
2
+ const require_package = require("../package-BdaLbzEh.cjs");
3
+ const require_list_tools = require("../list-tools-DiMCRunS.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-Cr1oDeFn.js";
3
- import { t as buildMcpListing } from "../list-tools-CTtFfDLi.js";
2
+ import { t as version } from "../package-dtiombMt.js";
3
+ import { t as buildMcpListing } from "../list-tools-Dt-mhh52.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-CB35c3Wg.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-FOlzhxrM.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,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-CzTj3-nh.cjs");
1
+ const require_authorize = require("./authorize-CB35c3Wg.cjs");
2
+ const require_gate = require("./gate-B9RSzvoI.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", {
@@ -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-D1m2Ud44.js";
1
+ import { f as methodNotAllowed, n as createRequestAuthorizer, t as assertRestResourceBinding } from "./authorize-FOlzhxrM.js";
2
+ import { t as createGatedHandler } from "./gate-BeHmyGxk.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 };
@@ -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
- import { i as log, r as describeError } from "./logger-3-kwsF-5.js";
1
+ import { i as log, r as describeError } from "./logger-rGakBvJ1.js";
2
2
  import { i as ToolContext, n as errorSummary, r as resolveToolErrorMessage } from "./errors-DSe96Ffd.js";
3
- import { d as nowMs, i as createRequestAuthorizer, n as withCors, t as corsPreflightResponse, u as createNoopRecorder } from "./cors-D1m2Ud44.js";
3
+ import { l as nowMs, n as createRequestAuthorizer } from "./authorize-FOlzhxrM.js";
4
4
  import { t as extractTextContent } from "./content-D5LJAHyM.js";
5
+ import { t as createGatedHandler } from "./gate-BeHmyGxk.js";
5
6
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
7
  import { WebStandardStreamableHTTPServerTransport } from "@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,10 +16,7 @@ function statelessMethodNotAllowed() {
16
16
  }
17
17
  }, {
18
18
  status: 405,
19
- headers: {
20
- Allow: STATELESS_ALLOW_METHODS,
21
- "Cache-Control": "no-store"
22
- }
19
+ headers: { Allow: allow }
23
20
  });
24
21
  }
25
22
  /**
@@ -140,13 +137,12 @@ function createMcpProtocolHandler(mcp, options = {}) {
140
137
  }, { status: 500 });
141
138
  }
142
139
  };
143
- return async (request, recorder = createNoopRecorder()) => {
144
- if (request.method === "OPTIONS") return corsPreflightResponse(STATELESS_ALLOW_METHODS);
145
- const authResult = await authorizer.authorize(request, recorder);
146
- if (!authResult.ok) return withCors(authResult.response);
147
- if (request.method !== "POST") return withCors(statelessMethodNotAllowed());
148
- return withCors(await handle(request, authResult, recorder));
149
- };
140
+ return createGatedHandler({
141
+ authorizer,
142
+ methods: ["POST"],
143
+ methodNotAllowed: statelessMethodNotAllowed,
144
+ handle
145
+ });
150
146
  }
151
147
  //#endregion
152
148
  export { createMcpProtocolHandler as t };