fix(mcp): reject unknown MCP tool inputs (#975)

* fix(mcp): reject unknown official tool inputs

* fix(mcp): reject unknown native tool inputs

* test(mcp): follow native contract module move

* fix(mcp): reject unknown remaining tool inputs

* fix(mcp): satisfy strict unknown and browser input schemas

Remove obsolete approval fields from residual-unknown fixtures, project update inputs explicitly, and stop passing target_id to list-targets parsing.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morluto
2026-10-08 01:10:53 +08:00
committed by GitHub
co-authored by Cursor Agent
parent ae0f725fad
commit fe64fd65d9
18 changed files with 267 additions and 25 deletions
@@ -28,6 +28,38 @@ function schemaErrors(tools: readonly ToolSchemas[]): string[] {
);
}
function expectStrictInputSchemaParity(
tools: readonly ToolSchemas[],
ajv: Ajv2020,
): void {
const advertised = new Map(tools.map((tool) => [tool.name, tool]));
const names = [
"inspect_managed_artifact",
"inspect_managed_members",
"inspect_managed_native_boundaries",
"list_browser_targets",
"open_binary",
"close_binary",
"binary_session",
"find_changed_behavior",
"build_call_path",
"record_unknown",
"update_unknown",
];
for (const name of names) {
const contract = TOOL_CONTRACTS.find(
({ name: toolName }) => toolName === name,
);
const tool = advertised.get(name);
const example = contract?.examples[0];
if (contract === undefined || tool === undefined || example === undefined)
throw new Error(`${name} did not have an advertised example`);
const malformed = { ...example.input, __unexpected_root_key__: true };
expect(contract.inputSchema.safeParse(malformed).success, name).toBe(false);
expect(ajv.compile(tool.inputSchema)(malformed), name).toBe(false);
}
}
const advertiseAndEnforceProcessEnvironmentKeyConstraint =
async (): Promise<void> => {
const contract = TOOL_CONTRACTS.find(
@@ -190,6 +222,8 @@ describe("MCP JSON Schema validity", () => {
).toBe(true);
}
expectStrictInputSchemaParity(tools, ajv);
const nativeObservation = TOOL_CONTRACTS.find(
({ name }) => name === "observe_native_ui",
);