fix(mcp): bound capture comparison input schema depth (#1005)
* fix(mcp): advertise JSON values without recursive schemas
`z.json()` projects a self-referential `$defs/__schema0` entry. Twenty
tool input schemas and 123 output schemas carried it, and clients or
model APIs that reject recursive JSON Schemas refuse the whole tool
list. Every JSON value satisfies `{}`, so the shared JSON value schema
now advertises that. Runtime parsing still admits only JSON values.
Refs #919
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(mcp): keep advertised input schemas within model function-calling limits
Some model providers reject the whole tool list when any input schema
contains a recursive $ref or nests deeper than 10 levels (fixes #919).
Sanitize the advertised wire projection: break cyclic $refs, bound nesting
depth, and drop unreachable $defs. Canonical Zod contracts are untouched.
---------
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: sx4im <sx4im@users.noreply.github.com>
Co-authored-by: N0zoM1z0 <1705004398@qq.com>
This commit is contained in:
co-authored by
Kaoru0822
Claude Opus 5.5
sx4im
N0zoM1z0
parent
7425f70fd0
commit
6b55de017b
@@ -0,0 +1,62 @@
|
||||
import { browserCaptureComparisonInputSchema } from "../domain/browserCaptureComparison.js";
|
||||
import { browserScenarioCaptureSchema } from "../domain/browserScenarioCapture.js";
|
||||
import { captureSnapshotSchema } from "../domain/webCaptureDiffSchemas.js";
|
||||
|
||||
// Captures are complete producer results to pass back unchanged, rather than
|
||||
// analyst-authored options. Describe that boundary without embedding the entire
|
||||
// inspection result schema in every comparison input. The cloned parser still
|
||||
// validates every nested field using the canonical domain schemas.
|
||||
const passiveCaptureInputSchema = captureSnapshotSchema.clone(
|
||||
captureSnapshotSchema.def,
|
||||
);
|
||||
passiveCaptureInputSchema._zod.toJSONSchema = () => ({
|
||||
type: "object",
|
||||
properties: {
|
||||
inspection: {
|
||||
type: "object",
|
||||
description:
|
||||
"Complete result object returned by inspect_web_page. Pass the entire result unchanged, including capture identity, observations, completeness, and limitations. Every nested field is validated by REA.",
|
||||
},
|
||||
webmcp: {
|
||||
anyOf: [{ type: "object" }, { type: "null" }],
|
||||
default: null,
|
||||
description:
|
||||
"Complete result object returned by discover_webmcp_tools for this capture, or null when it was not recorded. Pass the entire result unchanged. Every nested field is validated by REA.",
|
||||
},
|
||||
},
|
||||
required: ["inspection"],
|
||||
});
|
||||
|
||||
const scenarioCaptureInputSchema = browserScenarioCaptureSchema.clone(
|
||||
browserScenarioCaptureSchema.def,
|
||||
);
|
||||
scenarioCaptureInputSchema._zod.toJSONSchema = () => ({
|
||||
type: "object",
|
||||
description:
|
||||
"Complete result object returned by capture_browser_scenario. Pass the entire result unchanged, including browser and scenario identity, steps, events, artifact contents and digests, completeness, and limitations. Every nested field is validated by REA.",
|
||||
});
|
||||
|
||||
/** Advertise capture round trips while retaining full runtime validation. */
|
||||
export const browserCaptureToolInputSchema =
|
||||
browserCaptureComparisonInputSchema.safeExtend({
|
||||
before: passiveCaptureInputSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Earlier passive web-page capture with complete producer results.",
|
||||
),
|
||||
after: passiveCaptureInputSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Later passive web-page capture with complete producer results.",
|
||||
),
|
||||
before_scenario: scenarioCaptureInputSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Earlier complete result object returned by capture_browser_scenario.",
|
||||
),
|
||||
after_scenario: scenarioCaptureInputSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Later complete result object returned by capture_browser_scenario.",
|
||||
),
|
||||
});
|
||||
@@ -17,10 +17,7 @@ import {
|
||||
discoverWebMcpToolsInputSchema,
|
||||
webMcpDiscoverySchema,
|
||||
} from "../domain/webMcpDiscovery.js";
|
||||
import {
|
||||
browserCaptureComparisonInputSchema,
|
||||
browserCaptureComparisonSchema,
|
||||
} from "../domain/browserCaptureComparison.js";
|
||||
import { browserCaptureComparisonSchema } from "../domain/browserCaptureComparison.js";
|
||||
import {
|
||||
captureWebScreenshotInputSchema,
|
||||
compareWebScreenshotsInputSchema,
|
||||
@@ -29,6 +26,7 @@ import {
|
||||
} from "../domain/webScreenshot.js";
|
||||
import { toolContractMetadata } from "./toolEffects.js";
|
||||
import { evidenceResultOf } from "./toolOutputSchemas.js";
|
||||
import { browserCaptureToolInputSchema } from "./browserCaptureToolInputSchema.js";
|
||||
|
||||
const evidenceResult = evidenceResultOf;
|
||||
const listOutputSchema = evidenceResult(browserTargetListSchema);
|
||||
@@ -215,9 +213,9 @@ export const BROWSER_TOOL_CONTRACTS = [
|
||||
name: "compare_web_captures",
|
||||
...toolContractMetadata("compare_web_captures"),
|
||||
description:
|
||||
"Compare passive web captures by providing before and after, or compare recorded scenarios by providing before_scenario and after_scenario with an optional normalization policy. Use exactly one input group. Scenario comparison aligns exact step IDs, records deterministic literal normalization, and returns every artifact-level difference plus alignment failures inline. Missing or truncated evidence never proves equality.",
|
||||
"Compare passive web captures by providing before and after, each with the complete inspect_web_page result in inspection and an optional complete discover_webmcp_tools result in webmcp; or compare recorded scenarios by passing complete capture_browser_scenario results in before_scenario and after_scenario with an optional normalization policy. Use exactly one input group. Scenario comparison aligns exact step IDs, records deterministic literal normalization, and returns every artifact-level difference plus alignment failures inline. Missing or truncated evidence never proves equality.",
|
||||
kind: "browser-provider",
|
||||
inputSchema: browserCaptureComparisonInputSchema,
|
||||
inputSchema: browserCaptureToolInputSchema,
|
||||
outputSchema: captureDiffOutputSchema,
|
||||
examples: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user