fix: salvage a list result's valid entries when one is malformed (#1909)

The SDK validates a list result as a whole, so a single non-conforming entry
rejected the entire response and the panel showed "Couldn't load resources"
with zero items — the exact opposite of what a debugging tool should do with a
server that is 90% right. Reported against a PHP server whose empty
`annotations` object reaches the wire as `[]` rather than `{}`.

`listAll*` now falls back to a lenient re-walk when — and only when — the SDK
rejects a result it received (`InvalidResult` / `UnsupportedResultType`), keeps
the entries that validate, and reports the rest. A conforming server takes the
strict, cache-aware path exactly as before.

Salvaging is not accepting: the dropped entries are named with their reason in
a warning above the list, and the Protocol entry is still marked rejected, so
the wire truth survives. When every entry validates, the original error is
rethrown rather than swallowed — the rejection was about something the
per-item pass cannot explain.

`isClientDecodeRejection` moves to the new module and is now shared with
managedListState, which had the only copy.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HDdo1rNRVQnVRRdsqSrvG3
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-15 16:52:11 -04:00
commit fe5b622fd1

View file

@ -11,6 +11,7 @@ import type {
DiscoverResult,
} from "@modelcontextprotocol/client";
import type { ExcludedTool } from "../mcp/types.js";
import type { MalformedListItem } from "../mcp/listSalvage.js";
// Module-scope frozen object so the `?? EMPTY_CLIENT_CAPABILITIES`
// fallback below doesn't return a fresh literal on every render —
@ -44,6 +45,12 @@ export interface UseInspectorClientResult {
* connections and before connect (#1632).
*/
excludedTools: ExcludedTool[];
/**
* Entries the Inspector dropped from a list result because they failed the
* spec schema for their primitive. Empty against a conforming server; a
* non-empty set means that list rendered without them (#1909).
*/
malformedListItems: MalformedListItem[];
/**
* Message from the most recent mid-session transport failure (the client's
* `error` event — stdio crash, SSE drop, HTTP 5xx). Stays set until the next
@ -97,6 +104,9 @@ export function useInspectorClient(
const [excludedTools, setExcludedTools] = useState<ExcludedTool[]>(
inspectorClient?.getExcludedTools() ?? [],
);
const [malformedListItems, setMalformedListItems] = useState<
MalformedListItem[]
>(inspectorClient?.getMalformedListItems() ?? []);
const [lastError, setLastError] = useState<string | undefined>(undefined);
useEffect(() => {
@ -109,6 +119,7 @@ export function useInspectorClient(
setProtocolEra(undefined);
setDiscoverResult(undefined);
setExcludedTools([]);
setMalformedListItems([]);
setLastError(undefined);
return;
}
@ -121,6 +132,7 @@ export function useInspectorClient(
setProtocolEra(inspectorClient.getProtocolEra());
setDiscoverResult(inspectorClient.getDiscoverResult());
setExcludedTools(inspectorClient.getExcludedTools());
setMalformedListItems(inspectorClient.getMalformedListItems());
setLastError(undefined);
const onStatusChange = (event: TypedEvent<"statusChange">) => {
@ -156,6 +168,11 @@ export function useInspectorClient(
) => {
setDiscoverResult(event.detail);
};
const onMalformedListItemsChange = (
event: TypedEvent<"malformedListItemsChange">,
) => {
setMalformedListItems(event.detail);
};
const onExcludedToolsChange = (
event: TypedEvent<"excludedToolsChange">,
) => {
@ -186,6 +203,10 @@ export function useInspectorClient(
"excludedToolsChange",
onExcludedToolsChange,
);
inspectorClient.addEventListener(
"malformedListItemsChange",
onMalformedListItemsChange,
);
return () => {
inspectorClient.removeEventListener("statusChange", onStatusChange);
@ -218,6 +239,10 @@ export function useInspectorClient(
"excludedToolsChange",
onExcludedToolsChange,
);
inspectorClient.removeEventListener(
"malformedListItemsChange",
onMalformedListItemsChange,
);
};
}, [inspectorClient]);
@ -247,6 +272,7 @@ export function useInspectorClient(
protocolEra,
discoverResult,
excludedTools,
malformedListItems,
lastError,
appRendererClient: inspectorClient?.getAppRendererClient() ?? null,
connect,