fix(browser): distinguish WebMCP registration frame owners (#813)
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
+45
@@ -22,6 +22,13 @@ const emitWebMcpEvents = (
|
||||
port: number,
|
||||
options: FakeOptions,
|
||||
): void => {
|
||||
if (
|
||||
command.method === "WebMCP.enable" &&
|
||||
options.webMcpSameUrlRegistrations !== undefined
|
||||
) {
|
||||
emitSameUrlWebMcpRegistrations(socket, command, options);
|
||||
return;
|
||||
}
|
||||
if (command.method === "WebMCP.enable" && options.webMcpTools === true) {
|
||||
const inputSchemaProperties =
|
||||
options.webMcpSchemaPropertyCount === undefined
|
||||
@@ -160,6 +167,44 @@ const emitWebMcpEvents = (
|
||||
}
|
||||
};
|
||||
|
||||
const emitSameUrlWebMcpRegistrations = (
|
||||
socket: WebSocket,
|
||||
command: FakeCdpCommand,
|
||||
options: FakeOptions,
|
||||
): void => {
|
||||
event(socket, "WebMCP.toolsAdded", command.sessionId, {
|
||||
tools: [
|
||||
{
|
||||
name: "read_item",
|
||||
description: "First owner",
|
||||
frameId: "webmcp-frame-0",
|
||||
},
|
||||
],
|
||||
});
|
||||
event(socket, "WebMCP.toolsAdded", command.sessionId, {
|
||||
tools: [
|
||||
{
|
||||
name: "read_item",
|
||||
description: "First owner updated",
|
||||
frameId: "webmcp-frame-0",
|
||||
},
|
||||
],
|
||||
});
|
||||
event(socket, "WebMCP.toolsAdded", command.sessionId, {
|
||||
tools: [
|
||||
{
|
||||
name: "read_item",
|
||||
description: "Second owner",
|
||||
frameId: "webmcp-frame-1",
|
||||
},
|
||||
],
|
||||
});
|
||||
if (options.webMcpSameUrlRegistrations === "remove-second")
|
||||
event(socket, "WebMCP.toolsRemoved", command.sessionId, {
|
||||
tools: [{ name: "read_item", frameId: "webmcp-frame-1" }],
|
||||
});
|
||||
};
|
||||
|
||||
const emitSessionTimeline = (
|
||||
socket: WebSocket,
|
||||
command: FakeCdpCommand,
|
||||
|
||||
+15
-10
@@ -66,7 +66,9 @@ const frameTreeResult = (
|
||||
? ":"
|
||||
: (options.electronFileUrl ?? options.attachedFrameUrl),
|
||||
options.extraCollections === true,
|
||||
options.webMcpFrameCount,
|
||||
options.webMcpSameUrlRegistrations === undefined
|
||||
? options.webMcpFrameCount
|
||||
: "same-url",
|
||||
);
|
||||
|
||||
const resourceTreeResult = (port: number, options: FakeOptions) =>
|
||||
@@ -236,7 +238,7 @@ const frameTree = (
|
||||
port: number,
|
||||
overrideUrl?: string,
|
||||
extraCollections = false,
|
||||
webMcpFrameCount = 0,
|
||||
webMcpFrameCount: number | "same-url" = 0,
|
||||
): Readonly<Record<string, unknown>> => ({
|
||||
frameTree: {
|
||||
frame: {
|
||||
@@ -259,14 +261,17 @@ const frameTree = (
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...Array.from({ length: webMcpFrameCount }, (_value, index) => ({
|
||||
frame: {
|
||||
id: `webmcp-frame-${String(index)}`,
|
||||
parentId: "frame-main",
|
||||
loaderId: `loader-webmcp-${String(index)}`,
|
||||
url: `http://127.0.0.1:${String(port)}/webmcp-frame/${String(index)}`,
|
||||
},
|
||||
})),
|
||||
...Array.from(
|
||||
{ length: webMcpFrameCount === "same-url" ? 2 : webMcpFrameCount },
|
||||
(_value, index) => ({
|
||||
frame: {
|
||||
id: `webmcp-frame-${String(index)}`,
|
||||
parentId: "frame-main",
|
||||
loaderId: `loader-webmcp-${String(index)}`,
|
||||
url: `http://127.0.0.1:${String(port)}/webmcp-frame/${webMcpFrameCount === "same-url" ? "shared" : String(index)}`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
{
|
||||
frame: {
|
||||
id: "frame-private",
|
||||
|
||||
+1
@@ -62,6 +62,7 @@ export interface FakeOptions {
|
||||
readonly cachedResponseBody?: string;
|
||||
readonly invalidResponseBodyBase64?: boolean;
|
||||
readonly webMcpTools?: boolean;
|
||||
readonly webMcpSameUrlRegistrations?: "retain" | "remove-second";
|
||||
readonly webMcpFrameCount?: number;
|
||||
readonly webMcpSchemaPropertyCount?: number;
|
||||
readonly webMcpChildLeavesScope?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user