Phase 1: Refactor all 16 element component interfaces to use MCP SDK types

Replace ad-hoc local type definitions in element components with real
MCP SDK types and Inspector wrapper types from core/mcp/types.ts:

Schema-typed primitives:
- LogLevelBadge: LogLevel → LoggingLevel (SDK)
- TransportBadge: "stdio"|"http" → ServerType (core), add sse/streamable-http
- TaskStatusBadge: local TaskStatus → SDK TaskStatus (working/input_required/...)
- ServerStatusIndicator: inline union → ConnectionStatus (core), "failed"→"error"

MCP wrapper consumers:
- AnnotationBadge: label+variant → facet+value with SDK Role type
- CapabilityItem: name:string → capability:keyof ServerCapabilities|ClientCapabilities
- LogEntry: flat props → entry:{receivedAt:Date, params:LoggingMessageNotification["params"]}
- MessageBubble: flat props → message:SamplingMessage|PromptMessage
- ProgressDisplay: flat props → params:ProgressNotification["params"]

Composite-input elements:
- ContentViewer: type+content+mimeType → block:ContentBlock (SDK discriminated union)
- InlineError: message+details → error:{message,data?}
- ConnectionToggle: checked+loading+onChange → status:ConnectionStatus+onConnect/onDisconnect

Also updates all group/screen/view consumers to keep the build green,
and renames CSS variable --inspector-status-failed → --inspector-status-error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
cliffhall 2026-04-16 22:25:23 -04:00
commit 2d4fca4fa6
2 changed files with 905 additions and 648 deletions

View file

@ -11,77 +11,66 @@ type Story = StoryObj<typeof ContentViewer>;
export const PlainText: Story = {
args: {
type: "text",
content: "Hello, world!\nThis is plain text.",
block: { type: "text", text: "Hello, world!\nThis is plain text." },
},
};
export const JsonContent: Story = {
args: {
type: "json",
content:
'{"name":"my-app","version":"1.0.0","description":"Sample configuration file"}',
block: {
type: "text",
text: '{"name":"my-app","version":"1.0.0","description":"Sample configuration file"}',
},
},
};
export const ImagePreview: Story = {
args: {
type: "image",
content:
"iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAABWUlEQVR4nO3YsQnAMAwAQe+/dLKCRZpD+UA6cVh8p/Oc81z9t1/eJ+/oD/ybVxDM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: {
type: "json",
content: JSON.stringify({
name: "my-app",
version: "2.5.0",
description: "A comprehensive application configuration",
author: "Inspector Team",
license: "MIT",
repository: "https://github.com/example/my-app",
dependencies: {
react: "^18.0.0",
typescript: "^5.0.0",
mantine: "^7.0.0",
},
devDependencies: {
vitest: "^1.0.0",
storybook: "^8.0.0",
eslint: "^9.0.0",
},
scripts: {
dev: "vite",
build: "tsc && vite build",
test: "vitest",
lint: "eslint .",
},
settings: {
theme: "dark",
language: "en",
notifications: true,
maxRetries: 3,
},
}),
block: {
type: "text",
text: JSON.stringify({
name: "my-app",
version: "2.5.0",
description: "A comprehensive application configuration",
dependencies: {
react: "^18.0.0",
typescript: "^5.0.0",
},
scripts: {
dev: "vite",
build: "tsc && vite build",
},
}),
},
},
};
export const WithCopyButton: Story = {
args: {
type: "text",
content: "Hello, world!\nThis text can be copied.",
block: {
type: "text",
text: "Hello, world!\nThis text can be copied.",
},
copyable: true,
},
};
export const JsonWithCopy: Story = {
args: {
type: "json",
content:
'{"name":"my-app","version":"1.0.0","description":"Sample configuration file"}',
block: {
type: "text",
text: '{"name":"my-app","version":"1.0.0","description":"Sample configuration file"}',
},
copyable: true,
},
};

View file

@ -1,10 +1,9 @@
import { Code, Flex, Image, Stack } from "@mantine/core";
import { Code, Flex, Image, Stack, Text } from "@mantine/core";
import type { ContentBlock } from "@modelcontextprotocol/sdk/types.js";
import { CopyButton } from "../CopyButton/CopyButton";
export interface ContentViewerProps {
type: "text" | "json" | "image" | "audio";
content: string;
mimeType?: string;
block: ContentBlock;
copyable?: boolean;
}
@ -16,12 +15,24 @@ function formatJson(content: string): string {
}
}
function buildDataUri(mimeType: string, content: string): string {
return `data:${mimeType};base64,${content}`;
function isJsonText(block: ContentBlock): boolean {
if (block.type !== "text") return false;
if (
"annotations" in block &&
block.annotations &&
"mimeType" in block.annotations
) {
return (
(block.annotations as Record<string, unknown>).mimeType ===
"application/json"
);
}
const trimmed = block.text.trimStart();
return trimmed.startsWith("{") || trimmed.startsWith("[");
}
function formatContent(type: "text" | "json", content: string): string {
return type === "json" ? formatJson(content) : content;
function buildDataUri(mimeType: string, data: string): string {
return `data:${mimeType};base64,${data}`;
}
const ContentWrapper = Flex.withProps({
@ -41,36 +52,61 @@ const PreviewImage = Image.withProps({
radius: "md",
});
export function ContentViewer({
type,
content,
mimeType,
copyable = false,
}: ContentViewerProps) {
const showCopy = copyable && (type === "text" || type === "json");
return (
<Stack gap="xs">
{(type === "json" || type === "text") && (
<ContentWrapper>
<Code block p={36}>
{formatContent(type, content)}
</Code>
{showCopy && (
<CopyOverlay>
<CopyButton value={content} />
</CopyOverlay>
)}
</ContentWrapper>
)}
{type === "image" && (
<PreviewImage src={buildDataUri(mimeType || "image/png", content)} />
)}
{type === "audio" && (
<audio controls>
<source src={buildDataUri(mimeType || "audio/wav", content)} />
</audio>
)}
</Stack>
);
export function ContentViewer({ block, copyable = false }: ContentViewerProps) {
switch (block.type) {
case "text": {
const isJson = isJsonText(block);
const displayText = isJson ? formatJson(block.text) : block.text;
return (
<Stack gap="xs">
<ContentWrapper>
<Code block p={36}>
{displayText}
</Code>
{copyable && (
<CopyOverlay>
<CopyButton value={block.text} />
</CopyOverlay>
)}
</ContentWrapper>
</Stack>
);
}
case "image":
return (
<Stack gap="xs">
<PreviewImage src={buildDataUri(block.mimeType, block.data)} />
</Stack>
);
case "audio":
return (
<Stack gap="xs">
<audio controls>
<source src={buildDataUri(block.mimeType, block.data)} />
</audio>
</Stack>
);
case "resource":
return (
<Stack gap="xs">
<ContentWrapper>
<Code block p={36}>
{"text" in block.resource
? block.resource.text
: `[blob: ${block.resource.uri}]`}
</Code>
</ContentWrapper>
</Stack>
);
case "resource_link":
return (
<Stack gap="xs">
<Text size="sm" c="blue">
{block.name ?? block.uri}
</Text>
</Stack>
);
default:
return null;
}
}