@frontmcp/sdk 1.10.11 → 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.
- package/browser/index.cjs +15 -15
- package/browser/transport/web-standard-mcp.mjs +14 -14
- package/esm/index.mjs +1 -1
- package/index.js +1 -1
- package/package.json +10 -10
- package/transport/web-standard-mcp.d.ts.map +1 -1
package/browser/index.cjs
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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,
|