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:
parent
85153c6232
commit
219298b24d
4 changed files with 643 additions and 22 deletions
|
|
@ -0,0 +1,87 @@
|
|||
import { useState } from "react";
|
||||
import type { ComponentProps } from "react";
|
||||
import type { Meta, StoryObj } from "@storybook/react-vite";
|
||||
import { expect, fn, userEvent, within } from "storybook/test";
|
||||
import type { StderrLogEntry } from "../../../../../../core/mcp/types.js";
|
||||
import { ConsoleScreen } from "./ConsoleScreen";
|
||||
import { EMPTY_CONSOLE_UI } from "../screenUiState";
|
||||
|
||||
// ConsoleScreen is controlled (the search text lives in the parent as `ui` —
|
||||
// see #1417). This wrapper holds that state so the play-driven search actually
|
||||
// filters entries, mirroring how App owns the state.
|
||||
function StatefulConsoleScreen(args: ComponentProps<typeof ConsoleScreen>) {
|
||||
const [ui, setUi] = useState({ ...EMPTY_CONSOLE_UI, ...args.ui });
|
||||
return <ConsoleScreen {...args} ui={ui} onUiChange={setUi} />;
|
||||
}
|
||||
|
||||
const meta: Meta<typeof ConsoleScreen> = {
|
||||
title: "Screens/ConsoleScreen",
|
||||
component: ConsoleScreen,
|
||||
parameters: { layout: "fullscreen" },
|
||||
args: {
|
||||
onClear: fn(),
|
||||
onExport: fn(),
|
||||
ui: EMPTY_CONSOLE_UI,
|
||||
onUiChange: fn(),
|
||||
sortDirection: "newest-first",
|
||||
onSortChange: fn(),
|
||||
},
|
||||
render: (args) => <StatefulConsoleScreen {...args} />,
|
||||
};
|
||||
|
||||
export default meta;
|
||||
type Story = StoryObj<typeof ConsoleScreen>;
|
||||
|
||||
const sampleEntries: StderrLogEntry[] = [
|
||||
{
|
||||
timestamp: new Date("2026-03-17T10:00:00Z"),
|
||||
message: "Starting MCP time server…",
|
||||
},
|
||||
{
|
||||
timestamp: new Date("2026-03-17T10:00:01Z"),
|
||||
message:
|
||||
'Traceback (most recent call last):\n File "<frozen runpy>", line 198, in _run_module_as_main',
|
||||
},
|
||||
{
|
||||
timestamp: new Date("2026-03-17T10:00:01Z"),
|
||||
message: "ModuleNotFoundError: No module named 'mcp_server_time'",
|
||||
},
|
||||
];
|
||||
|
||||
export const WithEntries: Story = {
|
||||
args: {
|
||||
entries: sampleEntries,
|
||||
},
|
||||
};
|
||||
|
||||
export const Empty: Story = {
|
||||
args: {
|
||||
entries: [],
|
||||
},
|
||||
};
|
||||
|
||||
export const FilterBySearch: Story = {
|
||||
args: {
|
||||
entries: sampleEntries,
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
// Both the startup line and the error are visible initially.
|
||||
await expect(
|
||||
canvas.getByText("Starting MCP time server…"),
|
||||
).toBeInTheDocument();
|
||||
// Searching for the error text hides the unrelated startup line.
|
||||
await userEvent.type(
|
||||
canvas.getByPlaceholderText("Search..."),
|
||||
"ModuleNotFound",
|
||||
);
|
||||
await expect(
|
||||
canvas.queryByText("Starting MCP time server…"),
|
||||
).not.toBeInTheDocument();
|
||||
await expect(
|
||||
canvas.getByText(
|
||||
"ModuleNotFoundError: No module named 'mcp_server_time'",
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
import { describe, it, expect, vi } from "vitest";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import type { StderrLogEntry } from "@inspector/core/mcp/types.js";
|
||||
import { renderWithMantine, screen } from "../../../test/renderWithMantine";
|
||||
import { ConsoleScreen, type ConsoleScreenProps } from "./ConsoleScreen";
|
||||
import { EMPTY_CONSOLE_UI } from "../screenUiState";
|
||||
|
||||
const entries: StderrLogEntry[] = [
|
||||
{ timestamp: new Date("2026-03-17T10:00:00Z"), message: "first line" },
|
||||
{ timestamp: new Date("2026-03-17T10:00:01Z"), message: "second BOOM line" },
|
||||
];
|
||||
|
||||
function makeProps(
|
||||
overrides: Partial<ConsoleScreenProps> = {},
|
||||
): ConsoleScreenProps {
|
||||
return {
|
||||
entries,
|
||||
ui: EMPTY_CONSOLE_UI,
|
||||
onUiChange: vi.fn(),
|
||||
onClear: vi.fn(),
|
||||
onExport: vi.fn(),
|
||||
sortDirection: "newest-first",
|
||||
onSortChange: vi.fn(),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("ConsoleScreen", () => {
|
||||
it("renders each stderr entry's message", () => {
|
||||
renderWithMantine(<ConsoleScreen {...makeProps()} />);
|
||||
expect(screen.getByText("first line")).toBeInTheDocument();
|
||||
expect(screen.getByText("second BOOM line")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the empty state when there are no entries", () => {
|
||||
renderWithMantine(<ConsoleScreen {...makeProps({ entries: [] })} />);
|
||||
expect(screen.getByText("No console output")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("filters entries by the search text in ui", () => {
|
||||
renderWithMantine(
|
||||
<ConsoleScreen {...makeProps({ ui: { filterText: "boom" } })} />,
|
||||
);
|
||||
expect(screen.queryByText("first line")).toBeNull();
|
||||
expect(screen.getByText("second BOOM line")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("dispatches onUiChange when typing in the search box", async () => {
|
||||
const onUiChange = vi.fn();
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(<ConsoleScreen {...makeProps({ onUiChange })} />);
|
||||
await user.type(screen.getByPlaceholderText("Search..."), "x");
|
||||
expect(onUiChange).toHaveBeenCalledWith({ filterText: "x" });
|
||||
});
|
||||
|
||||
it("clears the search text via the clear button", async () => {
|
||||
const onUiChange = vi.fn();
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(
|
||||
<ConsoleScreen
|
||||
{...makeProps({ ui: { filterText: "boom" }, onUiChange })}
|
||||
/>,
|
||||
);
|
||||
// Two controls share the accessible name "Clear": the search-box clear
|
||||
// ActionIcon (rendered first, in the sidebar) and the panel's Clear button.
|
||||
// The sidebar one is the search reset.
|
||||
const [clearSearch] = screen.getAllByRole("button", { name: "Clear" });
|
||||
await user.click(clearSearch);
|
||||
expect(onUiChange).toHaveBeenCalledWith({ filterText: "" });
|
||||
});
|
||||
|
||||
it("orders entries oldest-first when requested", () => {
|
||||
renderWithMantine(
|
||||
<ConsoleScreen {...makeProps({ sortDirection: "oldest-first" })} />,
|
||||
);
|
||||
const rendered = screen.getAllByText(/line$/);
|
||||
expect(rendered[0]).toHaveTextContent("first line");
|
||||
});
|
||||
|
||||
it("orders entries newest-first by default", () => {
|
||||
renderWithMantine(<ConsoleScreen {...makeProps()} />);
|
||||
const rendered = screen.getAllByText(/line$/);
|
||||
expect(rendered[0]).toHaveTextContent("second BOOM line");
|
||||
});
|
||||
|
||||
it("disables Clear and Export when there are no entries", () => {
|
||||
renderWithMantine(<ConsoleScreen {...makeProps({ entries: [] })} />);
|
||||
expect(screen.getByRole("button", { name: "Clear" })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Export" })).toBeDisabled();
|
||||
});
|
||||
|
||||
it("invokes onClear and onExport", async () => {
|
||||
const onClear = vi.fn();
|
||||
const onExport = vi.fn();
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(<ConsoleScreen {...makeProps({ onClear, onExport })} />);
|
||||
await user.click(screen.getByRole("button", { name: "Clear" }));
|
||||
await user.click(screen.getByRole("button", { name: "Export" }));
|
||||
expect(onClear).toHaveBeenCalledOnce();
|
||||
expect(onExport).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("shows a pin button only when onPin is provided", () => {
|
||||
const { rerender } = renderWithMantine(<ConsoleScreen {...makeProps()} />);
|
||||
expect(screen.queryByRole("button", { name: "Pin as column" })).toBeNull();
|
||||
rerender(<ConsoleScreen {...makeProps({ onPin: vi.fn() })} />);
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Pin as column" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("drops the search sidebar when embedded", () => {
|
||||
renderWithMantine(<ConsoleScreen {...makeProps({ embedded: true })} />);
|
||||
// The embedded column has no in-screen search box (the column supplies it).
|
||||
expect(screen.queryByPlaceholderText("Search...")).toBeNull();
|
||||
// Entries still render.
|
||||
expect(screen.getByText("first line")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,203 @@
|
|||
import { useMemo } from "react";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Flex,
|
||||
Group,
|
||||
Paper,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import type { StderrLogEntry } from "@inspector/core/mcp/types.js";
|
||||
import { ClearButton } from "../../elements/ClearButton/ClearButton";
|
||||
import {
|
||||
SortToggle,
|
||||
type SortDirection,
|
||||
} from "../../elements/SortToggle/SortToggle";
|
||||
import { PinColumnButton } from "../../elements/PinColumnButton/PinColumnButton";
|
||||
import { EmbeddableScrollArea } from "../../elements/EmbeddableScrollArea/EmbeddableScrollArea";
|
||||
import { useScrollMemory } from "../../../hooks/useScrollMemory";
|
||||
|
||||
export interface ConsoleScreenProps {
|
||||
entries: StderrLogEntry[];
|
||||
ui: ConsoleUiState;
|
||||
onUiChange: (next: ConsoleUiState) => void;
|
||||
onClear: () => void;
|
||||
onExport: () => void;
|
||||
sortDirection: SortDirection;
|
||||
onSortChange: (next: SortDirection) => void;
|
||||
/** See LoggingScreen: shows a "pin as column" button when set (#1616). */
|
||||
onPin?: () => void;
|
||||
/** See LoggingScreen: fills the parent height and drops the filter sidebar. */
|
||||
embedded?: boolean;
|
||||
}
|
||||
|
||||
// Just the search text — stderr has no levels/categories to filter, so this is
|
||||
// the whole of the Console screen's lifted UI state. Controlled by the parent
|
||||
// (App) so it survives tab navigation within a live session (#1417).
|
||||
export interface ConsoleUiState {
|
||||
filterText: string;
|
||||
}
|
||||
|
||||
const ScreenLayout = Flex.withProps({
|
||||
variant: "screen",
|
||||
h: "calc(100dvh - var(--app-shell-header-height, 0px))",
|
||||
gap: "md",
|
||||
p: "xl",
|
||||
});
|
||||
|
||||
const Sidebar = Stack.withProps({
|
||||
w: 340,
|
||||
flex: "0 0 auto",
|
||||
});
|
||||
|
||||
const SidebarCard = Card.withProps({
|
||||
withBorder: true,
|
||||
padding: "lg",
|
||||
});
|
||||
|
||||
const PanelContainer = Paper.withProps({
|
||||
withBorder: true,
|
||||
p: "lg",
|
||||
flex: 1,
|
||||
variant: "panel",
|
||||
});
|
||||
|
||||
const EmptyCenter = Stack.withProps({
|
||||
flex: 1,
|
||||
align: "center",
|
||||
justify: "center",
|
||||
});
|
||||
|
||||
// A single stderr line: a dimmed monospace timestamp beside the process's raw
|
||||
// output. `align: flex-start` keeps the timestamp on the first wrapped row.
|
||||
const EntryRow = Group.withProps({
|
||||
gap: "sm",
|
||||
wrap: "nowrap",
|
||||
align: "flex-start",
|
||||
});
|
||||
|
||||
const TimestampText = Text.withProps({
|
||||
size: "sm",
|
||||
ff: "monospace",
|
||||
c: "dimmed",
|
||||
flex: "0 0 auto",
|
||||
});
|
||||
|
||||
// `consoleLine` (theme variant) preserves the process's own newlines/whitespace
|
||||
// while wrapping over-long lines inside the narrow column.
|
||||
const MessageText = Text.withProps({
|
||||
size: "sm",
|
||||
ff: "monospace",
|
||||
variant: "consoleLine",
|
||||
flex: 1,
|
||||
});
|
||||
|
||||
function formatTimestamp(date: Date): string {
|
||||
return date.toLocaleTimeString();
|
||||
}
|
||||
|
||||
function matchesFilter(entry: StderrLogEntry, filterText: string): boolean {
|
||||
if (!filterText) return true;
|
||||
return entry.message.toLowerCase().includes(filterText.toLowerCase());
|
||||
}
|
||||
|
||||
export function ConsoleScreen({
|
||||
entries,
|
||||
ui,
|
||||
onUiChange,
|
||||
onClear,
|
||||
onExport,
|
||||
sortDirection,
|
||||
onSortChange,
|
||||
onPin,
|
||||
embedded = false,
|
||||
}: ConsoleScreenProps) {
|
||||
const { filterText } = ui;
|
||||
const viewportRef = useScrollMemory("console-stream");
|
||||
|
||||
const filteredEntries = useMemo(() => {
|
||||
// `.filter()` returns a fresh array, so sorting in-place is safe.
|
||||
const sorted = entries
|
||||
.filter((e) => matchesFilter(e, filterText))
|
||||
.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
|
||||
if (sortDirection === "newest-first") sorted.reverse();
|
||||
return sorted;
|
||||
}, [entries, filterText, sortDirection]);
|
||||
|
||||
return (
|
||||
<ScreenLayout h={embedded ? "100%" : undefined}>
|
||||
{embedded ? null : (
|
||||
<Sidebar>
|
||||
<SidebarCard>
|
||||
<Stack gap="md">
|
||||
<Title order={4}>Console</Title>
|
||||
<TextInput
|
||||
placeholder="Search..."
|
||||
value={filterText}
|
||||
onChange={(e) =>
|
||||
onUiChange({ filterText: e.currentTarget.value })
|
||||
}
|
||||
rightSectionPointerEvents="auto"
|
||||
rightSection={
|
||||
filterText ? (
|
||||
<ClearButton
|
||||
onClick={() => onUiChange({ filterText: "" })}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
</Stack>
|
||||
</SidebarCard>
|
||||
</Sidebar>
|
||||
)}
|
||||
<PanelContainer>
|
||||
<Group justify="space-between" mb="sm">
|
||||
<Title order={4}>Server Console</Title>
|
||||
<Group>
|
||||
<SortToggle
|
||||
value={sortDirection}
|
||||
onChange={onSortChange}
|
||||
aria-label="Console sort direction"
|
||||
/>
|
||||
<Button
|
||||
variant="default"
|
||||
onClick={onClear}
|
||||
disabled={entries.length === 0}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
<Button
|
||||
variant="default"
|
||||
onClick={onExport}
|
||||
disabled={entries.length === 0}
|
||||
>
|
||||
Export
|
||||
</Button>
|
||||
{onPin ? <PinColumnButton onPin={onPin} /> : null}
|
||||
</Group>
|
||||
</Group>
|
||||
{filteredEntries.length > 0 ? (
|
||||
<EmbeddableScrollArea embedded={embedded} viewportRef={viewportRef}>
|
||||
<Stack gap="xs">
|
||||
{filteredEntries.map((entry, index) => (
|
||||
<EntryRow key={index}>
|
||||
<TimestampText>
|
||||
{formatTimestamp(entry.timestamp)}
|
||||
</TimestampText>
|
||||
<MessageText>{entry.message}</MessageText>
|
||||
</EntryRow>
|
||||
))}
|
||||
</Stack>
|
||||
</EmbeddableScrollArea>
|
||||
) : (
|
||||
<EmptyCenter>
|
||||
<Text c="dimmed">No console output</Text>
|
||||
</EmptyCenter>
|
||||
)}
|
||||
</PanelContainer>
|
||||
</ScreenLayout>
|
||||
);
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import type { TasksUiState } from "./TasksScreen/TasksScreen";
|
|||
import type { LogsUiState } from "./LoggingScreen/LoggingScreen";
|
||||
import type { HistoryUiState } from "./HistoryScreen/HistoryScreen";
|
||||
import type { NetworkUiState } from "./NetworkScreen/NetworkScreen";
|
||||
import type { ConsoleUiState } from "./ConsoleScreen/ConsoleScreen";
|
||||
import { ALL_LEVELS_VISIBLE } from "./LoggingScreen/logLevels";
|
||||
import { ALL_CATEGORIES_VISIBLE } from "./NetworkScreen/fetchCategories";
|
||||
|
||||
|
|
@ -63,6 +64,10 @@ export const EMPTY_NETWORK_UI: NetworkUiState = {
|
|||
visibleCategories: ALL_CATEGORIES_VISIBLE,
|
||||
};
|
||||
|
||||
export const EMPTY_CONSOLE_UI: ConsoleUiState = {
|
||||
filterText: "",
|
||||
};
|
||||
|
||||
/** Registry for OAuth resume snapshot restore (data-only; setters live in App). */
|
||||
export const TAB_UI_REGISTRY = {
|
||||
Apps: { empty: EMPTY_APPS_UI },
|
||||
|
|
|
|||
Loading…
Reference in a new issue