fix(browser)!: preserve payload shapes and WebMCP declarations
Retain primitive and nested array types with typed paths, and compare only mutually observed body shapes while preserving selected coverage uncertainty. Return full untrusted WebMCP input declarations with canonical digests, without resolving references or invoking tools. BREAKING CHANGE: JSON shape paths now contain typed property and array-element segments. WebMCP input_schema_shape is replaced by input_schema and input_schema_sha256, retaining declared examples and defaults.
This commit is contained in:
@@ -5,7 +5,8 @@ import type {
|
||||
DiscoverWebMcpToolsInput,
|
||||
WebMcpDiscovery,
|
||||
} from "../domain/webMcpDiscovery.js";
|
||||
import { inferJsonShape } from "../domain/jsonShape.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { digestCanonicalValue } from "../domain/canonicalDigest.js";
|
||||
import { compositeKey } from "../domain/unicodeCodePointOrder.js";
|
||||
import type { CdpEndpointDiscovery, CdpEndpointTarget } from "./CdpEndpoint.js";
|
||||
import type { CdpConnection, CdpEvent } from "./CdpConnection.js";
|
||||
@@ -413,6 +414,10 @@ const normalizeTool = (
|
||||
}
|
||||
const description = cdpStringValue(value.description) ?? "";
|
||||
const annotations = recordValue(value.annotations);
|
||||
const declaration = jsonValueSchema.safeParse(value.inputSchema);
|
||||
if (!declaration.success)
|
||||
completeness.exclude("webmcp_tools", "invalid_protocol_value");
|
||||
const schema = declaration.success ? declaration.data : null;
|
||||
return {
|
||||
tool_key: toolKey(frame.url, frameId, name),
|
||||
name,
|
||||
@@ -424,7 +429,10 @@ const normalizeTool = (
|
||||
numberValue(value.backendNodeId) === undefined
|
||||
? "imperative"
|
||||
: "declarative",
|
||||
input_schema_shape: schemaShape(value.inputSchema),
|
||||
input_schema: schema,
|
||||
input_schema_sha256: declaration.success
|
||||
? digestCanonicalValue(schema)
|
||||
: null,
|
||||
annotations: {
|
||||
read_only: booleanOrNull(annotations?.readOnly),
|
||||
untrusted_content: booleanOrNull(annotations?.untrustedContent),
|
||||
@@ -438,15 +446,6 @@ const normalizeTool = (
|
||||
};
|
||||
};
|
||||
|
||||
const schemaShape = (value: unknown) => {
|
||||
if (recordValue(value) === undefined) return null;
|
||||
const encoded = JSON.stringify(value);
|
||||
const shape = inferJsonShape(encoded);
|
||||
if (shape === null)
|
||||
throw new BrowserObservationError("inspect_web_page", "protocol_error");
|
||||
return shape;
|
||||
};
|
||||
|
||||
const registrationSource = (
|
||||
stack: UnknownRecord | undefined,
|
||||
allowedOrigins: ReadonlySet<string>,
|
||||
|
||||
Reference in New Issue
Block a user