Phase 2: Refactor Logs cluster to MCP SDK types

Replace string-typed log levels with SDK LoggingLevel across the Logs
group components and LoggingScreen.

- LogControls: type currentLevel, visibleLevels, and all handlers with
  LoggingLevel instead of string; type LOG_LEVELS array and LEVEL_COLORS
  record with LoggingLevel
- LogStreamPanel: type visibleLevels as Record<LoggingLevel, boolean>
  instead of Record<string, boolean>
- LoggingScreen: type currentLevel, onSetLevel, visibleLevels state,
  and toggle handlers with LoggingLevel; extract NO_LEVELS_VISIBLE as
  a module-level constant
- Stories already used LoggingLevel literals; updated type annotations
  to use Record<LoggingLevel, boolean>
- No ConnectedView story changes needed (already passes valid
  LoggingLevel values)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
cliffhall 2026-04-18 19:39:19 -04:00
commit 95e3a2dca7
3 changed files with 31 additions and 20 deletions

View file

@ -1,8 +1,9 @@
import type { Meta, StoryObj } from "@storybook/react-vite";
import type { LoggingLevel } from "@modelcontextprotocol/sdk/types.js";
import { fn } from "storybook/test";
import { LogControls } from "./LogControls";
const allLevelsVisible: Record<string, boolean> = {
const allLevelsVisible: Record<LoggingLevel, boolean> = {
debug: true,
info: true,
notice: true,

View file

@ -8,8 +8,9 @@ import {
Title,
UnstyledButton,
} from "@mantine/core";
import type { LoggingLevel } from "@modelcontextprotocol/sdk/types.js";
const LOG_LEVELS = [
const LOG_LEVELS: LoggingLevel[] = [
"debug",
"info",
"notice",
@ -18,9 +19,9 @@ const LOG_LEVELS = [
"critical",
"alert",
"emergency",
] as const;
];
const LEVEL_COLORS: Record<string, { c: string }> = {
const LEVEL_COLORS: Record<LoggingLevel, { c: string }> = {
debug: { c: "dimmed" },
info: { c: "blue" },
notice: { c: "teal" },
@ -37,12 +38,12 @@ const SubtleButton = Button.withProps({
});
export interface LogControlsProps {
currentLevel: string;
currentLevel: LoggingLevel;
filterText: string;
visibleLevels: Record<string, boolean>;
onSetLevel: (level: string) => void;
visibleLevels: Record<LoggingLevel, boolean>;
onSetLevel: (level: LoggingLevel) => void;
onFilterChange: (text: string) => void;
onToggleLevel: (level: string, visible: boolean) => void;
onToggleLevel: (level: LoggingLevel, visible: boolean) => void;
onToggleAllLevels: () => void;
}
@ -72,7 +73,7 @@ export function LogControls({
data={LOG_LEVELS.map((level) => ({ value: level, label: level }))}
value={currentLevel}
onChange={(value) => {
if (value) onSetLevel(value);
if (value) onSetLevel(value as LoggingLevel);
}}
/>
<Button size="sm" onClick={() => onSetLevel(currentLevel)}>

View file

@ -9,13 +9,14 @@ import {
Text,
Title,
} from "@mantine/core";
import type { LoggingLevel } from "@modelcontextprotocol/sdk/types.js";
import { LogEntry } from "../../elements/LogEntry/LogEntry";
import type { LogEntryData } from "../../elements/LogEntry/LogEntry";
export interface LogStreamPanelProps {
entries: LogEntryData[];
filterText: string;
visibleLevels: Record<string, boolean>;
visibleLevels: Record<LoggingLevel, boolean>;
autoScroll: boolean;
onToggleAutoScroll: () => void;
onCopyAll: () => void;
@ -50,7 +51,7 @@ function formatData(data: unknown): string {
function matchesFilters(
entry: LogEntryData,
filterText: string,
visibleLevels: Record<string, boolean>,
visibleLevels: Record<LoggingLevel, boolean>,
): boolean {
if (!visibleLevels[entry.params.level]) return false;
if (filterText) {