fix(browser): retain incomplete WebMCP replay coverage
Mark malformed WebMCP event envelopes, tool lists and entries as invalid protocol values while preserving valid siblings and out-of-scope classifications. Verify toolsAdded and toolsRemoved replay uncertainty through CDP discovery and capture comparison.
This commit is contained in:
@@ -365,20 +365,30 @@ const ingestWebMcpEvent = (options: WebMcpIngestOptions): void => {
|
||||
transientFrames,
|
||||
resolvedTransientFrames,
|
||||
} = options;
|
||||
if (
|
||||
event.method !== "WebMCP.toolsAdded" &&
|
||||
event.method !== "WebMCP.toolsRemoved"
|
||||
)
|
||||
return;
|
||||
const params = recordValue(event.params);
|
||||
if (params === undefined) return;
|
||||
if (params === undefined) {
|
||||
completeness.exclude("webmcp_tools", "invalid_protocol_value");
|
||||
return;
|
||||
}
|
||||
if (event.method === "WebMCP.toolsRemoved") {
|
||||
for (const removed of recordsValue(params.tools)) {
|
||||
for (const removed of webMcpEventTools(params.tools, completeness)) {
|
||||
const name = cdpStringValue(removed.name);
|
||||
const frameId = cdpStringValue(removed.frameId);
|
||||
if (name === undefined || frameId === undefined) continue;
|
||||
if (name === undefined || frameId === undefined) {
|
||||
completeness.exclude("webmcp_tools", "invalid_protocol_value");
|
||||
continue;
|
||||
}
|
||||
for (const [key, tool] of tools)
|
||||
if (tool.name === name && tool.frame_id === frameId) tools.delete(key);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.method !== "WebMCP.toolsAdded") return;
|
||||
for (const declared of recordsValue(params.tools)) {
|
||||
for (const declared of webMcpEventTools(params.tools, completeness)) {
|
||||
const frameId = cdpStringValue(declared.frameId);
|
||||
if (frameId !== undefined && transientFrames.has(frameId)) {
|
||||
if (!resolvedTransientFrames.has(frameId)) continue;
|
||||
@@ -391,6 +401,26 @@ const ingestWebMcpEvent = (options: WebMcpIngestOptions): void => {
|
||||
}
|
||||
};
|
||||
|
||||
const webMcpEventTools = (
|
||||
value: unknown,
|
||||
completeness: CdpCaptureCompleteness,
|
||||
): UnknownRecord[] => {
|
||||
if (!Array.isArray(value)) {
|
||||
completeness.exclude("webmcp_tools", "invalid_protocol_value");
|
||||
return [];
|
||||
}
|
||||
const records: UnknownRecord[] = [];
|
||||
for (const item of value) {
|
||||
const record = recordValue(item);
|
||||
if (record === undefined) {
|
||||
completeness.exclude("webmcp_tools", "invalid_protocol_value");
|
||||
continue;
|
||||
}
|
||||
records.push(record);
|
||||
}
|
||||
return records;
|
||||
};
|
||||
|
||||
const normalizeTool = (
|
||||
value: UnknownRecord,
|
||||
input: DiscoverWebMcpToolsInput,
|
||||
@@ -403,12 +433,11 @@ const normalizeTool = (
|
||||
const frameId = cdpStringValue(value.frameId);
|
||||
const name = cdpStringValue(value.name);
|
||||
const frame = frameId === undefined ? undefined : frames.get(frameId);
|
||||
if (
|
||||
frameId === undefined ||
|
||||
name === undefined ||
|
||||
frame?.origin === null ||
|
||||
frame === undefined
|
||||
) {
|
||||
if (frameId === undefined || name === undefined) {
|
||||
completeness.exclude("webmcp_tools", "invalid_protocol_value");
|
||||
return undefined;
|
||||
}
|
||||
if (frame?.origin === null || frame === undefined) {
|
||||
completeness.exclude("webmcp_tools", "out_of_target_scope");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user