@frontmcp/sdk 1.10.11 → 1.10.13
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 +887 -856
- package/browser/prompt/flows/get-prompt.flow.mjs +8 -2
- package/browser/resource/flows/read-resource.flow.mjs +7 -1
- package/browser/transport/mcp-20260728/dispatcher.mjs +16 -0
- package/browser/transport/mcp-handlers/initialize-request.handler.mjs +8 -5
- package/browser/transport/web-standard-mcp.mjs +14 -14
- package/esm/index.mjs +19 -19
- package/index.js +18 -18
- package/package.json +10 -10
- package/prompt/flows/get-prompt.flow.d.ts +1 -0
- package/prompt/flows/get-prompt.flow.d.ts.map +1 -1
- package/resource/flows/read-resource.flow.d.ts +1 -0
- package/resource/flows/read-resource.flow.d.ts.map +1 -1
- package/transport/mcp-20260728/dispatcher.d.ts.map +1 -1
- package/transport/mcp-handlers/initialize-request.handler.d.ts.map +1 -1
- package/transport/web-standard-mcp.d.ts.map +1 -1
|
@@ -59,7 +59,9 @@ var stateSchema = z.object({
|
|
|
59
59
|
promptContext: z.any(),
|
|
60
60
|
// z.any() used because prompt output type varies by prompt implementation
|
|
61
61
|
rawOutput: z.any().optional(),
|
|
62
|
-
output: outputSchema
|
|
62
|
+
output: outputSchema,
|
|
63
|
+
// Why the flow failed, set by the flow runner before the finalize stage
|
|
64
|
+
flowError: z.instanceof(Error).optional()
|
|
63
65
|
});
|
|
64
66
|
var plan = {
|
|
65
67
|
pre: [
|
|
@@ -288,7 +290,11 @@ var GetPromptFlow = class extends FlowBase {
|
|
|
288
290
|
}
|
|
289
291
|
async finalize() {
|
|
290
292
|
this.logger.verbose("finalize:start");
|
|
291
|
-
const { prompt, rawOutput, input } = this.state;
|
|
293
|
+
const { prompt, rawOutput, input, flowError } = this.state;
|
|
294
|
+
if (flowError) {
|
|
295
|
+
this.logger.verbose("finalize: skipping, an earlier stage failed");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
292
298
|
if (!prompt) {
|
|
293
299
|
this.logger.error("finalize: prompt not found in state");
|
|
294
300
|
throw new PromptExecutionError("unknown", new Error("Prompt not found in state"));
|
|
@@ -64,7 +64,9 @@ var stateSchema = z.object({
|
|
|
64
64
|
// Flag indicating this is a UI resource (ui:// scheme)
|
|
65
65
|
isUIResource: z.boolean().default(false),
|
|
66
66
|
// Pre-resolved UI resource result (if isUIResource is true)
|
|
67
|
-
uiResourceResult: outputSchema.optional()
|
|
67
|
+
uiResourceResult: outputSchema.optional(),
|
|
68
|
+
// Why the flow failed, set by the flow runner before the finalize stage
|
|
69
|
+
flowError: z.instanceof(Error).optional()
|
|
68
70
|
});
|
|
69
71
|
var plan = {
|
|
70
72
|
pre: ["parseInput", "ensureRemoteCapabilities", "findResource", "checkEntryAuthorities", "createResourceContext"],
|
|
@@ -312,6 +314,10 @@ var ReadResourceFlow = class extends FlowBase {
|
|
|
312
314
|
}
|
|
313
315
|
async finalize() {
|
|
314
316
|
this.logger.verbose("finalize:start");
|
|
317
|
+
if (this.state.flowError) {
|
|
318
|
+
this.logger.verbose("finalize: skipping, an earlier stage failed");
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
315
321
|
if (this.state.isUIResource) {
|
|
316
322
|
const { uiResourceResult, input: input2 } = this.state;
|
|
317
323
|
if (!uiResourceResult) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// libs/sdk/src/transport/mcp-20260728/dispatcher.ts
|
|
2
2
|
import { isAnonymousSubject } from "@frontmcp/auth";
|
|
3
|
+
import { z } from "@frontmcp/lazy-zod";
|
|
3
4
|
import {
|
|
4
5
|
MCP_20260728_ERROR_CODES,
|
|
5
6
|
MCP_20260728_REMOVED_METHODS,
|
|
@@ -92,6 +93,17 @@ function methodOfSchema(schema) {
|
|
|
92
93
|
const values = method?._def?.values;
|
|
93
94
|
return Array.isArray(values) && typeof values[0] === "string" ? values[0] : void 0;
|
|
94
95
|
}
|
|
96
|
+
var MRTR_PARAMS_SCHEMA = z.object({
|
|
97
|
+
params: z.object({ inputResponses: z.record(z.string(), z.record(z.string(), z.unknown())).optional() }).optional()
|
|
98
|
+
});
|
|
99
|
+
function describeInvalidParams(schema, body) {
|
|
100
|
+
const issues = [schema.safeParse(body), MRTR_PARAMS_SCHEMA.safeParse(body)].flatMap(
|
|
101
|
+
(parsed) => parsed.success ? [] : parsed.error.issues
|
|
102
|
+
);
|
|
103
|
+
if (issues.length === 0) return void 0;
|
|
104
|
+
const problems = issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`);
|
|
105
|
+
return `Invalid params: ${problems.join("; ")}`;
|
|
106
|
+
}
|
|
95
107
|
function toJsonRpcError(error) {
|
|
96
108
|
if (error instanceof MissingClientCapabilityError) {
|
|
97
109
|
return {
|
|
@@ -190,6 +202,10 @@ async function dispatch20260728(options) {
|
|
|
190
202
|
if (!handler) {
|
|
191
203
|
return { kind: "error", status: 404, error: { code: -32601, message: `Method not found: ${method}` } };
|
|
192
204
|
}
|
|
205
|
+
const invalidParams = describeInvalidParams(handler.requestSchema, body);
|
|
206
|
+
if (invalidParams) {
|
|
207
|
+
return { kind: "error", status: 200, error: { code: -32602, message: invalidParams } };
|
|
208
|
+
}
|
|
193
209
|
const binding = {
|
|
194
210
|
principal: resolvePrincipal(authInfo),
|
|
195
211
|
binding: computeRequestBinding(method, params)
|
|
@@ -45,6 +45,7 @@ function initializeRequestHandler({
|
|
|
45
45
|
request.params.capabilities?.elicitation ? { elicitation: request.params.capabilities.elicitation } : void 0
|
|
46
46
|
);
|
|
47
47
|
if (sessionId) {
|
|
48
|
+
const hasRegisteredServer = scope.notifications.getRegisteredServer(sessionId) !== void 0;
|
|
48
49
|
if (request.params.capabilities) {
|
|
49
50
|
const clientCapabilities = {
|
|
50
51
|
roots: request.params.capabilities.roots,
|
|
@@ -56,7 +57,7 @@ function initializeRequestHandler({
|
|
|
56
57
|
// Include elicitation capability for interactive user input support
|
|
57
58
|
elicitation: request.params.capabilities.elicitation
|
|
58
59
|
};
|
|
59
|
-
scope.notifications.setClientCapabilities(sessionId, clientCapabilities);
|
|
60
|
+
if (hasRegisteredServer) scope.notifications.setClientCapabilities(sessionId, clientCapabilities);
|
|
60
61
|
await scope.transportService?.updateStoredSessionCapabilities(
|
|
61
62
|
sessionId,
|
|
62
63
|
clientCapabilities
|
|
@@ -65,10 +66,12 @@ function initializeRequestHandler({
|
|
|
65
66
|
}
|
|
66
67
|
if (request.params.clientInfo) {
|
|
67
68
|
const { name: clientName, version: clientVersion } = request.params.clientInfo;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
if (hasRegisteredServer) {
|
|
70
|
+
scope.notifications.setClientInfo(sessionId, {
|
|
71
|
+
name: clientName,
|
|
72
|
+
version: clientVersion
|
|
73
|
+
});
|
|
74
|
+
}
|
|
72
75
|
const finalPlatform = resolvePlatformType(
|
|
73
76
|
request.params.clientInfo,
|
|
74
77
|
request.params.capabilities,
|
|
@@ -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,
|