@frontmcp/sdk 1.10.3 → 1.10.5
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/common/tokens/server.tokens.mjs +2 -1
- package/browser/common/types/options/transport/schema.mjs +2 -0
- package/browser/front-mcp/front-mcp.mjs +5 -1
- package/browser/index.cjs +187 -13
- package/browser/transport/flows/handle.mcp-20260728.flow.mjs +19 -5
- package/browser/transport/mcp-20260728/dispatcher.mjs +5 -3
- package/browser/transport/mcp-20260728/subscriptions.mjs +2 -1
- package/browser/transport/stdio-revision-router.mjs +147 -0
- package/common/tokens/server.tokens.d.ts +8 -0
- package/common/tokens/server.tokens.d.ts.map +1 -1
- package/common/types/options/transport/interfaces.d.ts +3 -1
- package/common/types/options/transport/interfaces.d.ts.map +1 -1
- package/common/types/options/transport/schema.d.ts.map +1 -1
- package/esm/index.mjs +190 -11
- package/front-mcp/front-mcp.d.ts +2 -0
- package/front-mcp/front-mcp.d.ts.map +1 -1
- package/index.js +187 -13
- package/package.json +10 -10
- package/transport/flows/handle.mcp-20260728.flow.d.ts +2 -0
- package/transport/flows/handle.mcp-20260728.flow.d.ts.map +1 -1
- package/transport/mcp-20260728/dispatcher.d.ts +2 -0
- package/transport/mcp-20260728/dispatcher.d.ts.map +1 -1
- package/transport/mcp-20260728/subscriptions.d.ts.map +1 -1
- package/transport/stdio-revision-router.d.ts +32 -0
- package/transport/stdio-revision-router.d.ts.map +1 -0
|
@@ -10,7 +10,8 @@ var ServerRequestTokens = {
|
|
|
10
10
|
webCtx: tokenFactory.meta("webCtx"),
|
|
11
11
|
webEnv: tokenFactory.meta("webEnv"),
|
|
12
12
|
webTransport: tokenFactory.meta("webTransport"),
|
|
13
|
-
relayedFrom: tokenFactory.meta("relayedFrom")
|
|
13
|
+
relayedFrom: tokenFactory.meta("relayedFrom"),
|
|
14
|
+
stdio: tokenFactory.meta("stdio")
|
|
14
15
|
};
|
|
15
16
|
export {
|
|
16
17
|
ServerRequestTokens
|
|
@@ -140,6 +140,8 @@ var transportOptionsSchema = z.object({
|
|
|
140
140
|
* friends), where statelessness is the natural fit and sessions cost a
|
|
141
141
|
* Durable Object; and to `'legacy'` everywhere else, so existing Node
|
|
142
142
|
* deployments are untouched.
|
|
143
|
+
*
|
|
144
|
+
* Over stdio (`'legacy'` by default) it applies until the connection sends `initialize`.
|
|
143
145
|
*/
|
|
144
146
|
defaultProtocolVersion: z.enum(["2026-07-28", "legacy"]).optional(),
|
|
145
147
|
// ============================================
|
|
@@ -518,6 +518,8 @@ var FrontMcpInstance = class _FrontMcpInstance {
|
|
|
518
518
|
* transport and returns only when the connection closes. **No TCP port is
|
|
519
519
|
* bound** — the HTTP server is disabled for this entry point (#451).
|
|
520
520
|
*
|
|
521
|
+
* One connection serves every revision: `initialize` opens a session, a 2026-07-28 request is served statelessly.
|
|
522
|
+
*
|
|
521
523
|
* Accepts either a `@FrontMcp`-decorated class or the same config object you
|
|
522
524
|
* pass to `@FrontMcp()` (#450).
|
|
523
525
|
*
|
|
@@ -654,7 +656,9 @@ var FrontMcpInstance = class _FrontMcpInstance {
|
|
|
654
656
|
mcpServer.setRequestHandler(handler.requestSchema, wrappedHandler);
|
|
655
657
|
}
|
|
656
658
|
const { IpcServerTransport, isIpcStdioRequested } = await import("../transport/ipc-server.transport.mjs");
|
|
657
|
-
const
|
|
659
|
+
const { StdioRevisionRouter } = await import("../transport/stdio-revision-router.mjs");
|
|
660
|
+
const stdioTransport = isIpcStdioRequested() ? new IpcServerTransport() : new StdioServerTransport();
|
|
661
|
+
const transport = new StdioRevisionRouter(stdioTransport, { scope, principal: sessionId });
|
|
658
662
|
startupCleanups.push(() => transport.close());
|
|
659
663
|
await mcpServer.connect(transport);
|
|
660
664
|
startupSucceeded = true;
|
package/browser/index.cjs
CHANGED
|
@@ -1592,7 +1592,8 @@ var init_server_tokens = __esm({
|
|
|
1592
1592
|
webCtx: tokenFactory.meta("webCtx"),
|
|
1593
1593
|
webEnv: tokenFactory.meta("webEnv"),
|
|
1594
1594
|
webTransport: tokenFactory.meta("webTransport"),
|
|
1595
|
-
relayedFrom: tokenFactory.meta("relayedFrom")
|
|
1595
|
+
relayedFrom: tokenFactory.meta("relayedFrom"),
|
|
1596
|
+
stdio: tokenFactory.meta("stdio")
|
|
1596
1597
|
};
|
|
1597
1598
|
}
|
|
1598
1599
|
});
|
|
@@ -3568,6 +3569,8 @@ var init_schema7 = __esm({
|
|
|
3568
3569
|
* friends), where statelessness is the natural fit and sessions cost a
|
|
3569
3570
|
* Durable Object; and to `'legacy'` everywhere else, so existing Node
|
|
3570
3571
|
* deployments are untouched.
|
|
3572
|
+
*
|
|
3573
|
+
* Over stdio (`'legacy'` by default) it applies until the connection sends `initialize`.
|
|
3571
3574
|
*/
|
|
3572
3575
|
defaultProtocolVersion: import_lazy_zod20.z.enum(["2026-07-28", "legacy"]).optional(),
|
|
3573
3576
|
// ============================================
|
|
@@ -19060,7 +19063,8 @@ function createSubscriptionStream(options) {
|
|
|
19060
19063
|
}
|
|
19061
19064
|
notify?.();
|
|
19062
19065
|
};
|
|
19063
|
-
signal?.
|
|
19066
|
+
if (signal?.aborted) cleanup();
|
|
19067
|
+
else signal?.addEventListener("abort", cleanup, { once: true });
|
|
19064
19068
|
async function* generate() {
|
|
19065
19069
|
try {
|
|
19066
19070
|
yield frame({
|
|
@@ -19257,7 +19261,7 @@ function shouldCreateTask(params) {
|
|
|
19257
19261
|
}
|
|
19258
19262
|
return { kind: "skip" };
|
|
19259
19263
|
}
|
|
19260
|
-
const ownership = resolveTaskOwner(
|
|
19264
|
+
const ownership = resolveTaskOwner(params.taskPrincipal);
|
|
19261
19265
|
if (!ownership.ok) return { kind: "refuse", reason: ownership.reason };
|
|
19262
19266
|
return { kind: "create", owner: ownership.owner };
|
|
19263
19267
|
}
|
|
@@ -19325,12 +19329,14 @@ async function dispatch20260728(options) {
|
|
|
19325
19329
|
frontmcpContext,
|
|
19326
19330
|
authInfo,
|
|
19327
19331
|
isAnonymous,
|
|
19332
|
+
transportPrincipal,
|
|
19328
19333
|
signal,
|
|
19329
19334
|
composeInstructions,
|
|
19330
19335
|
notificationSink,
|
|
19331
19336
|
traceContext
|
|
19332
19337
|
} = options;
|
|
19333
19338
|
const method = body["method"];
|
|
19339
|
+
const taskPrincipal = transportPrincipal ?? resolveTaskPrincipal(authInfo, isAnonymous);
|
|
19334
19340
|
const params = body["params"] ?? {};
|
|
19335
19341
|
const cacheScope = resolveCacheScope(isAnonymous, isShapedPerCaller(scope, method));
|
|
19336
19342
|
const serverInfo = scope.metadata.info;
|
|
@@ -19354,7 +19360,7 @@ async function dispatch20260728(options) {
|
|
|
19354
19360
|
}
|
|
19355
19361
|
};
|
|
19356
19362
|
}
|
|
19357
|
-
const ownership = resolveTaskOwner(
|
|
19363
|
+
const ownership = resolveTaskOwner(taskPrincipal);
|
|
19358
19364
|
if (!ownership.ok) {
|
|
19359
19365
|
return { kind: "error", status: 200, error: { code: -32602, message: ownership.reason } };
|
|
19360
19366
|
}
|
|
@@ -19407,7 +19413,7 @@ async function dispatch20260728(options) {
|
|
|
19407
19413
|
});
|
|
19408
19414
|
frontmcpContext?.setMrtrExchange(exchange);
|
|
19409
19415
|
if (notificationSink) frontmcpContext?.setRequestNotificationSink(notificationSink);
|
|
19410
|
-
const taskDecision = shouldCreateTask({ scope, method, params, clientCapabilities,
|
|
19416
|
+
const taskDecision = shouldCreateTask({ scope, method, params, clientCapabilities, taskPrincipal });
|
|
19411
19417
|
if (taskDecision.kind === "refuse") {
|
|
19412
19418
|
return { kind: "error", status: 200, error: { code: -32602, message: taskDecision.reason } };
|
|
19413
19419
|
}
|
|
@@ -45995,7 +46001,7 @@ var init_handle_mcp_20260728_flow = __esm({
|
|
|
45995
46001
|
}
|
|
45996
46002
|
const body = request.body ?? {};
|
|
45997
46003
|
const scope = this.scope;
|
|
45998
|
-
const
|
|
46004
|
+
const clientDeclaredRevision = declaresProtocol20260728({
|
|
45999
46005
|
headers: request.headers,
|
|
46000
46006
|
body
|
|
46001
46007
|
});
|
|
@@ -46003,7 +46009,7 @@ var init_handle_mcp_20260728_flow = __esm({
|
|
|
46003
46009
|
headers: request.headers,
|
|
46004
46010
|
body,
|
|
46005
46011
|
lookupToolSchema: (toolName) => this.findToolSchema(scope, toolName),
|
|
46006
|
-
strictHeaders
|
|
46012
|
+
strictHeaders: clientDeclaredRevision && !this.stdioOrigin
|
|
46007
46013
|
});
|
|
46008
46014
|
if (!result.ok) {
|
|
46009
46015
|
this.log.info("validate: rejected", { code: result.error.code, message: result.error.message });
|
|
@@ -46011,7 +46017,11 @@ var init_handle_mcp_20260728_flow = __esm({
|
|
|
46011
46017
|
return;
|
|
46012
46018
|
}
|
|
46013
46019
|
this.state.set("version", result.version);
|
|
46014
|
-
this.state.set("clientDeclaredRevision",
|
|
46020
|
+
this.state.set("clientDeclaredRevision", clientDeclaredRevision);
|
|
46021
|
+
}
|
|
46022
|
+
/** Set when the request arrived over stdio rather than HTTP. */
|
|
46023
|
+
get stdioOrigin() {
|
|
46024
|
+
return this.rawInput.request[ServerRequestTokens.stdio];
|
|
46015
46025
|
}
|
|
46016
46026
|
/**
|
|
46017
46027
|
* Re-enter this request's `FrontMcpContext` for work deferred past the flow.
|
|
@@ -46070,6 +46080,9 @@ var init_handle_mcp_20260728_flow = __esm({
|
|
|
46070
46080
|
const controller = new AbortController();
|
|
46071
46081
|
const abort = () => controller.abort();
|
|
46072
46082
|
response?.on?.("close", abort);
|
|
46083
|
+
const stdioSignal = this.stdioOrigin?.signal;
|
|
46084
|
+
if (stdioSignal?.aborted) abort();
|
|
46085
|
+
else stdioSignal?.addEventListener("abort", abort, { once: true });
|
|
46073
46086
|
const { acknowledged, stream } = createSubscriptionStream({
|
|
46074
46087
|
scope: this.scope,
|
|
46075
46088
|
subscriptionId: subscriptionId.data,
|
|
@@ -46112,6 +46125,7 @@ var init_handle_mcp_20260728_flow = __esm({
|
|
|
46112
46125
|
const params = body["params"] ?? {};
|
|
46113
46126
|
const meta = params["_meta"] ?? {};
|
|
46114
46127
|
const auth = request[ServerRequestTokens.auth];
|
|
46128
|
+
const stdio = this.stdioOrigin;
|
|
46115
46129
|
const clientCapabilities = meta[import_protocol50.MCP_20260728_META.clientCapabilities] ?? {};
|
|
46116
46130
|
const logLevel = typeof meta[import_protocol50.MCP_20260728_META.logLevel] === "string" ? meta[import_protocol50.MCP_20260728_META.logLevel] : void 0;
|
|
46117
46131
|
const rawProgressToken = meta["progressToken"];
|
|
@@ -46140,15 +46154,21 @@ var init_handle_mcp_20260728_flow = __esm({
|
|
|
46140
46154
|
// off an id. It names the request only, the same per-request id as the request
|
|
46141
46155
|
// context's `sessionId`; the request context does not vouch for it (#629).
|
|
46142
46156
|
sessionId: auth.session?.id ?? this.tryGetContext()?.sessionId
|
|
46143
|
-
} :
|
|
46157
|
+
} : (
|
|
46158
|
+
// A stdio caller presents no credential, so the handlers get only the per-request id.
|
|
46159
|
+
stdio && { sessionId: this.tryGetContext()?.sessionId }
|
|
46160
|
+
),
|
|
46144
46161
|
isAnonymous: this.state.required.isAnonymous,
|
|
46162
|
+
transportPrincipal: stdio?.principal,
|
|
46163
|
+
signal: stdio?.signal,
|
|
46145
46164
|
clientDeclaredRevision: this.state.clientDeclaredRevision !== false,
|
|
46146
46165
|
// The instructions `initialize` sends: the server's, the channel hint and the skill catalog, for this caller
|
|
46147
46166
|
composeInstructions: (caller) => composeCallerInstructions(this.scope, { ctx: caller, skillUriHints: true }),
|
|
46148
46167
|
notificationSink: sink,
|
|
46149
46168
|
traceContext: extractTraceContext(meta)
|
|
46150
46169
|
};
|
|
46151
|
-
|
|
46170
|
+
const streams = stdio !== void 0 || acceptsEventStream(request.headers);
|
|
46171
|
+
if (sink.active && streams) {
|
|
46152
46172
|
this.respond({
|
|
46153
46173
|
kind: "sse",
|
|
46154
46174
|
status: 200,
|
|
@@ -72007,6 +72027,156 @@ var init_ipc_server_transport = __esm({
|
|
|
72007
72027
|
}
|
|
72008
72028
|
});
|
|
72009
72029
|
|
|
72030
|
+
// libs/sdk/src/transport/stdio-revision-router.ts
|
|
72031
|
+
var stdio_revision_router_exports = {};
|
|
72032
|
+
__export(stdio_revision_router_exports, {
|
|
72033
|
+
StdioRevisionRouter: () => StdioRevisionRouter
|
|
72034
|
+
});
|
|
72035
|
+
function eventData(event) {
|
|
72036
|
+
return event.split("\n").filter((line) => line.startsWith(EVENT_DATA_FIELD)).map((line) => line.slice(EVENT_DATA_FIELD.length).trimStart()).join("\n");
|
|
72037
|
+
}
|
|
72038
|
+
async function* eventStreamMessages(stream) {
|
|
72039
|
+
const decoder2 = new TextDecoder();
|
|
72040
|
+
let pending = "";
|
|
72041
|
+
for await (const chunk of stream) {
|
|
72042
|
+
pending += decoder2.decode(chunk, { stream: true });
|
|
72043
|
+
let boundary = pending.indexOf(EVENT_SEPARATOR);
|
|
72044
|
+
while (boundary !== -1) {
|
|
72045
|
+
const data = eventData(pending.slice(0, boundary));
|
|
72046
|
+
pending = pending.slice(boundary + EVENT_SEPARATOR.length);
|
|
72047
|
+
if (data) yield JSON.parse(data);
|
|
72048
|
+
boundary = pending.indexOf(EVENT_SEPARATOR);
|
|
72049
|
+
}
|
|
72050
|
+
}
|
|
72051
|
+
}
|
|
72052
|
+
function isAsyncIterable(stream) {
|
|
72053
|
+
return Symbol.asyncIterator in stream;
|
|
72054
|
+
}
|
|
72055
|
+
function internalError(id) {
|
|
72056
|
+
return { jsonrpc: "2.0", id, error: { code: -32603, message: "Internal error" } };
|
|
72057
|
+
}
|
|
72058
|
+
var import_protocol59, EVENT_SEPARATOR, EVENT_DATA_FIELD, StdioRevisionRouter;
|
|
72059
|
+
var init_stdio_revision_router = __esm({
|
|
72060
|
+
"libs/sdk/src/transport/stdio-revision-router.ts"() {
|
|
72061
|
+
"use strict";
|
|
72062
|
+
import_protocol59 = require("@frontmcp/protocol");
|
|
72063
|
+
init_common();
|
|
72064
|
+
init_flow_error_output();
|
|
72065
|
+
init_mcp_20260728();
|
|
72066
|
+
EVENT_SEPARATOR = "\n\n";
|
|
72067
|
+
EVENT_DATA_FIELD = "data:";
|
|
72068
|
+
StdioRevisionRouter = class {
|
|
72069
|
+
constructor(inner, options) {
|
|
72070
|
+
this.inner = inner;
|
|
72071
|
+
this.options = options;
|
|
72072
|
+
}
|
|
72073
|
+
inner;
|
|
72074
|
+
options;
|
|
72075
|
+
onclose;
|
|
72076
|
+
onerror;
|
|
72077
|
+
onmessage;
|
|
72078
|
+
inFlight = /* @__PURE__ */ new Map();
|
|
72079
|
+
/** `initialize` makes the connection session-era for good; a 2026-07-28 message first makes it stateless. */
|
|
72080
|
+
era = "unknown";
|
|
72081
|
+
async start() {
|
|
72082
|
+
this.inner.onmessage = (message, extra) => this.route(message, extra);
|
|
72083
|
+
this.inner.onerror = (error) => this.onerror?.(error);
|
|
72084
|
+
this.inner.onclose = () => {
|
|
72085
|
+
this.cancelAll();
|
|
72086
|
+
this.onclose?.();
|
|
72087
|
+
};
|
|
72088
|
+
await this.inner.start();
|
|
72089
|
+
}
|
|
72090
|
+
async send(message, options) {
|
|
72091
|
+
if (this.era === "modern" && (0, import_protocol59.isJSONRPCNotification)(message)) return;
|
|
72092
|
+
await this.inner.send(message, options);
|
|
72093
|
+
}
|
|
72094
|
+
async close() {
|
|
72095
|
+
this.cancelAll();
|
|
72096
|
+
await this.inner.close();
|
|
72097
|
+
}
|
|
72098
|
+
route(message, extra) {
|
|
72099
|
+
if (this.cancelsModernRequest(message)) return;
|
|
72100
|
+
if (((0, import_protocol59.isJSONRPCRequest)(message) || (0, import_protocol59.isJSONRPCNotification)(message)) && this.servesModern(message)) {
|
|
72101
|
+
if (this.era === "unknown") this.era = "modern";
|
|
72102
|
+
void this.serveModern(message);
|
|
72103
|
+
return;
|
|
72104
|
+
}
|
|
72105
|
+
if ((0, import_protocol59.isJSONRPCRequest)(message) && message.method === "initialize") this.era = "legacy";
|
|
72106
|
+
this.onmessage?.(message, extra);
|
|
72107
|
+
}
|
|
72108
|
+
servesModern(message) {
|
|
72109
|
+
const configured = this.options.scope.metadata.transport?.defaultProtocolVersion ?? "legacy";
|
|
72110
|
+
return isProtocol20260728Request({
|
|
72111
|
+
headers: void 0,
|
|
72112
|
+
body: message,
|
|
72113
|
+
defaultVersion: this.era === "legacy" ? "legacy" : configured
|
|
72114
|
+
});
|
|
72115
|
+
}
|
|
72116
|
+
cancelsModernRequest(message) {
|
|
72117
|
+
if (!(0, import_protocol59.isJSONRPCNotification)(message) || message.method !== "notifications/cancelled") return false;
|
|
72118
|
+
const requestId = message.params?.["requestId"];
|
|
72119
|
+
if (typeof requestId !== "string" && typeof requestId !== "number") return false;
|
|
72120
|
+
const controller = this.inFlight.get(requestId);
|
|
72121
|
+
if (!controller) return false;
|
|
72122
|
+
this.inFlight.delete(requestId);
|
|
72123
|
+
controller.abort();
|
|
72124
|
+
return true;
|
|
72125
|
+
}
|
|
72126
|
+
async serveModern(message) {
|
|
72127
|
+
const id = (0, import_protocol59.isJSONRPCRequest)(message) ? message.id : void 0;
|
|
72128
|
+
const controller = new AbortController();
|
|
72129
|
+
if (id !== void 0) this.inFlight.set(id, controller);
|
|
72130
|
+
try {
|
|
72131
|
+
const output = await this.runFlow(message, controller.signal);
|
|
72132
|
+
if (id !== void 0) await this.reply(output, id, controller.signal);
|
|
72133
|
+
} catch (error) {
|
|
72134
|
+
this.options.scope.logger.child("StdioRevisionRouter").error("failed to serve a 2026-07-28 message", {
|
|
72135
|
+
method: message.method,
|
|
72136
|
+
error: error instanceof Error ? error.message : String(error)
|
|
72137
|
+
});
|
|
72138
|
+
} finally {
|
|
72139
|
+
if (id !== void 0 && this.inFlight.get(id) === controller) this.inFlight.delete(id);
|
|
72140
|
+
}
|
|
72141
|
+
}
|
|
72142
|
+
async runFlow(message, signal) {
|
|
72143
|
+
const origin = { principal: this.options.principal, signal };
|
|
72144
|
+
const request = {
|
|
72145
|
+
method: "POST",
|
|
72146
|
+
path: "/",
|
|
72147
|
+
url: "/",
|
|
72148
|
+
headers: {},
|
|
72149
|
+
query: {},
|
|
72150
|
+
body: message,
|
|
72151
|
+
[ServerRequestTokens.stdio]: origin
|
|
72152
|
+
};
|
|
72153
|
+
try {
|
|
72154
|
+
return await this.options.scope.runFlow("handle:mcp-202607280728", { request, response: {} });
|
|
72155
|
+
} catch (error) {
|
|
72156
|
+
return flowErrorToHttpOutput(error);
|
|
72157
|
+
}
|
|
72158
|
+
}
|
|
72159
|
+
async reply(output, id, signal) {
|
|
72160
|
+
if (output?.kind === "sse" && isAsyncIterable(output.stream)) {
|
|
72161
|
+
for await (const message of eventStreamMessages(output.stream)) {
|
|
72162
|
+
if (signal.aborted) return;
|
|
72163
|
+
await this.inner.send(message);
|
|
72164
|
+
}
|
|
72165
|
+
return;
|
|
72166
|
+
}
|
|
72167
|
+
if (signal.aborted) return;
|
|
72168
|
+
const body = output?.kind === "json" ? output.body : void 0;
|
|
72169
|
+
const isReply = (0, import_protocol59.isJSONRPCResultResponse)(body) || (0, import_protocol59.isJSONRPCErrorResponse)(body);
|
|
72170
|
+
await this.inner.send(isReply ? body : internalError(id));
|
|
72171
|
+
}
|
|
72172
|
+
cancelAll() {
|
|
72173
|
+
for (const controller of this.inFlight.values()) controller.abort();
|
|
72174
|
+
this.inFlight.clear();
|
|
72175
|
+
}
|
|
72176
|
+
};
|
|
72177
|
+
}
|
|
72178
|
+
});
|
|
72179
|
+
|
|
72010
72180
|
// libs/sdk/src/front-mcp/front-mcp.ts
|
|
72011
72181
|
var front_mcp_exports = {};
|
|
72012
72182
|
__export(front_mcp_exports, {
|
|
@@ -72519,6 +72689,8 @@ var init_front_mcp = __esm({
|
|
|
72519
72689
|
* transport and returns only when the connection closes. **No TCP port is
|
|
72520
72690
|
* bound** — the HTTP server is disabled for this entry point (#451).
|
|
72521
72691
|
*
|
|
72692
|
+
* One connection serves every revision: `initialize` opens a session, a 2026-07-28 request is served statelessly.
|
|
72693
|
+
*
|
|
72522
72694
|
* Accepts either a `@FrontMcp`-decorated class or the same config object you
|
|
72523
72695
|
* pass to `@FrontMcp()` (#450).
|
|
72524
72696
|
*
|
|
@@ -72655,7 +72827,9 @@ var init_front_mcp = __esm({
|
|
|
72655
72827
|
mcpServer.setRequestHandler(handler.requestSchema, wrappedHandler);
|
|
72656
72828
|
}
|
|
72657
72829
|
const { IpcServerTransport: IpcServerTransport2, isIpcStdioRequested: isIpcStdioRequested2 } = await Promise.resolve().then(() => (init_ipc_server_transport(), ipc_server_transport_exports));
|
|
72658
|
-
const
|
|
72830
|
+
const { StdioRevisionRouter: StdioRevisionRouter2 } = await Promise.resolve().then(() => (init_stdio_revision_router(), stdio_revision_router_exports));
|
|
72831
|
+
const stdioTransport = isIpcStdioRequested2() ? new IpcServerTransport2() : new StdioServerTransport();
|
|
72832
|
+
const transport = new StdioRevisionRouter2(stdioTransport, { scope, principal: sessionId });
|
|
72659
72833
|
startupCleanups.push(() => transport.close());
|
|
72660
72834
|
await mcpServer.connect(transport);
|
|
72661
72835
|
startupSucceeded = true;
|
|
@@ -74893,7 +75067,7 @@ __export(index_exports, {
|
|
|
74893
75067
|
OrchestratorJwksNotAvailableError: () => import_auth15.OrchestratorJwksNotAvailableError,
|
|
74894
75068
|
PLATFORM_CLIENT_INFO: () => PLATFORM_CLIENT_INFO,
|
|
74895
75069
|
PRIMITIVE_FILTER_KEYS: () => PRIMITIVE_FILTER_KEYS,
|
|
74896
|
-
PROTOCOL_2026_07_28: () =>
|
|
75070
|
+
PROTOCOL_2026_07_28: () => import_protocol60.PROTOCOL_2026_07_28,
|
|
74897
75071
|
PROTOCOL_PRESETS: () => PROTOCOL_PRESETS,
|
|
74898
75072
|
PayloadTooLargeError: () => PayloadTooLargeError,
|
|
74899
75073
|
Plugin: () => FrontMcpPlugin,
|
|
@@ -76267,7 +76441,7 @@ init_mcp_20260728();
|
|
|
76267
76441
|
init_mcp_20260728();
|
|
76268
76442
|
init_mcp_20260728();
|
|
76269
76443
|
init_mcp_stateless_client_adapter();
|
|
76270
|
-
var
|
|
76444
|
+
var import_protocol60 = require("@frontmcp/protocol");
|
|
76271
76445
|
init_ext_apps2();
|
|
76272
76446
|
var import_auth67 = require("@frontmcp/auth");
|
|
76273
76447
|
var import_auth68 = require("@frontmcp/auth");
|
|
@@ -155,7 +155,7 @@ var HandleMcp20260728Flow = class extends FlowBase {
|
|
|
155
155
|
}
|
|
156
156
|
const body = request.body ?? {};
|
|
157
157
|
const scope = this.scope;
|
|
158
|
-
const
|
|
158
|
+
const clientDeclaredRevision = declaresProtocol20260728({
|
|
159
159
|
headers: request.headers,
|
|
160
160
|
body
|
|
161
161
|
});
|
|
@@ -163,7 +163,7 @@ var HandleMcp20260728Flow = class extends FlowBase {
|
|
|
163
163
|
headers: request.headers,
|
|
164
164
|
body,
|
|
165
165
|
lookupToolSchema: (toolName) => this.findToolSchema(scope, toolName),
|
|
166
|
-
strictHeaders
|
|
166
|
+
strictHeaders: clientDeclaredRevision && !this.stdioOrigin
|
|
167
167
|
});
|
|
168
168
|
if (!result.ok) {
|
|
169
169
|
this.log.info("validate: rejected", { code: result.error.code, message: result.error.message });
|
|
@@ -171,7 +171,11 @@ var HandleMcp20260728Flow = class extends FlowBase {
|
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
173
|
this.state.set("version", result.version);
|
|
174
|
-
this.state.set("clientDeclaredRevision",
|
|
174
|
+
this.state.set("clientDeclaredRevision", clientDeclaredRevision);
|
|
175
|
+
}
|
|
176
|
+
/** Set when the request arrived over stdio rather than HTTP. */
|
|
177
|
+
get stdioOrigin() {
|
|
178
|
+
return this.rawInput.request[ServerRequestTokens.stdio];
|
|
175
179
|
}
|
|
176
180
|
/**
|
|
177
181
|
* Re-enter this request's `FrontMcpContext` for work deferred past the flow.
|
|
@@ -230,6 +234,9 @@ var HandleMcp20260728Flow = class extends FlowBase {
|
|
|
230
234
|
const controller = new AbortController();
|
|
231
235
|
const abort = () => controller.abort();
|
|
232
236
|
response?.on?.("close", abort);
|
|
237
|
+
const stdioSignal = this.stdioOrigin?.signal;
|
|
238
|
+
if (stdioSignal?.aborted) abort();
|
|
239
|
+
else stdioSignal?.addEventListener("abort", abort, { once: true });
|
|
233
240
|
const { acknowledged, stream } = createSubscriptionStream({
|
|
234
241
|
scope: this.scope,
|
|
235
242
|
subscriptionId: subscriptionId.data,
|
|
@@ -272,6 +279,7 @@ var HandleMcp20260728Flow = class extends FlowBase {
|
|
|
272
279
|
const params = body["params"] ?? {};
|
|
273
280
|
const meta = params["_meta"] ?? {};
|
|
274
281
|
const auth = request[ServerRequestTokens.auth];
|
|
282
|
+
const stdio = this.stdioOrigin;
|
|
275
283
|
const clientCapabilities = meta[MCP_20260728_META.clientCapabilities] ?? {};
|
|
276
284
|
const logLevel = typeof meta[MCP_20260728_META.logLevel] === "string" ? meta[MCP_20260728_META.logLevel] : void 0;
|
|
277
285
|
const rawProgressToken = meta["progressToken"];
|
|
@@ -300,15 +308,21 @@ var HandleMcp20260728Flow = class extends FlowBase {
|
|
|
300
308
|
// off an id. It names the request only, the same per-request id as the request
|
|
301
309
|
// context's `sessionId`; the request context does not vouch for it (#629).
|
|
302
310
|
sessionId: auth.session?.id ?? this.tryGetContext()?.sessionId
|
|
303
|
-
} :
|
|
311
|
+
} : (
|
|
312
|
+
// A stdio caller presents no credential, so the handlers get only the per-request id.
|
|
313
|
+
stdio && { sessionId: this.tryGetContext()?.sessionId }
|
|
314
|
+
),
|
|
304
315
|
isAnonymous: this.state.required.isAnonymous,
|
|
316
|
+
transportPrincipal: stdio?.principal,
|
|
317
|
+
signal: stdio?.signal,
|
|
305
318
|
clientDeclaredRevision: this.state.clientDeclaredRevision !== false,
|
|
306
319
|
// The instructions `initialize` sends: the server's, the channel hint and the skill catalog, for this caller
|
|
307
320
|
composeInstructions: (caller) => composeCallerInstructions(this.scope, { ctx: caller, skillUriHints: true }),
|
|
308
321
|
notificationSink: sink,
|
|
309
322
|
traceContext: extractTraceContext(meta)
|
|
310
323
|
};
|
|
311
|
-
|
|
324
|
+
const streams = stdio !== void 0 || acceptsEventStream(request.headers);
|
|
325
|
+
if (sink.active && streams) {
|
|
312
326
|
this.respond({
|
|
313
327
|
kind: "sse",
|
|
314
328
|
status: 200,
|
|
@@ -56,7 +56,7 @@ function shouldCreateTask(params) {
|
|
|
56
56
|
}
|
|
57
57
|
return { kind: "skip" };
|
|
58
58
|
}
|
|
59
|
-
const ownership = resolveTaskOwner(
|
|
59
|
+
const ownership = resolveTaskOwner(params.taskPrincipal);
|
|
60
60
|
if (!ownership.ok) return { kind: "refuse", reason: ownership.reason };
|
|
61
61
|
return { kind: "create", owner: ownership.owner };
|
|
62
62
|
}
|
|
@@ -124,12 +124,14 @@ async function dispatch20260728(options) {
|
|
|
124
124
|
frontmcpContext,
|
|
125
125
|
authInfo,
|
|
126
126
|
isAnonymous,
|
|
127
|
+
transportPrincipal,
|
|
127
128
|
signal,
|
|
128
129
|
composeInstructions,
|
|
129
130
|
notificationSink,
|
|
130
131
|
traceContext
|
|
131
132
|
} = options;
|
|
132
133
|
const method = body["method"];
|
|
134
|
+
const taskPrincipal = transportPrincipal ?? resolveTaskPrincipal(authInfo, isAnonymous);
|
|
133
135
|
const params = body["params"] ?? {};
|
|
134
136
|
const cacheScope = resolveCacheScope(isAnonymous, isShapedPerCaller(scope, method));
|
|
135
137
|
const serverInfo = scope.metadata.info;
|
|
@@ -153,7 +155,7 @@ async function dispatch20260728(options) {
|
|
|
153
155
|
}
|
|
154
156
|
};
|
|
155
157
|
}
|
|
156
|
-
const ownership = resolveTaskOwner(
|
|
158
|
+
const ownership = resolveTaskOwner(taskPrincipal);
|
|
157
159
|
if (!ownership.ok) {
|
|
158
160
|
return { kind: "error", status: 200, error: { code: -32602, message: ownership.reason } };
|
|
159
161
|
}
|
|
@@ -206,7 +208,7 @@ async function dispatch20260728(options) {
|
|
|
206
208
|
});
|
|
207
209
|
frontmcpContext?.setMrtrExchange(exchange);
|
|
208
210
|
if (notificationSink) frontmcpContext?.setRequestNotificationSink(notificationSink);
|
|
209
|
-
const taskDecision = shouldCreateTask({ scope, method, params, clientCapabilities,
|
|
211
|
+
const taskDecision = shouldCreateTask({ scope, method, params, clientCapabilities, taskPrincipal });
|
|
210
212
|
if (taskDecision.kind === "refuse") {
|
|
211
213
|
return { kind: "error", status: 200, error: { code: -32602, message: taskDecision.reason } };
|
|
212
214
|
}
|
|
@@ -81,7 +81,8 @@ function createSubscriptionStream(options) {
|
|
|
81
81
|
}
|
|
82
82
|
notify?.();
|
|
83
83
|
};
|
|
84
|
-
signal?.
|
|
84
|
+
if (signal?.aborted) cleanup();
|
|
85
|
+
else signal?.addEventListener("abort", cleanup, { once: true });
|
|
85
86
|
async function* generate() {
|
|
86
87
|
try {
|
|
87
88
|
yield frame({
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// libs/sdk/src/transport/stdio-revision-router.ts
|
|
2
|
+
import {
|
|
3
|
+
isJSONRPCErrorResponse,
|
|
4
|
+
isJSONRPCNotification,
|
|
5
|
+
isJSONRPCRequest,
|
|
6
|
+
isJSONRPCResultResponse
|
|
7
|
+
} from "@frontmcp/protocol";
|
|
8
|
+
import { ServerRequestTokens } from "../common/index.mjs";
|
|
9
|
+
import { flowErrorToHttpOutput } from "./flow-error-output.mjs";
|
|
10
|
+
import { isProtocol20260728Request } from "./mcp-20260728/index.mjs";
|
|
11
|
+
var EVENT_SEPARATOR = "\n\n";
|
|
12
|
+
var EVENT_DATA_FIELD = "data:";
|
|
13
|
+
function eventData(event) {
|
|
14
|
+
return event.split("\n").filter((line) => line.startsWith(EVENT_DATA_FIELD)).map((line) => line.slice(EVENT_DATA_FIELD.length).trimStart()).join("\n");
|
|
15
|
+
}
|
|
16
|
+
async function* eventStreamMessages(stream) {
|
|
17
|
+
const decoder = new TextDecoder();
|
|
18
|
+
let pending = "";
|
|
19
|
+
for await (const chunk of stream) {
|
|
20
|
+
pending += decoder.decode(chunk, { stream: true });
|
|
21
|
+
let boundary = pending.indexOf(EVENT_SEPARATOR);
|
|
22
|
+
while (boundary !== -1) {
|
|
23
|
+
const data = eventData(pending.slice(0, boundary));
|
|
24
|
+
pending = pending.slice(boundary + EVENT_SEPARATOR.length);
|
|
25
|
+
if (data) yield JSON.parse(data);
|
|
26
|
+
boundary = pending.indexOf(EVENT_SEPARATOR);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function isAsyncIterable(stream) {
|
|
31
|
+
return Symbol.asyncIterator in stream;
|
|
32
|
+
}
|
|
33
|
+
function internalError(id) {
|
|
34
|
+
return { jsonrpc: "2.0", id, error: { code: -32603, message: "Internal error" } };
|
|
35
|
+
}
|
|
36
|
+
var StdioRevisionRouter = class {
|
|
37
|
+
constructor(inner, options) {
|
|
38
|
+
this.inner = inner;
|
|
39
|
+
this.options = options;
|
|
40
|
+
}
|
|
41
|
+
inner;
|
|
42
|
+
options;
|
|
43
|
+
onclose;
|
|
44
|
+
onerror;
|
|
45
|
+
onmessage;
|
|
46
|
+
inFlight = /* @__PURE__ */ new Map();
|
|
47
|
+
/** `initialize` makes the connection session-era for good; a 2026-07-28 message first makes it stateless. */
|
|
48
|
+
era = "unknown";
|
|
49
|
+
async start() {
|
|
50
|
+
this.inner.onmessage = (message, extra) => this.route(message, extra);
|
|
51
|
+
this.inner.onerror = (error) => this.onerror?.(error);
|
|
52
|
+
this.inner.onclose = () => {
|
|
53
|
+
this.cancelAll();
|
|
54
|
+
this.onclose?.();
|
|
55
|
+
};
|
|
56
|
+
await this.inner.start();
|
|
57
|
+
}
|
|
58
|
+
async send(message, options) {
|
|
59
|
+
if (this.era === "modern" && isJSONRPCNotification(message)) return;
|
|
60
|
+
await this.inner.send(message, options);
|
|
61
|
+
}
|
|
62
|
+
async close() {
|
|
63
|
+
this.cancelAll();
|
|
64
|
+
await this.inner.close();
|
|
65
|
+
}
|
|
66
|
+
route(message, extra) {
|
|
67
|
+
if (this.cancelsModernRequest(message)) return;
|
|
68
|
+
if ((isJSONRPCRequest(message) || isJSONRPCNotification(message)) && this.servesModern(message)) {
|
|
69
|
+
if (this.era === "unknown") this.era = "modern";
|
|
70
|
+
void this.serveModern(message);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (isJSONRPCRequest(message) && message.method === "initialize") this.era = "legacy";
|
|
74
|
+
this.onmessage?.(message, extra);
|
|
75
|
+
}
|
|
76
|
+
servesModern(message) {
|
|
77
|
+
const configured = this.options.scope.metadata.transport?.defaultProtocolVersion ?? "legacy";
|
|
78
|
+
return isProtocol20260728Request({
|
|
79
|
+
headers: void 0,
|
|
80
|
+
body: message,
|
|
81
|
+
defaultVersion: this.era === "legacy" ? "legacy" : configured
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
cancelsModernRequest(message) {
|
|
85
|
+
if (!isJSONRPCNotification(message) || message.method !== "notifications/cancelled") return false;
|
|
86
|
+
const requestId = message.params?.["requestId"];
|
|
87
|
+
if (typeof requestId !== "string" && typeof requestId !== "number") return false;
|
|
88
|
+
const controller = this.inFlight.get(requestId);
|
|
89
|
+
if (!controller) return false;
|
|
90
|
+
this.inFlight.delete(requestId);
|
|
91
|
+
controller.abort();
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
async serveModern(message) {
|
|
95
|
+
const id = isJSONRPCRequest(message) ? message.id : void 0;
|
|
96
|
+
const controller = new AbortController();
|
|
97
|
+
if (id !== void 0) this.inFlight.set(id, controller);
|
|
98
|
+
try {
|
|
99
|
+
const output = await this.runFlow(message, controller.signal);
|
|
100
|
+
if (id !== void 0) await this.reply(output, id, controller.signal);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
this.options.scope.logger.child("StdioRevisionRouter").error("failed to serve a 2026-07-28 message", {
|
|
103
|
+
method: message.method,
|
|
104
|
+
error: error instanceof Error ? error.message : String(error)
|
|
105
|
+
});
|
|
106
|
+
} finally {
|
|
107
|
+
if (id !== void 0 && this.inFlight.get(id) === controller) this.inFlight.delete(id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async runFlow(message, signal) {
|
|
111
|
+
const origin = { principal: this.options.principal, signal };
|
|
112
|
+
const request = {
|
|
113
|
+
method: "POST",
|
|
114
|
+
path: "/",
|
|
115
|
+
url: "/",
|
|
116
|
+
headers: {},
|
|
117
|
+
query: {},
|
|
118
|
+
body: message,
|
|
119
|
+
[ServerRequestTokens.stdio]: origin
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
return await this.options.scope.runFlow("handle:mcp-202607280728", { request, response: {} });
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return flowErrorToHttpOutput(error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async reply(output, id, signal) {
|
|
128
|
+
if (output?.kind === "sse" && isAsyncIterable(output.stream)) {
|
|
129
|
+
for await (const message of eventStreamMessages(output.stream)) {
|
|
130
|
+
if (signal.aborted) return;
|
|
131
|
+
await this.inner.send(message);
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (signal.aborted) return;
|
|
136
|
+
const body = output?.kind === "json" ? output.body : void 0;
|
|
137
|
+
const isReply = isJSONRPCResultResponse(body) || isJSONRPCErrorResponse(body);
|
|
138
|
+
await this.inner.send(isReply ? body : internalError(id));
|
|
139
|
+
}
|
|
140
|
+
cancelAll() {
|
|
141
|
+
for (const controller of this.inFlight.values()) controller.abort();
|
|
142
|
+
this.inFlight.clear();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
export {
|
|
146
|
+
StdioRevisionRouter
|
|
147
|
+
};
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/** Where a request that arrived over stdio (or the dev bridge's IPC channel) came from. */
|
|
2
|
+
export interface StdioRequestOrigin {
|
|
3
|
+
/** Names the connection: only the process that spawned the server can reach it, so it identifies the caller. */
|
|
4
|
+
principal: string;
|
|
5
|
+
/** Aborts when the client cancels the request with `notifications/cancelled`, or the connection closes. */
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
}
|
|
1
8
|
export declare const ServerRequestTokens: {
|
|
2
9
|
type: symbol;
|
|
3
10
|
intent: symbol;
|
|
@@ -9,5 +16,6 @@ export declare const ServerRequestTokens: {
|
|
|
9
16
|
webEnv: symbol;
|
|
10
17
|
webTransport: symbol;
|
|
11
18
|
relayedFrom: symbol;
|
|
19
|
+
stdio: symbol;
|
|
12
20
|
};
|
|
13
21
|
//# sourceMappingURL=server.tokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.tokens.d.ts","sourceRoot":"","sources":["../../../src/common/tokens/server.tokens.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.tokens.d.ts","sourceRoot":"","sources":["../../../src/common/tokens/server.tokens.ts"],"names":[],"mappings":"AAIA,2FAA2F;AAC3F,MAAM,WAAW,kBAAkB;IACjC,gHAAgH;IAChH,SAAS,EAAE,MAAM,CAAC;IAClB,2GAA2G;IAC3G,MAAM,EAAE,WAAW,CAAC;CACrB;AAuDD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;CAYqB,CAAC"}
|