fix: exclude undefined from _meta values, and cover the JSON worker

- `JsonValue` admits `undefined`, so `RequestMetadata` accepted values that do
  not survive serialization: `JSON.stringify` drops an `undefined` object
  member and rewrites an `undefined` array element to `null`. The type
  contradicted the one promise this payload makes. Added `StrictJsonValue` /
  `StrictJsonObject` and used them for the metadata path.

  Deliberately not a change to the repo-wide `JsonValue`: for tool *arguments*
  `undefined` legitimately means "not supplied". The narrowing is sound
  wherever it lands here, since every one of these values comes from
  `JSON.parse`, which cannot produce `undefined`. The CLI's `parseKeyValuePair`
  needed the same tightening — caught by `clients/cli`'s typecheck, which the
  web `tsc -b` does not cover.

- Nothing asserted the JSON worker's annotations, and the wrapper's own "Not
  valid JSON" message comes from our parser rather than from Ace — so a broken
  worker URL would have left every test passing while the gutter diagnostics
  silently disappeared. Added a Storybook play function that waits for a real
  `session.getAnnotations()` error entry, and verified it fails when the worker
  module URL is pointed at a bad path.

- `aria-describedby` referenced only the error, so a supplied `description` was
  never announced and would have been dropped entirely once the draft went
  invalid. Both ids are referenced now, with the description surviving the
  error.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177mPHAdECD18nLLCTwR5rh
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-23 18:27:28 -04:00
commit 616dd9c196

View file

@ -24,7 +24,11 @@ import type { OAuthClientProvider } from "@modelcontextprotocol/client";
import type { Transport } from "@modelcontextprotocol/client";
import type { InspectorLogger } from "../logging/logger.js";
import type { AppElicitationRenderer } from "./appElicitation.js";
import type { JsonObject, JsonValue } from "../json/jsonUtils.js";
import type {
JsonValue,
StrictJsonObject,
StrictJsonValue,
} from "../json/jsonUtils.js";
import type {
ClientConfig,
EnterpriseManagedAuthIdpConfig,
@ -112,7 +116,7 @@ export type StoredMCPServer = MCPServerConfig & {
* existing `mcp.json` keeps working, but it is never written back — a
* round-trip through the Inspector rewrites the field as an object.
*/
metadata?: JsonObject;
metadata?: StrictJsonObject;
/**
* Protocol era to negotiate with this server (`"legacy" | "auto" | "modern"`),
* orthogonal to the transport `type`. Inspector-specific (no analog in the
@ -374,6 +378,11 @@ export interface ServerState {
* A `_meta` payload: a JSON object whose values may be any JSON, not just
* strings (#1910).
*
* {@link StrictJsonValue}, not `JsonValue`: the latter admits `undefined`,
* which `JSON.stringify` drops from an object and turns into `null` inside an
* array — so a value the type accepted would not be the value that reaches the
* server, contradicting the one promise this payload makes.
*
* The MCP spec places no restriction on `_meta` value types and the SDK models
* the field as a passthrough object, so the Inspector must be able to send —
* and to record — nested objects, arrays, numbers, booleans and `null`. Used
@ -381,7 +390,7 @@ export interface ServerState {
* `InspectorClientOptions.defaultMetadata`) and the per-call metadata every
* request verb accepts.
*/
export type RequestMetadata = Record<string, JsonValue>;
export type RequestMetadata = Record<string, StrictJsonValue>;
/**
* Represents a complete resource read invocation, including request parameters,