@frontmcp/sdk 1.10.10 → 1.10.12

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.
@@ -318,7 +318,7 @@ function decideIntent(req, cfg) {
318
318
  };
319
319
  }
320
320
  const { key, channel, flags, init } = computeBitmap(req, cfg);
321
- if (method === "POST") {
321
+ if (method === "POST" && channel !== CH_POST_MESSAGE) {
322
322
  const accept = h(req, "accept");
323
323
  const acceptsSSE = wantsSSE(accept);
324
324
  const acceptsJSON = wantsJSON(accept) || !accept && cfg.tolerateMissingAccept;
package/browser/index.cjs CHANGED
@@ -42287,7 +42287,7 @@ function decideIntent(req, cfg) {
42287
42287
  };
42288
42288
  }
42289
42289
  const { key, channel: channel2, flags, init } = computeBitmap(req, cfg);
42290
- if (method === "POST") {
42290
+ if (method === "POST" && channel2 !== CH_POST_MESSAGE) {
42291
42291
  const accept = h(req, "accept");
42292
42292
  const acceptsSSE = wantsSSE(accept);
42293
42293
  const acceptsJSON = wantsJSON(accept) || !accept && cfg.tolerateMissingAccept;
@@ -43932,30 +43932,29 @@ async function runWebStandardMcp(scope, request, options) {
43932
43932
  if (options.persistent) {
43933
43933
  return options.persistent.transport.handleRequest(request, { authInfo: options.authInfo });
43934
43934
  }
43935
+ if (!STATELESS_METHODS.includes(request.method)) return methodNotAllowed();
43935
43936
  const sessionId = `web:${(0, import_utils89.randomUUID)()}`;
43936
43937
  const accept = request.headers.get("accept") ?? "";
43937
- const wantsStream = request.method === "GET" || options.sse && accept.includes("text/event-stream");
43938
+ const wantsStream = options.sse && accept.includes("text/event-stream");
43938
43939
  const { mcpServer, transport } = await wireServer(scope, options.serverOptions, sessionId, void 0, !wantsStream);
43939
43940
  const response = await transport.handleRequest(request, {
43940
43941
  authInfo: options.authInfo
43941
43942
  });
43942
- if (response.headers.get("content-type")?.includes("text/event-stream")) {
43943
- const closed = new Promise((resolve) => {
43944
- const prev = transport.onclose;
43945
- transport.onclose = () => {
43946
- prev?.();
43947
- resolve();
43948
- };
43949
- });
43950
- const teardown = closed.then(() => mcpServer.close().catch(() => void 0));
43951
- if (options.ctx?.waitUntil) options.ctx.waitUntil(teardown);
43952
- else void teardown;
43953
- } else {
43943
+ if (!response.body || !response.headers.get("content-type")?.includes("text/event-stream")) {
43954
43944
  void mcpServer.close().catch(() => void 0);
43945
+ return response;
43955
43946
  }
43956
- return response;
43947
+ const { readable, writable } = new TransformStream();
43948
+ const teardown = response.body.pipeTo(writable).catch(() => void 0).then(() => mcpServer.close().catch(() => void 0));
43949
+ options.ctx?.waitUntil?.(teardown);
43950
+ return new Response(readable, response);
43951
+ }
43952
+ function methodNotAllowed() {
43953
+ const error = { code: -32e3, message: "Method not allowed." };
43954
+ const headers = { allow: STATELESS_METHODS.join(", ") };
43955
+ return Response.json({ jsonrpc: "2.0", error, id: null }, { status: 405, headers });
43957
43956
  }
43958
- var import_protocol50, import_utils89;
43957
+ var import_protocol50, import_utils89, STATELESS_METHODS;
43959
43958
  var init_web_standard_mcp = __esm({
43960
43959
  "libs/sdk/src/transport/web-standard-mcp.ts"() {
43961
43960
  "use strict";
@@ -43964,6 +43963,7 @@ var init_web_standard_mcp = __esm({
43964
43963
  init_skill_instructions_helper();
43965
43964
  init_body_limit();
43966
43965
  init_build_scoped_server_options();
43966
+ STATELESS_METHODS = ["POST", "DELETE"];
43967
43967
  }
43968
43968
  });
43969
43969
 
@@ -4,6 +4,7 @@ import { randomUUID } from "@frontmcp/utils";
4
4
  import { composeCallerInstructions } from "../skill/skill-instructions.helper.mjs";
5
5
  import { mcpTransportBodyLimit } from "./body-limit.mjs";
6
6
  import { buildScopedServerOptions } from "./build-scoped-server-options.mjs";
7
+ var STATELESS_METHODS = ["POST", "DELETE"];
7
8
  async function wireServer(scope, serverOptions, sessionId, sessionIdGenerator, enableJsonResponse) {
8
9
  const { createMcpHandlers } = await import("./mcp-handlers/index.mjs");
9
10
  const mcpServer = new McpServer(scope.metadata.info, serverOptions);
@@ -34,28 +35,27 @@ async function runWebStandardMcp(scope, request, options) {
34
35
  if (options.persistent) {
35
36
  return options.persistent.transport.handleRequest(request, { authInfo: options.authInfo });
36
37
  }
38
+ if (!STATELESS_METHODS.includes(request.method)) return methodNotAllowed();
37
39
  const sessionId = `web:${randomUUID()}`;
38
40
  const accept = request.headers.get("accept") ?? "";
39
- const wantsStream = request.method === "GET" || options.sse && accept.includes("text/event-stream");
41
+ const wantsStream = options.sse && accept.includes("text/event-stream");
40
42
  const { mcpServer, transport } = await wireServer(scope, options.serverOptions, sessionId, void 0, !wantsStream);
41
43
  const response = await transport.handleRequest(request, {
42
44
  authInfo: options.authInfo
43
45
  });
44
- if (response.headers.get("content-type")?.includes("text/event-stream")) {
45
- const closed = new Promise((resolve) => {
46
- const prev = transport.onclose;
47
- transport.onclose = () => {
48
- prev?.();
49
- resolve();
50
- };
51
- });
52
- const teardown = closed.then(() => mcpServer.close().catch(() => void 0));
53
- if (options.ctx?.waitUntil) options.ctx.waitUntil(teardown);
54
- else void teardown;
55
- } else {
46
+ if (!response.body || !response.headers.get("content-type")?.includes("text/event-stream")) {
56
47
  void mcpServer.close().catch(() => void 0);
48
+ return response;
57
49
  }
58
- return response;
50
+ const { readable, writable } = new TransformStream();
51
+ const teardown = response.body.pipeTo(writable).catch(() => void 0).then(() => mcpServer.close().catch(() => void 0));
52
+ options.ctx?.waitUntil?.(teardown);
53
+ return new Response(readable, response);
54
+ }
55
+ function methodNotAllowed() {
56
+ const error = { code: -32e3, message: "Method not allowed." };
57
+ const headers = { allow: STATELESS_METHODS.join(", ") };
58
+ return Response.json({ jsonrpc: "2.0", error, id: null }, { status: 405, headers });
59
59
  }
60
60
  export {
61
61
  buildPersistentWebStandardMcp,