feat(web): add Console (stderr) tab; show it on stdio connect failure (#1621)

A failed stdio launch had no useful diagnostic surface: the message log
(History) is cleared on the error transition and there are no HTTP
requests (Network), so the auto-opened monitoring column was empty. The
process's stderr — which explains the failure (e.g. "No module named
mcp_server_time") — was captured in StderrLogState but never displayed.

- New ConsoleScreen renders the captured stderr stream (search / sort /
  clear / export; embeddable in the monitoring column), wired through App
  via the existing useStderrLog hook + StderrLogState.
- Console is a pinnable monitor tab like Logs/History/Network, gated to
  stdio servers (HTTP has no child process). It lives in the header menu
  when the column isn't pinned, and moves into the column when it is.
- The failure column now picks its tabs by which diagnostic actually
  captured content (stderr → Console, fetch requests → Network), not by
  the active server's transport: a connect failure fires the client
  `disconnect` event, which clears `activeServer`, so transport can't be
  read back there. The memo re-runs as stderr/fetch entries stream in, so
  the diagnostic tab appears as soon as the failing process prints.

Verified live against a failing `python -m mcp_server_time` stdio server:
the column auto-opens to Console showing the real ModuleNotFoundError.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BrihGWcrM9JGRyu41nzZYw
This commit is contained in:
cliffhall 2026-07-09 14:06:13 -04:00
commit 219298b24d
2 changed files with 643 additions and 22 deletions

View file

@ -44,6 +44,7 @@ import {
EMPTY_LOGS_UI,
EMPTY_HISTORY_UI,
EMPTY_NETWORK_UI,
EMPTY_CONSOLE_UI,
} from "../../screens/screenUiState";
// Stub bridge factory — AppsScreen mounts the inner iframe and invokes
@ -84,6 +85,7 @@ function makeProps(
tasks: [],
history: [],
network: [],
stderrLogs: [],
currentLogLevel: "info",
sandboxPath: "about:blank",
bridgeFactory: noopBridgeFactory,
@ -96,6 +98,7 @@ function makeProps(
logsUi: EMPTY_LOGS_UI,
historyUi: EMPTY_HISTORY_UI,
networkUi: EMPTY_NETWORK_UI,
consoleUi: EMPTY_CONSOLE_UI,
onToggleTheme: vi.fn(),
onOpenClientSettings: vi.fn(),
onToggleConnection: vi.fn(),
@ -140,6 +143,9 @@ function makeProps(
onNetworkUiChange: vi.fn(),
onClearNetwork: vi.fn(),
onExportNetwork: vi.fn(),
onConsoleUiChange: vi.fn(),
onClearConsole: vi.fn(),
onExportConsole: vi.fn(),
onAppsUiChange: vi.fn(),
onSelectApp: vi.fn(),
onOpenApp: vi.fn(),
@ -1404,22 +1410,41 @@ describe("InspectorView", () => {
screen.queryByRole("button", { name: "Close monitoring column" }),
).toBeNull();
// A connection failure (→ error) opens it to surface the diagnostics.
rerender(<StatefulInspectorViewHost {...failedHttp()} />);
// A connection failure (→ error) opens it to surface the diagnostics. The
// failed HTTP request is what captured the failure, so Network is present.
rerender(
<StatefulInspectorViewHost
{...failedHttp({
network: [
{
id: "f1",
timestamp: new Date(),
method: "POST",
url: "http://localhost:3000/mcp",
requestHeaders: {},
error: "fetch failed: ECONNREFUSED",
category: "transport",
},
],
})}
/>,
);
expect(
await screen.findByRole("button", { name: "Close monitoring column" }),
).toBeInTheDocument();
// The failure column offers the History + Network diagnostics, but not
// Logs (a failed connect never negotiated the logging capability).
// The failure column offers History + Network (the captured request), but
// not Logs (a failed connect never negotiated the logging capability) nor
// Console (an HTTP transport has no child-process stderr).
expect(screen.getByRole("radio", { name: "History" })).toBeChecked();
expect(
screen.getByRole("radio", { name: "Network" }),
).toBeInTheDocument();
expect(screen.queryByRole("radio", { name: "Logs" })).toBeNull();
expect(screen.queryByRole("radio", { name: "Console" })).toBeNull();
});
it("omits Network from the failure column for a stdio server (#1621)", async () => {
it("surfaces Console (stderr), not Network, in the failure column for a stdio server (#1621)", async () => {
monitorWide.value = true;
const stdioErr: ServerEntry = {
id: "beta",
@ -1437,13 +1462,30 @@ describe("InspectorView", () => {
/>,
);
rerender(
<StatefulInspectorViewHost {...failedHttp({ servers: [stdioErr] })} />,
<StatefulInspectorViewHost
{...failedHttp({
servers: [stdioErr],
// A connect failure fires the client `disconnect` event, which
// clears activeServer — so the failure column must key off captured
// stderr, NOT the (now-undefined) active server's transport.
activeServer: undefined,
stderrLogs: [
{ timestamp: new Date(), message: "ModuleNotFoundError: boom" },
],
})}
/>,
);
// stdio has no HTTP traffic, so the failure column shows History only.
// The captured stderr means it was a stdio launch: the column surfaces
// Console (the process's stderr) and defaults to it — that's where the
// spawn error is — with no Network (no HTTP traffic). The stderr renders.
expect(
await screen.findByRole("radio", { name: "History" }),
await screen.findByRole("radio", { name: "Console" }),
).toBeChecked();
expect(
screen.getByRole("radio", { name: "History" }),
).toBeInTheDocument();
expect(screen.queryByRole("radio", { name: "Network" })).toBeNull();
expect(screen.getByText("ModuleNotFoundError: boom")).toBeInTheDocument();
});
it("does not auto-open on a mount that starts already errored (#1621)", () => {
@ -1456,6 +1498,63 @@ describe("InspectorView", () => {
).toBeNull();
});
const stdioServer: ServerEntry = {
id: "gamma",
name: "Gamma",
config: { type: "stdio", command: "echo" },
connection: { status: "connected" },
};
it("offers Console (not Network) as a monitor tab for a connected stdio server (#1621)", async () => {
monitorWide.value = true;
window.localStorage.setItem("inspector.monitor.pinned", "true");
renderWithMantine(
<StatefulInspectorViewHost
{...makeProps({
servers: [stdioServer],
activeServer: "gamma",
connectionStatus: "connected",
initializeResult: httpInit,
stderrLogs: [{ timestamp: new Date(), message: "server booting" }],
})}
/>,
);
// Pinned column for a stdio server hosts Logs/History/Console — never
// Network (no HTTP traffic to show).
expect(
await screen.findByRole("radio", { name: "Console" }),
).toBeInTheDocument();
expect(
screen.getByRole("radio", { name: "History" }),
).toBeInTheDocument();
expect(screen.queryByRole("radio", { name: "Network" })).toBeNull();
});
it("lists Console in the header tab menu for a connected stdio server when unpinned (#1621)", async () => {
// Column not pinned, so the monitor group (incl. Console) lives in the
// header menu — the user can reach the stderr stream during a live
// session, not only on failure.
monitorWide.value = true;
renderWithMantine(
<StatefulInspectorViewHost
{...makeProps({
servers: [stdioServer],
activeServer: "gamma",
connectionStatus: "connected",
initializeResult: httpInit,
})}
/>,
);
const header = screen.getByRole("banner");
expect(
within(header).getByRole("radio", { name: "Console" }),
).toBeInTheDocument();
// stdio: Network is not in the header menu.
expect(
within(header).queryByRole("radio", { name: "Network" }),
).toBeNull();
});
it("pins the monitor group into the column and removes it from the header", async () => {
monitorWide.value = true;
renderWithMantine(<StatefulInspectorViewHost {...connectedHttp()} />);

View file

@ -32,6 +32,7 @@ import type {
InspectorResourceSubscription,
MessageEntry,
ServerEntry,
StderrLogEntry,
} from "@inspector/core/mcp/types.js";
import { isTerminalStatus } from "@inspector/core/mcp/types.js";
import { isAppTool } from "@inspector/core/mcp/apps.js";
@ -78,6 +79,10 @@ import {
NetworkScreen,
type NetworkUiState,
} from "../../screens/NetworkScreen/NetworkScreen";
import {
ConsoleScreen,
type ConsoleUiState,
} from "../../screens/ConsoleScreen/ConsoleScreen";
import type { SortDirection } from "../../elements/SortToggle/SortToggle";
import { MonitoringScreen } from "../../groups/MonitoringScreen/MonitoringScreen";
import { ResizeHandle } from "../../elements/ResizeHandle/ResizeHandle";
@ -120,7 +125,7 @@ function serializeListCompact(value: boolean): string {
// SPA only, no SSR — so the persisted value lands without a one-frame
// flicker through the default. The `inspector.<kind>.<scope>` namespace
// keeps related preferences grouped and easy to clear in bulk.
function useSortDirection(scope: "logs" | "history" | "network") {
function useSortDirection(scope: "logs" | "history" | "network" | "console") {
return useLocalStorage<SortDirection>({
key: `inspector.sortDirection.${scope}`,
defaultValue: SORT_DEFAULT,
@ -147,6 +152,7 @@ const SERVERS_TAB = INSPECTOR_SERVERS_TAB;
const LOGS_TAB = "Logs";
const HISTORY_TAB = "History";
const NETWORK_TAB = "Network";
const CONSOLE_TAB = "Console";
const ALL_TABS: string[] = [
SERVERS_TAB,
@ -158,16 +164,29 @@ const ALL_TABS: string[] = [
LOGS_TAB,
HISTORY_TAB,
NETWORK_TAB,
CONSOLE_TAB,
];
// The screens that can be pinned into the monitoring column (#1616). Pinning is
// a group action: opening the column removes all *available* monitor tabs from
// the header and hosts them in the column instead.
type MonitorTab = "Logs" | "History" | "Network";
const MONITOR_TABS: string[] = [LOGS_TAB, HISTORY_TAB, NETWORK_TAB];
// the header and hosts them in the column instead. Console (#1621) is the
// stdio server's stderr stream — mutually exclusive with Network (Console shows
// for stdio, Network for HTTP), but both live in the monitor group.
type MonitorTab = "Logs" | "History" | "Network" | "Console";
const MONITOR_TABS: string[] = [
LOGS_TAB,
HISTORY_TAB,
NETWORK_TAB,
CONSOLE_TAB,
];
function isMonitorTab(tab: string): tab is MonitorTab {
return tab === LOGS_TAB || tab === HISTORY_TAB || tab === NETWORK_TAB;
return (
tab === LOGS_TAB ||
tab === HISTORY_TAB ||
tab === NETWORK_TAB ||
tab === CONSOLE_TAB
);
}
// The viewport width below which the split collapses to a single column: matches
@ -351,6 +370,8 @@ export interface InspectorViewProps {
progressByTaskId?: Record<string, TaskProgress>;
history: MessageEntry[];
network: FetchRequestEntry[];
/** Captured stdio stderr (the Console screen). Empty for HTTP servers. (#1621) */
stderrLogs: StderrLogEntry[];
// Per-screen "operation in flight" states (panel-level; optional because
// the underlying screens accept them as optional).
@ -370,6 +391,7 @@ export interface InspectorViewProps {
logsUi: LogsUiState;
historyUi: HistoryUiState;
networkUi: NetworkUiState;
consoleUi: ConsoleUiState;
/** Active inspector tab (lifted to App for OAuth resume). */
activeTab: string;
@ -486,6 +508,10 @@ export interface InspectorViewProps {
onClearNetwork: () => void;
onExportNetwork: () => void;
onConsoleUiChange: (next: ConsoleUiState) => void;
onClearConsole: () => void;
onExportConsole: () => void;
onAppsUiChange: (next: AppsUiState) => void;
onSelectApp: (name: string) => void;
onOpenApp: (name: string, args: Record<string, unknown>) => void;
@ -514,6 +540,7 @@ export function InspectorView({
progressByTaskId,
history,
network,
stderrLogs,
toolCallState,
getPromptState,
readResourceState,
@ -525,6 +552,7 @@ export function InspectorView({
logsUi,
historyUi,
networkUi,
consoleUi,
currentLogLevel,
sandboxPath,
bridgeFactory,
@ -583,6 +611,9 @@ export function InspectorView({
onNetworkUiChange,
onClearNetwork,
onExportNetwork,
onConsoleUiChange,
onClearConsole,
onExportConsole,
onAppsUiChange,
onSelectApp,
onOpenApp,
@ -599,6 +630,7 @@ export function InspectorView({
const [logsSort, setLogsSort] = useSortDirection("logs");
const [historySort, setHistorySort] = useSortDirection("history");
const [networkSort, setNetworkSort] = useSortDirection("network");
const [consoleSort, setConsoleSort] = useSortDirection("console");
// Servers and Resources default to expanded (collapsed=false) so new
// users see content on first paint; History/Network default to
@ -729,6 +761,9 @@ export function InspectorView({
const hasLogging = capabilities?.logging !== undefined;
return ALL_TABS.filter((t) => {
if (t === NETWORK_TAB && isStdio) return false;
// Console is the stdio process's stderr stream — shown only for stdio
// servers (HTTP transports have no child process to capture). (#1621)
if (t === CONSOLE_TAB && !isStdio) return false;
if (t === "Tools" && !hasTools) return false;
if (t === "Apps" && !hasApps) return false;
if (t === "Prompts" && !hasPrompts) return false;
@ -761,16 +796,27 @@ export function InspectorView({
if (connected) return availableTabs.filter((t) => MONITOR_TABS.includes(t));
if (failed) {
// A failed connect never negotiated capabilities, so Logs (gated on the
// server's `logging` capability) isn't meaningful. History (the local
// client-side message log) always captured the attempt, and Network (HTTP
// requests) did too for non-stdio transports — those are what explain the
// failure, so offer exactly them.
const active = serversInput.find((s) => s.id === activeServer);
const isStdio = active ? getServerType(active.config) === "stdio" : false;
return isStdio ? [HISTORY_TAB] : [HISTORY_TAB, NETWORK_TAB];
// server's `logging` capability) isn't meaningful. What explains the
// failure is whichever diagnostic actually captured something:
// • stdio → the process's stderr (Console): the spawn/startup error the
// child printed before dying.
// • HTTP → the failed requests (Network).
// We key off *captured content*, not the server's declared transport,
// because a connect failure fires the client `disconnect` event, which
// clears `activeServer` — so transport can't be read back reliably here.
// History is always offered, though a pre-handshake failure usually
// leaves it empty. Console leads (it's the stdio failure's story); Network
// trails History (matching the connected order). This memo re-runs as
// stderr/fetch entries stream in, so the diagnostic tab appears as soon as
// the failing process/request produces output.
const tabs: string[] = [];
if (stderrLogs.length > 0) tabs.push(CONSOLE_TAB);
tabs.push(HISTORY_TAB);
if (network.length > 0) tabs.push(NETWORK_TAB);
return tabs;
}
return [];
}, [connected, failed, availableTabs, serversInput, activeServer]);
}, [connected, failed, availableTabs, stderrLogs, network]);
const effectivePinned =
monitorPinned &&
!!isWide &&
@ -933,6 +979,15 @@ export function InspectorView({
compact: networkCompact,
onToggleCompact: () => setNetworkCompact((c) => !c),
};
const consoleScreenProps = {
entries: stderrLogs,
ui: consoleUi,
onUiChange: onConsoleUiChange,
onClear: onClearConsole,
onExport: onExportConsole,
sortDirection: consoleSort,
onSortChange: setConsoleSort,
};
// Embedded instances for the pinned column, keyed by tab. MonitoringScreen
// renders only the active one; the rest are unmounted element values. Each
@ -960,6 +1015,13 @@ export function InspectorView({
embedded
/>
),
[CONSOLE_TAB]: (
<ConsoleScreen
{...consoleScreenProps}
ui={{ filterText: monitorSearch }}
embedded
/>
),
};
return (
@ -1111,6 +1173,12 @@ export function InspectorView({
onPin={canPin ? () => pinMonitor(NETWORK_TAB) : undefined}
/>
</ScreenStage>
<ScreenStage active={activeTab === CONSOLE_TAB}>
<ConsoleScreen
{...consoleScreenProps}
onPin={canPin ? () => pinMonitor(CONSOLE_TAB) : undefined}
/>
</ScreenStage>
</ScreenStageContainer>
<Transition
mounted={effectivePinned}