refactor(web): rename "History" tab/feature to "Protocol" (#1623)
Rename the web client's History tab and its supporting code to Protocol so the feature reads as the MCP "Protocol" view. - Tab renders as "Protocol"; INSPECTOR_TAB_IDS, InspectorView tab constants/MonitorTab, TAB_UI_REGISTRY key, and navigation.ts tab id all updated to Protocol. - Rename components + folders: HistoryScreen -> ProtocolScreen, HistoryListPanel -> ProtocolListPanel, HistoryEntry -> ProtocolEntry, HistoryControls -> ProtocolControls, historyUtils -> protocolUtils (plus their tests and stories, and exported types). - Rename App/InspectorView plumbing: historyUi, pinnedHistoryIds, on*History* handlers/props, replayHistoryRequest, isReplayableHistoryMethod, sort/compact scopes, etc. -> Protocol names. - Export filenames use the "protocol" slug (buildExportFilename + ExportKind). Preserved (per issue #1623 decisions): - The in-panel section discriminator keeps its "pinned" | "history" values, and the sub-sections stay labeled Pinned / History. - window.history and core message-log/replay concepts are untouched. npm run ci passes (format, lint, build, unit tests, >=90 per-file coverage gate, smoke, Storybook). 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
0fde2d0024
commit
ace4250d31
6 changed files with 413 additions and 405 deletions
|
|
@ -0,0 +1,167 @@
|
|||
import { useState } from "react";
|
||||
import type { ComponentProps } from "react";
|
||||
import type { Meta, StoryObj } from "@storybook/react-vite";
|
||||
import type { MessageEntry } from "../../../../../../core/mcp/types.js";
|
||||
import { expect, fn, screen, userEvent, within } from "storybook/test";
|
||||
import { ProtocolScreen } from "./ProtocolScreen";
|
||||
import { EMPTY_PROTOCOL_UI } from "../screenUiState";
|
||||
|
||||
// ProtocolScreen is controlled (search text + method filter live in the parent
|
||||
// as one `ui` object — see #1417). This wrapper holds that state so the
|
||||
// play-driven filter selection and clear-all reset are observable, mirroring
|
||||
// how App owns the state.
|
||||
function StatefulProtocolScreen(args: ComponentProps<typeof ProtocolScreen>) {
|
||||
const [ui, setUi] = useState({ ...EMPTY_PROTOCOL_UI, ...args.ui });
|
||||
return <ProtocolScreen {...args} ui={ui} onUiChange={setUi} />;
|
||||
}
|
||||
|
||||
const meta: Meta<typeof ProtocolScreen> = {
|
||||
title: "Screens/ProtocolScreen",
|
||||
component: ProtocolScreen,
|
||||
parameters: { layout: "fullscreen" },
|
||||
args: {
|
||||
pinnedIds: new Set<string>(),
|
||||
onClearAll: fn(),
|
||||
onExport: fn(),
|
||||
onReplay: fn(),
|
||||
onTogglePin: fn(),
|
||||
ui: EMPTY_PROTOCOL_UI,
|
||||
onUiChange: fn(),
|
||||
sortDirection: "newest-first",
|
||||
onSortChange: fn(),
|
||||
compact: true,
|
||||
onToggleCompact: fn(),
|
||||
},
|
||||
render: (args) => <StatefulProtocolScreen {...args} />,
|
||||
};
|
||||
|
||||
export default meta;
|
||||
type Story = StoryObj<typeof ProtocolScreen>;
|
||||
|
||||
const sampleEntries: MessageEntry[] = [
|
||||
{
|
||||
id: "req-1",
|
||||
timestamp: new Date("2026-03-17T10:00:00Z"),
|
||||
direction: "request",
|
||||
message: {
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
method: "tools/call",
|
||||
params: { name: "send_message", arguments: { message: "Hello, world!" } },
|
||||
},
|
||||
response: {
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
result: {
|
||||
content: [{ type: "text", text: "Message sent successfully" }],
|
||||
},
|
||||
},
|
||||
duration: 120,
|
||||
},
|
||||
{
|
||||
id: "req-2",
|
||||
timestamp: new Date("2026-03-17T10:01:00Z"),
|
||||
direction: "request",
|
||||
message: {
|
||||
jsonrpc: "2.0",
|
||||
id: 2,
|
||||
method: "resources/read",
|
||||
params: { uri: "file:///config.json" },
|
||||
},
|
||||
response: {
|
||||
jsonrpc: "2.0",
|
||||
id: 2,
|
||||
result: {
|
||||
contents: [{ uri: "file:///config.json", text: "{}" }],
|
||||
},
|
||||
},
|
||||
duration: 45,
|
||||
},
|
||||
{
|
||||
id: "req-3",
|
||||
timestamp: new Date("2026-03-17T10:02:00Z"),
|
||||
direction: "request",
|
||||
message: {
|
||||
jsonrpc: "2.0",
|
||||
id: 3,
|
||||
method: "tools/call",
|
||||
params: { name: "delete_records", arguments: { ids: [1, 2, 3] } },
|
||||
},
|
||||
response: {
|
||||
jsonrpc: "2.0",
|
||||
id: 3,
|
||||
error: { code: -32000, message: "Permission denied" },
|
||||
},
|
||||
duration: 350,
|
||||
},
|
||||
{
|
||||
id: "req-4",
|
||||
timestamp: new Date("2026-03-17T09:30:00Z"),
|
||||
direction: "request",
|
||||
message: {
|
||||
jsonrpc: "2.0",
|
||||
id: 4,
|
||||
method: "tools/list",
|
||||
},
|
||||
response: {
|
||||
jsonrpc: "2.0",
|
||||
id: 4,
|
||||
result: { tools: [] },
|
||||
},
|
||||
duration: 80,
|
||||
},
|
||||
{
|
||||
id: "req-5",
|
||||
timestamp: new Date("2026-03-17T09:35:00Z"),
|
||||
direction: "request",
|
||||
message: {
|
||||
jsonrpc: "2.0",
|
||||
id: 5,
|
||||
method: "prompts/get",
|
||||
params: { name: "greeting" },
|
||||
},
|
||||
response: {
|
||||
jsonrpc: "2.0",
|
||||
id: 5,
|
||||
result: {
|
||||
messages: [{ role: "user", content: { type: "text", text: "Hello!" } }],
|
||||
},
|
||||
},
|
||||
duration: 60,
|
||||
},
|
||||
];
|
||||
|
||||
export const WithEntries: Story = {
|
||||
args: {
|
||||
entries: sampleEntries,
|
||||
pinnedIds: new Set(["req-4", "req-5"]),
|
||||
},
|
||||
};
|
||||
|
||||
export const Empty: Story = {
|
||||
args: {
|
||||
entries: [],
|
||||
},
|
||||
};
|
||||
|
||||
export const MethodFilterClearedOnClearAll: Story = {
|
||||
args: {
|
||||
entries: sampleEntries,
|
||||
pinnedIds: new Set<string>(),
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
const filter = canvas.getByPlaceholderText(
|
||||
"All methods",
|
||||
) as HTMLInputElement;
|
||||
|
||||
await userEvent.click(filter);
|
||||
await userEvent.click(
|
||||
await screen.findByRole("option", { name: "tools/call" }),
|
||||
);
|
||||
await expect(filter).toHaveValue("tools/call");
|
||||
|
||||
await userEvent.click(canvas.getByRole("button", { name: /^clear$/i }));
|
||||
await expect(filter).toHaveValue("");
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
import { describe, it, expect, vi } from "vitest";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import type { MessageEntry } from "@inspector/core/mcp/types.js";
|
||||
import { renderWithMantine, screen } from "../../../test/renderWithMantine";
|
||||
import { ProtocolScreen } from "./ProtocolScreen";
|
||||
import { EMPTY_PROTOCOL_UI } from "../screenUiState";
|
||||
|
||||
const sampleEntries: MessageEntry[] = [
|
||||
{
|
||||
id: "1",
|
||||
timestamp: new Date(),
|
||||
direction: "request",
|
||||
message: { jsonrpc: "2.0", id: 1, method: "tools/list" },
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
timestamp: new Date(),
|
||||
direction: "response",
|
||||
message: { jsonrpc: "2.0", id: 1, result: {} },
|
||||
},
|
||||
];
|
||||
|
||||
const baseProps = {
|
||||
entries: sampleEntries,
|
||||
pinnedIds: new Set<string>(),
|
||||
ui: EMPTY_PROTOCOL_UI,
|
||||
onUiChange: vi.fn(),
|
||||
onClearAll: vi.fn(),
|
||||
onExport: vi.fn(),
|
||||
onClearSection: vi.fn(),
|
||||
onExportSection: vi.fn(),
|
||||
onReplay: vi.fn(),
|
||||
onTogglePin: vi.fn(),
|
||||
sortDirection: "newest-first" as const,
|
||||
onSortChange: vi.fn(),
|
||||
compact: true,
|
||||
onToggleCompact: vi.fn(),
|
||||
};
|
||||
|
||||
describe("ProtocolScreen", () => {
|
||||
it("renders the controls and panel", () => {
|
||||
renderWithMantine(<ProtocolScreen {...baseProps} />);
|
||||
expect(screen.getByText("Protocol")).toBeInTheDocument();
|
||||
expect(screen.getByPlaceholderText("Search...")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders empty state when there are no entries", () => {
|
||||
renderWithMantine(<ProtocolScreen {...baseProps} entries={[]} />);
|
||||
expect(screen.getByText("Protocol")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("invokes onClearAll when clear is triggered", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onClearAll = vi.fn();
|
||||
renderWithMantine(
|
||||
<ProtocolScreen {...baseProps} onClearAll={onClearAll} />,
|
||||
);
|
||||
const clearButton = screen.getByRole("button", { name: /Clear/ });
|
||||
await user.click(clearButton);
|
||||
expect(onClearAll).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("emits the search text through onUiChange", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onUiChange = vi.fn();
|
||||
renderWithMantine(
|
||||
<ProtocolScreen {...baseProps} onUiChange={onUiChange} />,
|
||||
);
|
||||
await user.type(screen.getByPlaceholderText("Search..."), "t");
|
||||
expect(onUiChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ search: "t" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("toggles a single message direction through onUiChange", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onUiChange = vi.fn();
|
||||
renderWithMantine(
|
||||
<ProtocolScreen {...baseProps} onUiChange={onUiChange} />,
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "client ← server" }));
|
||||
expect(onUiChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
visibleDirections: { client: true, server: false },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("toggles all message directions off through onUiChange", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onUiChange = vi.fn();
|
||||
renderWithMantine(
|
||||
<ProtocolScreen {...baseProps} onUiChange={onUiChange} />,
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "Deselect All" }));
|
||||
expect(onUiChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
visibleDirections: { client: false, server: false },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("emits the cleared method filter through onUiChange", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onUiChange = vi.fn();
|
||||
const { container } = renderWithMantine(
|
||||
<ProtocolScreen
|
||||
{...baseProps}
|
||||
ui={{ ...EMPTY_PROTOCOL_UI, methodFilter: "tools/list" }}
|
||||
onUiChange={onUiChange}
|
||||
/>,
|
||||
);
|
||||
const clearButton = container.querySelector(
|
||||
"button.mantine-InputClearButton-root",
|
||||
) as HTMLButtonElement | null;
|
||||
expect(clearButton).not.toBeNull();
|
||||
await user.click(clearButton!);
|
||||
expect(onUiChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ methodFilter: undefined }),
|
||||
);
|
||||
});
|
||||
|
||||
it("renders a pin-as-column button when onPin is provided and invokes it", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onPin = vi.fn();
|
||||
renderWithMantine(<ProtocolScreen {...baseProps} onPin={onPin} />);
|
||||
await user.click(screen.getByRole("button", { name: "Pin as column" }));
|
||||
expect(onPin).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("drops the filter sidebar when embedded, keeping the request list", () => {
|
||||
renderWithMantine(<ProtocolScreen {...baseProps} embedded />);
|
||||
expect(screen.getByText("Requests")).toBeInTheDocument();
|
||||
// The sidebar (ProtocolControls, with its Search box) is not rendered.
|
||||
expect(screen.queryByPlaceholderText("Search...")).toBeNull();
|
||||
});
|
||||
|
||||
it("applies the search text but ignores the method filter when embedded", () => {
|
||||
renderWithMantine(
|
||||
<ProtocolScreen
|
||||
{...baseProps}
|
||||
ui={{
|
||||
...EMPTY_PROTOCOL_UI,
|
||||
// Method filter would exclude the tools/list entries on the full-size
|
||||
// screen...
|
||||
methodFilter: "resources/list",
|
||||
// ...but the column search matches them.
|
||||
search: "tools",
|
||||
}}
|
||||
embedded
|
||||
/>,
|
||||
);
|
||||
expect(screen.queryByText("No request history")).toBeNull();
|
||||
});
|
||||
|
||||
it("hides entries not matching the column search when embedded", () => {
|
||||
renderWithMantine(
|
||||
<ProtocolScreen
|
||||
{...baseProps}
|
||||
ui={{ ...EMPTY_PROTOCOL_UI, search: "zzz-no-match" }}
|
||||
embedded
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText("No request history")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
import { useCallback, useMemo } from "react";
|
||||
import { Card, Flex, Stack } from "@mantine/core";
|
||||
import type {
|
||||
MessageEntry,
|
||||
MessageMethod,
|
||||
MessageOrigin,
|
||||
} from "@inspector/core/mcp/types.js";
|
||||
import { ProtocolControls } from "../../groups/ProtocolControls/ProtocolControls";
|
||||
import { ProtocolListPanel } from "../../groups/ProtocolListPanel/ProtocolListPanel.js";
|
||||
import { extractMethod } from "../../groups/protocolUtils.js";
|
||||
import type { SortDirection } from "../../elements/SortToggle/SortToggle";
|
||||
|
||||
export interface ProtocolScreenProps {
|
||||
entries: MessageEntry[];
|
||||
pinnedIds: Set<string>;
|
||||
ui: ProtocolUiState;
|
||||
onUiChange: (next: ProtocolUiState) => void;
|
||||
onClearAll: () => void;
|
||||
onExport: () => void;
|
||||
onClearSection: (section: "pinned" | "history") => void;
|
||||
onExportSection: (section: "pinned" | "history") => void;
|
||||
onReplay: (id: string) => void;
|
||||
onTogglePin: (id: string) => void;
|
||||
sortDirection: SortDirection;
|
||||
onSortChange: (next: SortDirection) => void;
|
||||
compact: boolean;
|
||||
onToggleCompact: () => 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;
|
||||
}
|
||||
|
||||
// Search text, method filter, and per-direction visibility — controlled by the
|
||||
// parent (App) as one object so they persist across tab navigation within a
|
||||
// live session (#1417).
|
||||
export interface ProtocolUiState {
|
||||
search: string;
|
||||
methodFilter?: MessageMethod;
|
||||
/** Which message directions are shown, keyed by entry origin. */
|
||||
visibleDirections: Record<MessageOrigin, boolean>;
|
||||
}
|
||||
|
||||
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",
|
||||
});
|
||||
|
||||
export function ProtocolScreen({
|
||||
entries,
|
||||
pinnedIds,
|
||||
ui,
|
||||
onUiChange,
|
||||
onClearAll,
|
||||
onExport,
|
||||
onClearSection,
|
||||
onExportSection,
|
||||
onReplay,
|
||||
onTogglePin,
|
||||
sortDirection,
|
||||
onSortChange,
|
||||
compact,
|
||||
onToggleCompact,
|
||||
onPin,
|
||||
embedded = false,
|
||||
}: ProtocolScreenProps) {
|
||||
const { search, methodFilter, visibleDirections } = ui;
|
||||
|
||||
const availableMethods = useMemo(
|
||||
() => Array.from(new Set(entries.map(extractMethod))).sort(),
|
||||
[entries],
|
||||
);
|
||||
|
||||
const handleClearAll = useCallback(() => {
|
||||
onUiChange({ ...ui, methodFilter: undefined });
|
||||
onClearAll();
|
||||
}, [ui, onUiChange, onClearAll]);
|
||||
|
||||
const handleToggleDirection = useCallback(
|
||||
(direction: MessageOrigin, visible: boolean) => {
|
||||
onUiChange({
|
||||
...ui,
|
||||
visibleDirections: { ...visibleDirections, [direction]: visible },
|
||||
});
|
||||
},
|
||||
[ui, visibleDirections, onUiChange],
|
||||
);
|
||||
|
||||
const handleToggleAllDirections = useCallback(() => {
|
||||
const next = !Object.values(visibleDirections).every(Boolean);
|
||||
onUiChange({
|
||||
...ui,
|
||||
visibleDirections: { client: next, server: next },
|
||||
});
|
||||
}, [ui, visibleDirections, onUiChange]);
|
||||
|
||||
return (
|
||||
<ScreenLayout h={embedded ? "100%" : undefined}>
|
||||
{embedded ? null : (
|
||||
<Sidebar>
|
||||
<SidebarCard>
|
||||
<ProtocolControls
|
||||
searchText={search}
|
||||
methodFilter={methodFilter}
|
||||
availableMethods={availableMethods}
|
||||
visibleDirections={visibleDirections}
|
||||
onSearchChange={(value) => onUiChange({ ...ui, search: value })}
|
||||
onMethodFilterChange={(value) =>
|
||||
onUiChange({ ...ui, methodFilter: value })
|
||||
}
|
||||
onToggleDirection={handleToggleDirection}
|
||||
onToggleAllDirections={handleToggleAllDirections}
|
||||
/>
|
||||
</SidebarCard>
|
||||
</Sidebar>
|
||||
)}
|
||||
<ProtocolListPanel
|
||||
entries={entries}
|
||||
pinnedIds={pinnedIds}
|
||||
searchText={search}
|
||||
methodFilter={methodFilter}
|
||||
visibleDirections={visibleDirections}
|
||||
onClearAll={handleClearAll}
|
||||
onExport={onExport}
|
||||
onClearSection={onClearSection}
|
||||
onExportSection={onExportSection}
|
||||
onReplay={onReplay}
|
||||
onTogglePin={onTogglePin}
|
||||
sortDirection={sortDirection}
|
||||
onSortChange={onSortChange}
|
||||
compact={compact}
|
||||
onToggleCompact={onToggleCompact}
|
||||
onPin={onPin}
|
||||
embedded={embedded}
|
||||
/>
|
||||
</ScreenLayout>
|
||||
);
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ export const MultipleServers: Story = {
|
|||
servers: [connectedStdioServer, disconnectedStdioServer, failedHttpServer],
|
||||
},
|
||||
// The server grid scroll region reserves a scrollbar gutter and hides the
|
||||
// bar when idle, matching the History/Network/Logging list panels (#1474).
|
||||
// bar when idle, matching the Protocol/Network/Logging list panels (#1474).
|
||||
play: async ({ canvasElement }) => {
|
||||
expectScrollbarGutterIdleHidden(canvasElement);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ export function ServerListScreen({
|
|||
|
||||
<ScrollArea.Autosize
|
||||
mah="calc(100dvh - var(--app-shell-header-height, 60px) - var(--mantine-spacing-xl) * 2 - 60px)"
|
||||
// Same scrollbar treatment as the History/Network/Logging list panels
|
||||
// Same scrollbar treatment as the Protocol/Network/Logging list panels
|
||||
// (#1474): reserve a gutter so the bar never overlays the right edge of
|
||||
// the server cards (occluding their action icons / status badges), and
|
||||
// only show it while actively scrolling rather than popping in on hover.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import type { ResourcesUiState } from "./ResourcesScreen/ResourcesScreen";
|
|||
import type { AppsUiState } from "./AppsScreen/AppsScreen";
|
||||
import type { TasksUiState } from "./TasksScreen/TasksScreen";
|
||||
import type { LogsUiState } from "./LoggingScreen/LoggingScreen";
|
||||
import type { HistoryUiState } from "./HistoryScreen/HistoryScreen";
|
||||
import type { ProtocolUiState } from "./ProtocolScreen/ProtocolScreen";
|
||||
import type { NetworkUiState } from "./NetworkScreen/NetworkScreen";
|
||||
import type { ConsoleUiState } from "./ConsoleScreen/ConsoleScreen";
|
||||
import { ALL_LEVELS_VISIBLE } from "./LoggingScreen/logLevels";
|
||||
|
|
@ -53,7 +53,7 @@ export const EMPTY_LOGS_UI: LogsUiState = {
|
|||
visibleLevels: ALL_LEVELS_VISIBLE,
|
||||
};
|
||||
|
||||
export const EMPTY_HISTORY_UI: HistoryUiState = {
|
||||
export const EMPTY_PROTOCOL_UI: ProtocolUiState = {
|
||||
search: "",
|
||||
methodFilter: undefined,
|
||||
visibleDirections: { client: true, server: true },
|
||||
|
|
@ -76,6 +76,6 @@ export const TAB_UI_REGISTRY = {
|
|||
Resources: { empty: EMPTY_RESOURCES_UI },
|
||||
Tasks: { empty: EMPTY_TASKS_UI },
|
||||
Logs: { empty: EMPTY_LOGS_UI },
|
||||
History: { empty: EMPTY_HISTORY_UI },
|
||||
Protocol: { empty: EMPTY_PROTOCOL_UI },
|
||||
Network: { empty: EMPTY_NETWORK_UI },
|
||||
} as const;
|
||||
|
|
|
|||
Loading…
Reference in a new issue