fix: address Copilot review rounds 7 and 8

- rootUnion: a `oneOf` demands that EXACTLY one alternative match, which
  flattening cannot preserve, so it is offered only when a discriminator makes
  the alternatives mutually exclusive; `anyOf` makes no such claim and is
  unaffected. An empty `additionalProperties` schema is the equivalent of
  `true` and no longer declines a union.
- selectBranchIndex: falls back to the branch whose own required fields the
  values supply, so an undiscriminated union's values open the picker on the
  shape they describe rather than on the first branch.
- admitsNull: honors a sibling `nullable: true` beside `const: null`.
- SchemaForm: a value is carried only where the incoming branch leaves the
  root's declaration as it found it; anything it declares itself is reset,
  since it may type the name differently from where the value was typed.
  `hasOwn`/`fromEntries` throughout, so `constructor` is not read as a
  supplied value and `__proto__` is not dropped into the prototype setter.
- TUI: the same prototype-safe construction on the way out of the form, and
  the chosen branch's `required` list is checked at submit — rendering a
  branch's fields optional makes the FORM satisfiable, not the call, so the
  missing names are reported rather than a known-invalid call being sent.

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-26 03:54:24 -04:00
commit 85b8e4601c

View file

@ -5,7 +5,11 @@ import { InspectorClient } from "@inspector/core/mcp/index.js";
import { AuthRecoveryRequiredError } from "@inspector/core/auth/challenge.js";
import type { Tool, CallToolResult } from "@modelcontextprotocol/client";
import type { JsonValue } from "@inspector/core/mcp/index.js";
import { decodeFormValues, schemaToForm } from "../utils/schemaToForm.js";
import {
decodeFormValues,
missingRequiredFields,
schemaToForm,
} from "../utils/schemaToForm.js";
import { ScrollView, type ScrollViewRef } from "ink-scroll-view";
interface ToolTestModalProps {
@ -123,6 +127,23 @@ export function ToolTestModal({
// the base fields plus the chosen branch's, and nothing from the others.
const values = decodeFormValues(tool.inputSchema, rawValues);
// A branch's fields are rendered optional — only one alternative applies to
// a call, and requiring every branch's would deadlock a static form — so
// the chosen shape's own requirements are checked here instead. Reported
// rather than sent: a call known to violate the schema teaches the user
// nothing about the server (#2123).
const missing = missingRequiredFields(tool.inputSchema, values, rawValues);
if (missing.length > 0) {
setResult({
input: values,
output: null,
error: `Missing required argument${missing.length > 1 ? "s" : ""}: ${missing.join(", ")}`,
duration: 0,
});
setState("results");
return;
}
setState("loading");
const startTime = Date.now();