@lovable.dev/mcp-js 2.0.2 → 2.0.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 (31) hide show
  1. package/dist/{authorize-Wg16_NdO.d.ts → authorize-B5VMSzcN.d.ts} +4 -1
  2. package/dist/{authorize-BobVCjtA.d.cts → authorize-oCEahmRv.d.cts} +4 -1
  3. package/dist/{base-6YZsnawW.d.cts → base-DAkOPRay.d.cts} +1 -2
  4. package/dist/{base-BKfPCoJ4.d.ts → base-DnCoJOZN.d.ts} +1 -2
  5. package/dist/cli/extract-manifest.cjs +1 -1
  6. package/dist/cli/extract-manifest.js +1 -1
  7. package/dist/{cors-DgPttZS3.cjs → cors-D7UGErr1.cjs} +21 -15
  8. package/dist/{cors-Dtb_zOPJ.js → cors-struSqwR.js} +16 -16
  9. package/dist/{io-BAr6VW3z.js → io-C3ADoUpo.js} +1 -1
  10. package/dist/{io-CZzR7mTd.cjs → io-XzL-H5AK.cjs} +1 -1
  11. package/dist/{mcp-BoA7vYNm.js → mcp-BcqkkVKv.js} +7 -7
  12. package/dist/{mcp-B0a1JpSs.cjs → mcp-DS_Z5uVd.cjs} +7 -7
  13. package/dist/{package-BdEtuU4E.js → package-BEdPHDOg.js} +1 -1
  14. package/dist/{package-pO0n3HOU.cjs → package-JU_QJfZ9.cjs} +1 -1
  15. package/dist/protocols/mcp/index.cjs +1 -1
  16. package/dist/protocols/mcp/index.d.cts +3 -3
  17. package/dist/protocols/mcp/index.d.ts +3 -3
  18. package/dist/protocols/mcp/index.js +1 -1
  19. package/dist/protocols/oauth-metadata.cjs +4 -4
  20. package/dist/protocols/oauth-metadata.d.cts +3 -3
  21. package/dist/protocols/oauth-metadata.d.ts +3 -3
  22. package/dist/protocols/oauth-metadata.js +4 -4
  23. package/dist/stacks/supabase/index.cjs +11 -4
  24. package/dist/stacks/supabase/index.js +11 -4
  25. package/dist/stacks/supabase/vite.cjs +1 -1
  26. package/dist/stacks/supabase/vite.js +1 -1
  27. package/dist/stacks/tanstack/index.cjs +9 -4
  28. package/dist/stacks/tanstack/index.d.cts +5 -2
  29. package/dist/stacks/tanstack/index.d.ts +5 -2
  30. package/dist/stacks/tanstack/index.js +9 -4
  31. package/package.json +1 -1
@@ -1,4 +1,7 @@
1
1
  import "./types-C6O4ciic.js";
2
+ //#region src/metrics/recorder.d.ts
3
+ type ScheduleBackground = (task: Promise<unknown>) => void;
4
+ //#endregion
2
5
  //#region src/auth/authorize.d.ts
3
6
  interface McpRuntimeOptions {
4
7
  /** Public MCP path OAuth resource/audience checks bind to when it differs from the request path. */
@@ -33,4 +36,4 @@ interface McpRuntimeOptions {
33
36
  forwardedHostTrustedByPlatform?: boolean;
34
37
  }
35
38
  //#endregion
36
- export { McpRuntimeOptions as t };
39
+ export { ScheduleBackground as n, McpRuntimeOptions as t };
@@ -1,4 +1,7 @@
1
1
  import "./types-C6O4ciic.cjs";
2
+ //#region src/metrics/recorder.d.ts
3
+ type ScheduleBackground = (task: Promise<unknown>) => void;
4
+ //#endregion
2
5
  //#region src/auth/authorize.d.ts
3
6
  interface McpRuntimeOptions {
4
7
  /** Public MCP path OAuth resource/audience checks bind to when it differs from the request path. */
@@ -33,4 +36,4 @@ interface McpRuntimeOptions {
33
36
  forwardedHostTrustedByPlatform?: boolean;
34
37
  }
35
38
  //#endregion
36
- export { McpRuntimeOptions as t };
39
+ export { ScheduleBackground as n, McpRuntimeOptions as t };
@@ -27,8 +27,7 @@ interface InvocationRecord {
27
27
  * summary (`handler_error`). Local log only — never sent to the collector. */
28
28
  errorText?: string;
29
29
  }
30
- /** A per-request telemetry recorder. `emit` logs the invocation and sends it as a
31
- * single OTLP POST, awaited so it lands before the request ends. */
30
+ /** A per-request telemetry recorder. `emit` logs the invocation and sends it as a single OTLP POST. */
32
31
  interface MetricsRecorder {
33
32
  emit(ev: InvocationRecord): Promise<void>;
34
33
  }
@@ -27,8 +27,7 @@ interface InvocationRecord {
27
27
  * summary (`handler_error`). Local log only — never sent to the collector. */
28
28
  errorText?: string;
29
29
  }
30
- /** A per-request telemetry recorder. `emit` logs the invocation and sends it as a
31
- * single OTLP POST, awaited so it lands before the request ends. */
30
+ /** A per-request telemetry recorder. `emit` logs the invocation and sends it as a single OTLP POST. */
32
31
  interface MetricsRecorder {
33
32
  emit(ev: InvocationRecord): Promise<void>;
34
33
  }
@@ -4,7 +4,7 @@ const projectRoot = process.argv[2] ?? process.cwd();
4
4
  import("zod/v3").catch((err) => {
5
5
  const message = err instanceof Error ? err.message : String(err);
6
6
  throw new Error(`@lovable.dev/mcp-js requires zod ^3.25 or ^4.0 to extract MCP schemas. Verify the project's zod dependency and package resolution, then try again. Underlying error: ${message}`);
7
- }).then(() => Promise.resolve().then(() => require("../io-CZzR7mTd.cjs"))).then(({ runExtract }) => runExtract(projectRoot)).catch((err) => {
7
+ }).then(() => Promise.resolve().then(() => require("../io-XzL-H5AK.cjs"))).then(({ runExtract }) => runExtract(projectRoot)).catch((err) => {
8
8
  console.error(err instanceof Error ? err.message : String(err));
9
9
  process.exit(1);
10
10
  });
@@ -4,7 +4,7 @@ const projectRoot = process.argv[2] ?? process.cwd();
4
4
  import("zod/v3").catch((err) => {
5
5
  const message = err instanceof Error ? err.message : String(err);
6
6
  throw new Error(`@lovable.dev/mcp-js requires zod ^3.25 or ^4.0 to extract MCP schemas. Verify the project's zod dependency and package resolution, then try again. Underlying error: ${message}`);
7
- }).then(() => import("../io-BAr6VW3z.js")).then(({ runExtract }) => runExtract(projectRoot)).catch((err) => {
7
+ }).then(() => import("../io-C3ADoUpo.js")).then(({ runExtract }) => runExtract(projectRoot)).catch((err) => {
8
8
  console.error(err instanceof Error ? err.message : String(err));
9
9
  process.exit(1);
10
10
  });
@@ -1,5 +1,5 @@
1
1
  const require_logger = require("./logger-CN1q-KNn.cjs");
2
- const require_package = require("./package-pO0n3HOU.cjs");
2
+ const require_package = require("./package-JU_QJfZ9.cjs");
3
3
  require("./metadata-path-zd7NSNoa.cjs");
4
4
  let jose = require("jose");
5
5
  //#region src/core/http.ts
@@ -118,17 +118,7 @@ function readProcessEnv(name) {
118
118
  return;
119
119
  }
120
120
  }
121
- /**
122
- * Base per-request recorder. Owns everything stack-agnostic: log-level setup, the
123
- * `tool.invoked` log, the single-record OTLP POST (awaited so it lands within the
124
- * request — serverless workers kill detached work once the response returns), and
125
- * never throwing into tool dispatch. Every invocation is reported (no sampling).
126
- * Subclasses supply only the `stack` label and how to read env on that runtime.
127
- *
128
- * One instance is created per request by the stack handler and shared across
129
- * every invocation in that request; it is never a process-wide singleton, since
130
- * on Cloudflare the env binding isn't readable at module-init scope.
131
- */
121
+ /** Shared recorder implementation. Callers await `emit` or register it with the runtime's request lifetime. */
132
122
  var BaseMetricRecorder = class {
133
123
  config;
134
124
  server;
@@ -284,6 +274,16 @@ var SupabaseMetricRecorder = class extends BaseMetricRecorder {
284
274
  };
285
275
  //#endregion
286
276
  //#region src/metrics/recorder.ts
277
+ async function emitBeforeResponse(recorder, event, scheduleBackground) {
278
+ const task = recorder.emit(event);
279
+ if (scheduleBackground) try {
280
+ scheduleBackground(task);
281
+ return;
282
+ } catch (err) {
283
+ require_logger.log.warn("metrics.background_schedule_failed", require_logger.describeError(err));
284
+ }
285
+ await task;
286
+ }
287
287
  /** Vend the recorder for a stack, in-flight per request. Returns a no-op when
288
288
  * metrics are disabled (`metrics: false`); otherwise the stack-specific class, which
289
289
  * logs `tool.invoked` for tool invocations even if the key or endpoint is unavailable. */
@@ -840,7 +840,7 @@ function assertRequiredScopes(auth, context) {
840
840
  }
841
841
  function createRequestAuthorizer(mcp, options = {}) {
842
842
  const runtime = getOAuthRuntime(mcp, options);
843
- return { async authorize(request, recorder) {
843
+ return { async authorize(request, recorder, scheduleBackground) {
844
844
  if (runtime.kind === "unconfigured") return { ok: true };
845
845
  const startedAt = nowMs();
846
846
  const token = parseBearerToken(request);
@@ -850,13 +850,13 @@ function createRequestAuthorizer(mcp, options = {}) {
850
850
  httpMethod,
851
851
  outcome: "401"
852
852
  });
853
- await recorder?.emit({
853
+ if (recorder) await emitBeforeResponse(recorder, {
854
854
  tool: null,
855
855
  method: "authorize",
856
856
  outcome: "auth_challenge",
857
857
  httpMethod,
858
858
  durationMs: nowMs() - startedAt
859
- });
859
+ }, scheduleBackground);
860
860
  return {
861
861
  ok: false,
862
862
  response: challengeResponse(runtime.auth, request, runtime.options, 401)
@@ -1029,6 +1029,12 @@ Object.defineProperty(exports, "createRequestAuthorizer", {
1029
1029
  return createRequestAuthorizer;
1030
1030
  }
1031
1031
  });
1032
+ Object.defineProperty(exports, "emitBeforeResponse", {
1033
+ enumerable: true,
1034
+ get: function() {
1035
+ return emitBeforeResponse;
1036
+ }
1037
+ });
1032
1038
  Object.defineProperty(exports, "evaluateCors", {
1033
1039
  enumerable: true,
1034
1040
  get: function() {
@@ -1,5 +1,5 @@
1
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-Ctv5xUSD.js";
2
- import { t as version } from "./package-BdEtuU4E.js";
2
+ import { t as version } from "./package-BEdPHDOg.js";
3
3
  import "./metadata-path-CAkNcfyY.js";
4
4
  import { createLocalJWKSet, decodeProtectedHeader, errors, jwtVerify } from "jose";
5
5
  //#region src/core/http.ts
@@ -118,17 +118,7 @@ function readProcessEnv(name) {
118
118
  return;
119
119
  }
120
120
  }
121
- /**
122
- * Base per-request recorder. Owns everything stack-agnostic: log-level setup, the
123
- * `tool.invoked` log, the single-record OTLP POST (awaited so it lands within the
124
- * request — serverless workers kill detached work once the response returns), and
125
- * never throwing into tool dispatch. Every invocation is reported (no sampling).
126
- * Subclasses supply only the `stack` label and how to read env on that runtime.
127
- *
128
- * One instance is created per request by the stack handler and shared across
129
- * every invocation in that request; it is never a process-wide singleton, since
130
- * on Cloudflare the env binding isn't readable at module-init scope.
131
- */
121
+ /** Shared recorder implementation. Callers await `emit` or register it with the runtime's request lifetime. */
132
122
  var BaseMetricRecorder = class {
133
123
  config;
134
124
  server;
@@ -284,6 +274,16 @@ var SupabaseMetricRecorder = class extends BaseMetricRecorder {
284
274
  };
285
275
  //#endregion
286
276
  //#region src/metrics/recorder.ts
277
+ async function emitBeforeResponse(recorder, event, scheduleBackground) {
278
+ const task = recorder.emit(event);
279
+ if (scheduleBackground) try {
280
+ scheduleBackground(task);
281
+ return;
282
+ } catch (err) {
283
+ log.warn("metrics.background_schedule_failed", describeError(err));
284
+ }
285
+ await task;
286
+ }
287
287
  /** Vend the recorder for a stack, in-flight per request. Returns a no-op when
288
288
  * metrics are disabled (`metrics: false`); otherwise the stack-specific class, which
289
289
  * logs `tool.invoked` for tool invocations even if the key or endpoint is unavailable. */
@@ -840,7 +840,7 @@ function assertRequiredScopes(auth, context) {
840
840
  }
841
841
  function createRequestAuthorizer(mcp, options = {}) {
842
842
  const runtime = getOAuthRuntime(mcp, options);
843
- return { async authorize(request, recorder) {
843
+ return { async authorize(request, recorder, scheduleBackground) {
844
844
  if (runtime.kind === "unconfigured") return { ok: true };
845
845
  const startedAt = nowMs();
846
846
  const token = parseBearerToken(request);
@@ -850,13 +850,13 @@ function createRequestAuthorizer(mcp, options = {}) {
850
850
  httpMethod,
851
851
  outcome: "401"
852
852
  });
853
- await recorder?.emit({
853
+ if (recorder) await emitBeforeResponse(recorder, {
854
854
  tool: null,
855
855
  method: "authorize",
856
856
  outcome: "auth_challenge",
857
857
  httpMethod,
858
858
  durationMs: nowMs() - startedAt
859
- });
859
+ }, scheduleBackground);
860
860
  return {
861
861
  ok: false,
862
862
  response: challengeResponse(runtime.auth, request, runtime.options, 401)
@@ -999,4 +999,4 @@ function evaluateCors(request, allowedOrigins) {
999
999
  };
1000
1000
  }
1001
1001
  //#endregion
1002
- export { oauthConfigurationErrorResponse as a, createRecorderForRuntime as c, JSON_HEADERS as d, finalizeWireResponse as f, normalizeHttpMethod as i, createNoopRecorder as l, createRequestAuthorizer as n, assertResourcePathShape as o, methodNotAllowed as p, getOAuthRuntime as r, resolveProtectedResource as s, evaluateCors as t, nowMs as u };
1002
+ export { oauthConfigurationErrorResponse as a, createRecorderForRuntime as c, nowMs as d, JSON_HEADERS as f, normalizeHttpMethod as i, emitBeforeResponse as l, methodNotAllowed as m, createRequestAuthorizer as n, assertResourcePathShape as o, finalizeWireResponse as p, getOAuthRuntime as r, resolveProtectedResource as s, evaluateCors as t, createNoopRecorder as u };
@@ -1,5 +1,5 @@
1
1
  import { t as jsonSchemaFromDefinition } from "./schema-CW1jKvio.js";
2
- import { t as version } from "./package-BdEtuU4E.js";
2
+ import { t as version } from "./package-BEdPHDOg.js";
3
3
  import { t as isFileMissing } from "./fs-errors-PA2t1TIp.js";
4
4
  import { lstatSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
5
5
  import { dirname, resolve } from "node:path";
@@ -1,5 +1,5 @@
1
1
  const require_schema = require("./schema-D3vClxb7.cjs");
2
- const require_package = require("./package-pO0n3HOU.cjs");
2
+ const require_package = require("./package-JU_QJfZ9.cjs");
3
3
  const require_fs_errors = require("./fs-errors-CWNzOV75.cjs");
4
4
  let node_fs = require("node:fs");
5
5
  let node_path = require("node:path");
@@ -1,7 +1,7 @@
1
1
  import { i as log, r as describeError } from "./logger-Ctv5xUSD.js";
2
2
  import { n as schemaFromDefinition, t as jsonSchemaFromDefinition } from "./schema-CW1jKvio.js";
3
3
  import { i as ToolContext, n as errorSummary, r as resolveToolErrorMessage } from "./errors-Bwd1L0Rf.js";
4
- import { f as finalizeWireResponse, i as normalizeHttpMethod, l as createNoopRecorder, n as createRequestAuthorizer, t as evaluateCors, u as nowMs } from "./cors-Dtb_zOPJ.js";
4
+ import { d as nowMs, i as normalizeHttpMethod, l as emitBeforeResponse, n as createRequestAuthorizer, p as finalizeWireResponse, t as evaluateCors, u as createNoopRecorder } from "./cors-struSqwR.js";
5
5
  import { getParseErrorMessage, safeParseAsync } from "@modelcontextprotocol/sdk/server/zod-compat.js";
6
6
  import { CLIENT_CAPABILITIES_META_KEY, CLIENT_INFO_META_KEY, McpServer, createMcpHandler } from "@modelcontextprotocol/server";
7
7
  //#region src/core/content.ts
@@ -85,13 +85,13 @@ async function finalizeToolResult(tool, result) {
85
85
  //#region src/protocols/gate.ts
86
86
  function createGatedHandler(gate) {
87
87
  const allow = [...gate.methods, "OPTIONS"].join(", ");
88
- const respond = async (request, recorder) => {
89
- const authResult = await gate.authorizer.authorize(request, recorder);
88
+ const respond = async (request, recorder, scheduleBackground) => {
89
+ const authResult = await gate.authorizer.authorize(request, recorder, scheduleBackground);
90
90
  if (!authResult.ok) return authResult.response;
91
91
  if (!gate.methods.includes(request.method)) return gate.methodNotAllowed(allow);
92
92
  return gate.handle(request, authResult, recorder);
93
93
  };
94
- return async (request, recorder = createNoopRecorder()) => {
94
+ return async (request, recorder = createNoopRecorder(), scheduleBackground) => {
95
95
  const cors = evaluateCors(request, gate.allowedOrigins);
96
96
  if (!cors.ok) {
97
97
  const httpMethod = normalizeHttpMethod(request.method);
@@ -99,17 +99,17 @@ function createGatedHandler(gate) {
99
99
  origin: request.headers.get("Origin"),
100
100
  httpMethod
101
101
  });
102
- await recorder.emit({
102
+ await emitBeforeResponse(recorder, {
103
103
  tool: null,
104
104
  method: "authorize",
105
105
  outcome: "origin_rejected",
106
106
  httpMethod,
107
107
  durationMs: 0
108
- });
108
+ }, scheduleBackground);
109
109
  return finalizeWireResponse(request, cors.response);
110
110
  }
111
111
  if (request.method === "OPTIONS") return cors.preflight(allow);
112
- const final = finalizeWireResponse(request, cors.withHeaders(await respond(request, recorder)));
112
+ const final = finalizeWireResponse(request, cors.withHeaders(await respond(request, recorder, scheduleBackground)));
113
113
  if (!final.headers.has("Cache-Control")) final.headers.set("Cache-Control", "no-store");
114
114
  return final;
115
115
  };
@@ -1,7 +1,7 @@
1
1
  const require_logger = require("./logger-CN1q-KNn.cjs");
2
2
  const require_schema = require("./schema-D3vClxb7.cjs");
3
3
  const require_errors = require("./errors-Cr95rSkB.cjs");
4
- const require_cors = require("./cors-DgPttZS3.cjs");
4
+ const require_cors = require("./cors-D7UGErr1.cjs");
5
5
  let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
6
6
  let _modelcontextprotocol_server = require("@modelcontextprotocol/server");
7
7
  //#region src/core/content.ts
@@ -85,13 +85,13 @@ async function finalizeToolResult(tool, result) {
85
85
  //#region src/protocols/gate.ts
86
86
  function createGatedHandler(gate) {
87
87
  const allow = [...gate.methods, "OPTIONS"].join(", ");
88
- const respond = async (request, recorder) => {
89
- const authResult = await gate.authorizer.authorize(request, recorder);
88
+ const respond = async (request, recorder, scheduleBackground) => {
89
+ const authResult = await gate.authorizer.authorize(request, recorder, scheduleBackground);
90
90
  if (!authResult.ok) return authResult.response;
91
91
  if (!gate.methods.includes(request.method)) return gate.methodNotAllowed(allow);
92
92
  return gate.handle(request, authResult, recorder);
93
93
  };
94
- return async (request, recorder = require_cors.createNoopRecorder()) => {
94
+ return async (request, recorder = require_cors.createNoopRecorder(), scheduleBackground) => {
95
95
  const cors = require_cors.evaluateCors(request, gate.allowedOrigins);
96
96
  if (!cors.ok) {
97
97
  const httpMethod = require_cors.normalizeHttpMethod(request.method);
@@ -99,17 +99,17 @@ function createGatedHandler(gate) {
99
99
  origin: request.headers.get("Origin"),
100
100
  httpMethod
101
101
  });
102
- await recorder.emit({
102
+ await require_cors.emitBeforeResponse(recorder, {
103
103
  tool: null,
104
104
  method: "authorize",
105
105
  outcome: "origin_rejected",
106
106
  httpMethod,
107
107
  durationMs: 0
108
- });
108
+ }, scheduleBackground);
109
109
  return require_cors.finalizeWireResponse(request, cors.response);
110
110
  }
111
111
  if (request.method === "OPTIONS") return cors.preflight(allow);
112
- const final = require_cors.finalizeWireResponse(request, cors.withHeaders(await respond(request, recorder)));
112
+ const final = require_cors.finalizeWireResponse(request, cors.withHeaders(await respond(request, recorder, scheduleBackground)));
113
113
  if (!final.headers.has("Cache-Control")) final.headers.set("Cache-Control", "no-store");
114
114
  return final;
115
115
  };
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "2.0.2";
2
+ var version = "2.0.3";
3
3
  //#endregion
4
4
  export { version as t };
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.0.2";
2
+ var version = "2.0.3";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
@@ -1,3 +1,3 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_mcp = require("../../mcp-B0a1JpSs.cjs");
2
+ const require_mcp = require("../../mcp-DS_Z5uVd.cjs");
3
3
  exports.createMcpProtocolHandler = require_mcp.createMcpProtocolHandler;
@@ -1,8 +1,8 @@
1
1
  import { d as McpDefinition } from "../../types-C6O4ciic.cjs";
2
- import { t as MetricsRecorder } from "../../base-6YZsnawW.cjs";
3
- import { t as McpRuntimeOptions } from "../../authorize-BobVCjtA.cjs";
2
+ import { t as MetricsRecorder } from "../../base-DAkOPRay.cjs";
3
+ import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-oCEahmRv.cjs";
4
4
  //#region src/protocols/mcp/protocol.d.ts
5
- type McpProtocolHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
5
+ type McpProtocolHandler = (request: Request, recorder?: MetricsRecorder, scheduleBackground?: ScheduleBackground) => Promise<Response>;
6
6
  /**
7
7
  * Build a Web-Standard request handler that serves the MCP protocol over
8
8
  * streamable HTTP. A fresh `McpServer` + transport is constructed per
@@ -1,8 +1,8 @@
1
1
  import { d as McpDefinition } from "../../types-C6O4ciic.js";
2
- import { t as MetricsRecorder } from "../../base-BKfPCoJ4.js";
3
- import { t as McpRuntimeOptions } from "../../authorize-Wg16_NdO.js";
2
+ import { t as MetricsRecorder } from "../../base-DnCoJOZN.js";
3
+ import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-B5VMSzcN.js";
4
4
  //#region src/protocols/mcp/protocol.d.ts
5
- type McpProtocolHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
5
+ type McpProtocolHandler = (request: Request, recorder?: MetricsRecorder, scheduleBackground?: ScheduleBackground) => Promise<Response>;
6
6
  /**
7
7
  * Build a Web-Standard request handler that serves the MCP protocol over
8
8
  * streamable HTTP. A fresh `McpServer` + transport is constructed per
@@ -1,2 +1,2 @@
1
- import { t as createMcpProtocolHandler } from "../../mcp-BoA7vYNm.js";
1
+ import { t as createMcpProtocolHandler } from "../../mcp-BcqkkVKv.js";
2
2
  export { createMcpProtocolHandler };
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_logger = require("../logger-CN1q-KNn.cjs");
3
- const require_cors = require("../cors-DgPttZS3.cjs");
3
+ const require_cors = require("../cors-D7UGErr1.cjs");
4
4
  //#region src/protocols/oauth-metadata.ts
5
5
  function notFound() {
6
6
  return new Response(JSON.stringify({ error: "not found" }), {
@@ -52,7 +52,7 @@ function createOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
52
52
  return require_cors.oauthConfigurationErrorResponse();
53
53
  }
54
54
  };
55
- return async (request, recorder = require_cors.createNoopRecorder()) => {
55
+ return async (request, recorder = require_cors.createNoopRecorder(), scheduleBackground) => {
56
56
  const cors = require_cors.evaluateCors(request, mcp.allowedOrigins);
57
57
  if (!cors.ok) {
58
58
  const httpMethod = require_cors.normalizeHttpMethod(request.method);
@@ -61,13 +61,13 @@ function createOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
61
61
  httpMethod,
62
62
  route: "oauth-metadata"
63
63
  });
64
- await recorder.emit({
64
+ await require_cors.emitBeforeResponse(recorder, {
65
65
  tool: null,
66
66
  method: "authorize",
67
67
  outcome: "origin_rejected",
68
68
  httpMethod,
69
69
  durationMs: 0
70
- });
70
+ }, scheduleBackground);
71
71
  return require_cors.finalizeWireResponse(request, cors.response);
72
72
  }
73
73
  if (request.method === "OPTIONS") return cors.preflight("GET, HEAD, OPTIONS");
@@ -1,8 +1,8 @@
1
1
  import { d as McpDefinition } from "../types-C6O4ciic.cjs";
2
- import { t as MetricsRecorder } from "../base-6YZsnawW.cjs";
3
- import { t as McpRuntimeOptions } from "../authorize-BobVCjtA.cjs";
2
+ import { t as MetricsRecorder } from "../base-DAkOPRay.cjs";
3
+ import { n as ScheduleBackground, t as McpRuntimeOptions } from "../authorize-oCEahmRv.cjs";
4
4
  //#region src/protocols/oauth-metadata.d.ts
5
- type OAuthProtectedResourceMetadataHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
5
+ type OAuthProtectedResourceMetadataHandler = (request: Request, recorder?: MetricsRecorder, scheduleBackground?: ScheduleBackground) => Promise<Response>;
6
6
  declare function createOAuthProtectedResourceMetadataHandler(mcp: McpDefinition, options?: McpRuntimeOptions): OAuthProtectedResourceMetadataHandler;
7
7
  //#endregion
8
8
  export { OAuthProtectedResourceMetadataHandler, createOAuthProtectedResourceMetadataHandler };
@@ -1,8 +1,8 @@
1
1
  import { d as McpDefinition } from "../types-C6O4ciic.js";
2
- import { t as MetricsRecorder } from "../base-BKfPCoJ4.js";
3
- import { t as McpRuntimeOptions } from "../authorize-Wg16_NdO.js";
2
+ import { t as MetricsRecorder } from "../base-DnCoJOZN.js";
3
+ import { n as ScheduleBackground, t as McpRuntimeOptions } from "../authorize-B5VMSzcN.js";
4
4
  //#region src/protocols/oauth-metadata.d.ts
5
- type OAuthProtectedResourceMetadataHandler = (request: Request, recorder?: MetricsRecorder) => Promise<Response>;
5
+ type OAuthProtectedResourceMetadataHandler = (request: Request, recorder?: MetricsRecorder, scheduleBackground?: ScheduleBackground) => Promise<Response>;
6
6
  declare function createOAuthProtectedResourceMetadataHandler(mcp: McpDefinition, options?: McpRuntimeOptions): OAuthProtectedResourceMetadataHandler;
7
7
  //#endregion
8
8
  export { OAuthProtectedResourceMetadataHandler, createOAuthProtectedResourceMetadataHandler };
@@ -1,5 +1,5 @@
1
1
  import { i as log, r as describeError } from "../logger-Ctv5xUSD.js";
2
- import { a as oauthConfigurationErrorResponse, d as JSON_HEADERS, f as finalizeWireResponse, i as normalizeHttpMethod, l as createNoopRecorder, p as methodNotAllowed, r as getOAuthRuntime, s as resolveProtectedResource, t as evaluateCors } from "../cors-Dtb_zOPJ.js";
2
+ import { a as oauthConfigurationErrorResponse, f as JSON_HEADERS, i as normalizeHttpMethod, l as emitBeforeResponse, m as methodNotAllowed, p as finalizeWireResponse, r as getOAuthRuntime, s as resolveProtectedResource, t as evaluateCors, u as createNoopRecorder } from "../cors-struSqwR.js";
3
3
  //#region src/protocols/oauth-metadata.ts
4
4
  function notFound() {
5
5
  return new Response(JSON.stringify({ error: "not found" }), {
@@ -51,7 +51,7 @@ function createOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
51
51
  return oauthConfigurationErrorResponse();
52
52
  }
53
53
  };
54
- return async (request, recorder = createNoopRecorder()) => {
54
+ return async (request, recorder = createNoopRecorder(), scheduleBackground) => {
55
55
  const cors = evaluateCors(request, mcp.allowedOrigins);
56
56
  if (!cors.ok) {
57
57
  const httpMethod = normalizeHttpMethod(request.method);
@@ -60,13 +60,13 @@ function createOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
60
60
  httpMethod,
61
61
  route: "oauth-metadata"
62
62
  });
63
- await recorder.emit({
63
+ await emitBeforeResponse(recorder, {
64
64
  tool: null,
65
65
  method: "authorize",
66
66
  outcome: "origin_rejected",
67
67
  httpMethod,
68
68
  durationMs: 0
69
- });
69
+ }, scheduleBackground);
70
70
  return finalizeWireResponse(request, cors.response);
71
71
  }
72
72
  if (request.method === "OPTIONS") return cors.preflight("GET, HEAD, OPTIONS");
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_logger = require("../../logger-CN1q-KNn.cjs");
3
- const require_cors = require("../../cors-DgPttZS3.cjs");
3
+ const require_cors = require("../../cors-D7UGErr1.cjs");
4
4
  const require_metadata_path = require("../../metadata-path-zd7NSNoa.cjs");
5
- const require_mcp = require("../../mcp-B0a1JpSs.cjs");
5
+ const require_mcp = require("../../mcp-DS_Z5uVd.cjs");
6
6
  const require_protocols_oauth_metadata = require("../../protocols/oauth-metadata.cjs");
7
7
  const require_forwarded = require("../../forwarded-B37IdmMX.cjs");
8
8
  const require_paths = require("../../paths-OP318a6c.cjs");
@@ -16,6 +16,12 @@ function deriveResourcePath(options) {
16
16
  function isMetadataPath(pathname) {
17
17
  return (pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname).endsWith(require_metadata_path.OAUTH_PROTECTED_RESOURCE_METADATA_PATH);
18
18
  }
19
+ function getScheduleBackground() {
20
+ const edgeRuntime = globalThis.EdgeRuntime;
21
+ const waitUntil = edgeRuntime?.waitUntil;
22
+ if (typeof waitUntil !== "function") return void 0;
23
+ return (task) => waitUntil.call(edgeRuntime, task);
24
+ }
19
25
  /**
20
26
  * Build a single Web-Standard handler that serves the full MCP surface from
21
27
  * one Supabase Edge Function. The returned handler dispatches by URL suffix:
@@ -44,8 +50,9 @@ function createSupabaseHandler(mcp, options = {}) {
44
50
  const metadataHandler = require_protocols_oauth_metadata.createOAuthProtectedResourceMetadataHandler(mcp, runtimeOptions);
45
51
  return async (request) => {
46
52
  const req = require_forwarded.applyForwardedOrigin(request, runtimeOptions);
47
- if (isMetadataPath(new URL(req.url).pathname)) return metadataHandler(req, require_cors.createRecorderForRuntime(mcp, { stack: "supabase" }));
48
- return mcpHandler(req, require_cors.createRecorderForRuntime(mcp, { stack: "supabase" }));
53
+ const scheduleBackground = getScheduleBackground();
54
+ if (isMetadataPath(new URL(req.url).pathname)) return metadataHandler(req, require_cors.createRecorderForRuntime(mcp, { stack: "supabase" }), scheduleBackground);
55
+ return mcpHandler(req, require_cors.createRecorderForRuntime(mcp, { stack: "supabase" }), scheduleBackground);
49
56
  };
50
57
  }
51
58
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { s as trimTrailingSlash } from "../../logger-Ctv5xUSD.js";
2
- import { c as createRecorderForRuntime, o as assertResourcePathShape } from "../../cors-Dtb_zOPJ.js";
2
+ import { c as createRecorderForRuntime, o as assertResourcePathShape } from "../../cors-struSqwR.js";
3
3
  import { t as OAUTH_PROTECTED_RESOURCE_METADATA_PATH } from "../../metadata-path-CAkNcfyY.js";
4
- import { t as createMcpProtocolHandler } from "../../mcp-BoA7vYNm.js";
4
+ import { t as createMcpProtocolHandler } from "../../mcp-BcqkkVKv.js";
5
5
  import { createOAuthProtectedResourceMetadataHandler } from "../../protocols/oauth-metadata.js";
6
6
  import { t as applyForwardedOrigin } from "../../forwarded-BBXvFeh6.js";
7
7
  import { n as assertFunctionName, t as FUNCTIONS_MOUNT_PREFIX } from "../../paths-IS65L6TA.js";
@@ -15,6 +15,12 @@ function deriveResourcePath(options) {
15
15
  function isMetadataPath(pathname) {
16
16
  return (pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname).endsWith(OAUTH_PROTECTED_RESOURCE_METADATA_PATH);
17
17
  }
18
+ function getScheduleBackground() {
19
+ const edgeRuntime = globalThis.EdgeRuntime;
20
+ const waitUntil = edgeRuntime?.waitUntil;
21
+ if (typeof waitUntil !== "function") return void 0;
22
+ return (task) => waitUntil.call(edgeRuntime, task);
23
+ }
18
24
  /**
19
25
  * Build a single Web-Standard handler that serves the full MCP surface from
20
26
  * one Supabase Edge Function. The returned handler dispatches by URL suffix:
@@ -43,8 +49,9 @@ function createSupabaseHandler(mcp, options = {}) {
43
49
  const metadataHandler = createOAuthProtectedResourceMetadataHandler(mcp, runtimeOptions);
44
50
  return async (request) => {
45
51
  const req = applyForwardedOrigin(request, runtimeOptions);
46
- if (isMetadataPath(new URL(req.url).pathname)) return metadataHandler(req, createRecorderForRuntime(mcp, { stack: "supabase" }));
47
- return mcpHandler(req, createRecorderForRuntime(mcp, { stack: "supabase" }));
52
+ const scheduleBackground = getScheduleBackground();
53
+ if (isMetadataPath(new URL(req.url).pathname)) return metadataHandler(req, createRecorderForRuntime(mcp, { stack: "supabase" }), scheduleBackground);
54
+ return mcpHandler(req, createRecorderForRuntime(mcp, { stack: "supabase" }), scheduleBackground);
48
55
  };
49
56
  }
50
57
  //#endregion
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_package = require("../../package-pO0n3HOU.cjs");
5
+ const require_package = require("../../package-JU_QJfZ9.cjs");
6
6
  const require_fs_errors = require("../../fs-errors-CWNzOV75.cjs");
7
7
  const require_supabase_config = require("../../supabase-config-Dz7dnUv0.cjs");
8
8
  const require_paths = require("../../paths-OP318a6c.cjs");
@@ -1,4 +1,4 @@
1
- import { t as version } from "../../package-BdEtuU4E.js";
1
+ import { t as version } from "../../package-BEdPHDOg.js";
2
2
  import { t as isFileMissing } from "../../fs-errors-PA2t1TIp.js";
3
3
  import { t as readSupabaseProjectRef } from "../../supabase-config-CakTU8YF.js";
4
4
  import { n as assertFunctionName, t as FUNCTIONS_MOUNT_PREFIX } from "../../paths-IS65L6TA.js";
@@ -1,17 +1,22 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_cors = require("../../cors-DgPttZS3.cjs");
3
- const require_mcp = require("../../mcp-B0a1JpSs.cjs");
2
+ const require_cors = require("../../cors-D7UGErr1.cjs");
3
+ const require_mcp = require("../../mcp-DS_Z5uVd.cjs");
4
4
  const require_protocols_oauth_metadata = require("../../protocols/oauth-metadata.cjs");
5
5
  const require_forwarded = require("../../forwarded-B37IdmMX.cjs");
6
6
  //#region src/stacks/tanstack/handlers.ts
7
7
  const STACK = "tanstack";
8
+ function getScheduleBackground(request) {
9
+ const waitUntil = request.waitUntil;
10
+ if (typeof waitUntil !== "function") return void 0;
11
+ return (task) => waitUntil.call(request, task);
12
+ }
8
13
  /**
9
14
  * Build a TanStack Start handler for the MCP protocol endpoint
10
15
  * (`POST /mcp`). Assignable directly to a route's `ANY` handler.
11
16
  */
12
17
  function createTanStackMcpHandler(mcp, options = {}) {
13
18
  const handler = require_mcp.createMcpProtocolHandler(mcp, options);
14
- return ({ request }) => handler(require_forwarded.applyForwardedOrigin(request, options), require_cors.createRecorderForRuntime(mcp, { stack: STACK }));
19
+ return ({ request }) => handler(require_forwarded.applyForwardedOrigin(request, options), require_cors.createRecorderForRuntime(mcp, { stack: STACK }), getScheduleBackground(request));
15
20
  }
16
21
  /**
17
22
  * Build a TanStack Start handler for `GET /.well-known/oauth-protected-resource`.
@@ -19,7 +24,7 @@ function createTanStackMcpHandler(mcp, options = {}) {
19
24
  */
20
25
  function createTanStackOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
21
26
  const handler = require_protocols_oauth_metadata.createOAuthProtectedResourceMetadataHandler(mcp, options);
22
- return ({ request }) => handler(require_forwarded.applyForwardedOrigin(request, options), require_cors.createRecorderForRuntime(mcp, { stack: STACK }));
27
+ return ({ request }) => handler(require_forwarded.applyForwardedOrigin(request, options), require_cors.createRecorderForRuntime(mcp, { stack: STACK }), getScheduleBackground(request));
23
28
  }
24
29
  //#endregion
25
30
  exports.createTanStackMcpHandler = createTanStackMcpHandler;
@@ -1,8 +1,11 @@
1
1
  import { d as McpDefinition } from "../../types-C6O4ciic.cjs";
2
- import { t as McpRuntimeOptions } from "../../authorize-BobVCjtA.cjs";
2
+ import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-oCEahmRv.cjs";
3
3
  //#region src/stacks/tanstack/handlers.d.ts
4
+ interface TanStackRequest extends Request {
5
+ waitUntil?: ScheduleBackground;
6
+ }
4
7
  interface TanStackRouteCtx {
5
- request: Request;
8
+ request: TanStackRequest;
6
9
  }
7
10
  type TanStackMcpHandler = (ctx: TanStackRouteCtx) => Promise<Response>;
8
11
  type TanStackOAuthProtectedResourceMetadataHandler = (ctx: TanStackRouteCtx) => Promise<Response>;
@@ -1,8 +1,11 @@
1
1
  import { d as McpDefinition } from "../../types-C6O4ciic.js";
2
- import { t as McpRuntimeOptions } from "../../authorize-Wg16_NdO.js";
2
+ import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-B5VMSzcN.js";
3
3
  //#region src/stacks/tanstack/handlers.d.ts
4
+ interface TanStackRequest extends Request {
5
+ waitUntil?: ScheduleBackground;
6
+ }
4
7
  interface TanStackRouteCtx {
5
- request: Request;
8
+ request: TanStackRequest;
6
9
  }
7
10
  type TanStackMcpHandler = (ctx: TanStackRouteCtx) => Promise<Response>;
8
11
  type TanStackOAuthProtectedResourceMetadataHandler = (ctx: TanStackRouteCtx) => Promise<Response>;
@@ -1,16 +1,21 @@
1
- import { c as createRecorderForRuntime } from "../../cors-Dtb_zOPJ.js";
2
- import { t as createMcpProtocolHandler } from "../../mcp-BoA7vYNm.js";
1
+ import { c as createRecorderForRuntime } from "../../cors-struSqwR.js";
2
+ import { t as createMcpProtocolHandler } from "../../mcp-BcqkkVKv.js";
3
3
  import { createOAuthProtectedResourceMetadataHandler } from "../../protocols/oauth-metadata.js";
4
4
  import { t as applyForwardedOrigin } from "../../forwarded-BBXvFeh6.js";
5
5
  //#region src/stacks/tanstack/handlers.ts
6
6
  const STACK = "tanstack";
7
+ function getScheduleBackground(request) {
8
+ const waitUntil = request.waitUntil;
9
+ if (typeof waitUntil !== "function") return void 0;
10
+ return (task) => waitUntil.call(request, task);
11
+ }
7
12
  /**
8
13
  * Build a TanStack Start handler for the MCP protocol endpoint
9
14
  * (`POST /mcp`). Assignable directly to a route's `ANY` handler.
10
15
  */
11
16
  function createTanStackMcpHandler(mcp, options = {}) {
12
17
  const handler = createMcpProtocolHandler(mcp, options);
13
- return ({ request }) => handler(applyForwardedOrigin(request, options), createRecorderForRuntime(mcp, { stack: STACK }));
18
+ return ({ request }) => handler(applyForwardedOrigin(request, options), createRecorderForRuntime(mcp, { stack: STACK }), getScheduleBackground(request));
14
19
  }
15
20
  /**
16
21
  * Build a TanStack Start handler for `GET /.well-known/oauth-protected-resource`.
@@ -18,7 +23,7 @@ function createTanStackMcpHandler(mcp, options = {}) {
18
23
  */
19
24
  function createTanStackOAuthProtectedResourceMetadataHandler(mcp, options = {}) {
20
25
  const handler = createOAuthProtectedResourceMetadataHandler(mcp, options);
21
- return ({ request }) => handler(applyForwardedOrigin(request, options), createRecorderForRuntime(mcp, { stack: STACK }));
26
+ return ({ request }) => handler(applyForwardedOrigin(request, options), createRecorderForRuntime(mcp, { stack: STACK }), getScheduleBackground(request));
22
27
  }
23
28
  //#endregion
24
29
  export { createTanStackMcpHandler, createTanStackOAuthProtectedResourceMetadataHandler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/mcp-js",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },