Merge pull request #1211 from modelcontextprotocol/v2/phase-1-elements
Phase 1: Refactor element component interfaces to MCP SDK types
This commit is contained in:
commit
9082e02e65
69 changed files with 1070 additions and 712 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,6 +1,7 @@
|
|||
.idea
|
||||
.vscode
|
||||
.DS_Store
|
||||
.claude/
|
||||
node_modules
|
||||
dist
|
||||
.env
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { Preview } from '@storybook/react-vite'
|
||||
import { MantineProvider, useMantineColorScheme } from '@mantine/core'
|
||||
import { MantineProvider, useMantineColorScheme, type CSSVariablesResolver } from '@mantine/core'
|
||||
import { Notifications } from '@mantine/notifications'
|
||||
import '@mantine/core/styles.css'
|
||||
import '@mantine/notifications/styles.css'
|
||||
|
|
@ -24,6 +24,14 @@ function ColorSchemeWrapper({
|
|||
return <>{children}</>
|
||||
}
|
||||
|
||||
const resolver: CSSVariablesResolver = () => ({
|
||||
variables: {},
|
||||
light: {},
|
||||
dark: {
|
||||
'--mantine-color-body': 'var(--mantine-color-dark-9)',
|
||||
},
|
||||
})
|
||||
|
||||
const preview: Preview = {
|
||||
globalTypes: {
|
||||
colorScheme: {
|
||||
|
|
@ -46,7 +54,7 @@ const preview: Preview = {
|
|||
(Story, context) => {
|
||||
const isFullscreen = context.parameters?.layout === 'fullscreen'
|
||||
return (
|
||||
<MantineProvider theme={theme} defaultColorScheme="light">
|
||||
<MantineProvider theme={theme} defaultColorScheme="light" cssVariablesResolver={resolver}>
|
||||
<ColorSchemeWrapper colorScheme={context.globals.colorScheme ?? 'light'}>
|
||||
<Notifications position="top-right" />
|
||||
{isFullscreen ? (
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@
|
|||
--inspector-surface-card: var(--mantine-color-gray-0);
|
||||
--inspector-surface-code: var(--mantine-color-white);
|
||||
|
||||
/* ── Inputs ────────────────────────────────────────────── */
|
||||
--inspector-input-background: var(--mantine-color-white);
|
||||
|
||||
/* ── Borders ───────────────────────────────────────────── */
|
||||
--inspector-border-default: var(--mantine-color-default-border);
|
||||
--inspector-border-subtle: var(--mantine-color-gray-3);
|
||||
|
|
@ -34,7 +37,7 @@
|
|||
--inspector-status-connected: var(--mantine-color-green-6);
|
||||
--inspector-status-connecting: var(--mantine-color-yellow-6);
|
||||
--inspector-status-disconnected: var(--mantine-color-gray-5);
|
||||
--inspector-status-failed: var(--mantine-color-red-6);
|
||||
--inspector-status-error: var(--mantine-color-red-6);
|
||||
|
||||
/* ── Log levels (RFC 5424) ─────────────────────────────── */
|
||||
--inspector-log-debug: var(--mantine-color-gray-6);
|
||||
|
|
@ -46,15 +49,6 @@
|
|||
--inspector-log-alert: var(--mantine-color-red-9);
|
||||
--inspector-log-emergency: var(--mantine-color-red-9);
|
||||
|
||||
/* ── Annotations ───────────────────────────────────────── */
|
||||
--inspector-annotation-destructive: var(--mantine-color-red-6);
|
||||
--inspector-annotation-long-run: var(--mantine-color-yellow-6);
|
||||
--inspector-annotation-read-only: var(--mantine-color-dark-6);
|
||||
--inspector-annotation-audience: var(--mantine-color-gray-6);
|
||||
--inspector-annotation-priority-high: var(--mantine-color-orange-6);
|
||||
--inspector-annotation-priority-medium: var(--mantine-color-yellow-6);
|
||||
--inspector-annotation-priority-low: var(--mantine-color-green-6);
|
||||
|
||||
/* ── Task status ───────────────────────────────────────── */
|
||||
--inspector-task-waiting: var(--mantine-color-gray-5);
|
||||
--inspector-task-running: var(--mantine-color-blue-6);
|
||||
|
|
@ -71,7 +65,8 @@
|
|||
[data-mantine-color-scheme="dark"] {
|
||||
--inspector-surface-card: var(--mantine-color-gray-9);
|
||||
--inspector-surface-code: var(--mantine-color-dark-9);
|
||||
--inspector-border-subtle: var(--mantine-color-dark-4);
|
||||
--inspector-border-subtle: var(--mantine-color-gray-4);
|
||||
--inspector-input-background: var(--mantine-color-dark-9);
|
||||
}
|
||||
|
||||
/* ── Animations ──────────────────────────────────────────── */
|
||||
|
|
@ -108,11 +103,43 @@
|
|||
/* ── List item hover ────────────────────────────────────── */
|
||||
|
||||
.list-item:hover {
|
||||
background-color: var(--mantine-color-gray-1);
|
||||
background-color: var(--mantine-primary-color-light);
|
||||
}
|
||||
|
||||
[data-mantine-color-scheme="dark"] .list-item:hover {
|
||||
background-color: var(--mantine-color-dark-5);
|
||||
background-color: var(--mantine-primary-color-light);
|
||||
}
|
||||
|
||||
/* ── Select dropdown / option (dark mode) ──────────────────────── */
|
||||
|
||||
[data-mantine-color-scheme="dark"] .mantine-Select-dropdown {
|
||||
background-color: var(--mantine-color-gray-8);
|
||||
}
|
||||
|
||||
[data-mantine-color-scheme="dark"] .mantine-Select-option:hover {
|
||||
background-color: var(--mantine-primary-color-light);
|
||||
}
|
||||
|
||||
/* ── Menu dropdown / option (dark mode) ──────────────────────── */
|
||||
|
||||
[data-mantine-color-scheme="dark"] .mantine-Menu-dropdown {
|
||||
background-color: var(--mantine-color-gray-8);
|
||||
}
|
||||
|
||||
[data-mantine-color-scheme="dark"] .mantine-Menu-item:hover {
|
||||
background-color: var(--mantine-primary-color-light);
|
||||
}
|
||||
|
||||
/* ── Segmented control label (dark mode) ──────────────────────── */
|
||||
|
||||
[data-mantine-color-scheme="dark"] .mantine-SegmentedControl-indicator {
|
||||
background-color: var(--mantine-primary-color-light);
|
||||
}
|
||||
|
||||
/* ── Accordion button hover ─────────────────────────────── */
|
||||
|
||||
.mantine-Accordion-control:hover {
|
||||
background-color: var(--mantine-primary-color-light-hover);
|
||||
}
|
||||
|
||||
/* ── Grid alignment ─────────────────────────────────────── */
|
||||
|
|
|
|||
|
|
@ -11,42 +11,63 @@ type Story = StoryObj<typeof AnnotationBadge>;
|
|||
|
||||
export const Audience: Story = {
|
||||
args: {
|
||||
label: "user",
|
||||
variant: "audience",
|
||||
facet: "audience",
|
||||
value: ["user"],
|
||||
},
|
||||
};
|
||||
|
||||
export const AudienceMultiple: Story = {
|
||||
args: {
|
||||
facet: "audience",
|
||||
value: ["user", "assistant"],
|
||||
},
|
||||
};
|
||||
|
||||
export const ReadOnly: Story = {
|
||||
args: {
|
||||
label: "read-only",
|
||||
variant: "readOnly",
|
||||
facet: "readOnlyHint",
|
||||
value: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const Destructive: Story = {
|
||||
args: {
|
||||
label: "destructive",
|
||||
variant: "destructive",
|
||||
facet: "destructiveHint",
|
||||
value: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const LongRun: Story = {
|
||||
export const Idempotent: Story = {
|
||||
args: {
|
||||
label: "long-run",
|
||||
variant: "longRun",
|
||||
facet: "idempotentHint",
|
||||
value: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const OpenWorld: Story = {
|
||||
args: {
|
||||
facet: "openWorldHint",
|
||||
value: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const LongRunning: Story = {
|
||||
args: {
|
||||
facet: "longRunHint",
|
||||
value: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const PriorityHigh: Story = {
|
||||
args: {
|
||||
label: "priority: high",
|
||||
variant: "priority",
|
||||
facet: "priority",
|
||||
value: 0.9,
|
||||
},
|
||||
};
|
||||
|
||||
export const Default: Story = {
|
||||
export const PriorityLow: Story = {
|
||||
args: {
|
||||
label: "custom",
|
||||
variant: "default",
|
||||
facet: "priority",
|
||||
value: 0.2,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,37 +1,63 @@
|
|||
import { Badge, useComputedColorScheme } from "@mantine/core";
|
||||
import type { Role } from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
export type AnnotationVariant =
|
||||
export type AnnotationFacet =
|
||||
| "audience"
|
||||
| "readOnly"
|
||||
| "destructive"
|
||||
| "longRun"
|
||||
| "priority"
|
||||
| "default";
|
||||
| "readOnlyHint"
|
||||
| "destructiveHint"
|
||||
| "idempotentHint"
|
||||
| "openWorldHint"
|
||||
| "longRunHint";
|
||||
|
||||
export interface AnnotationBadgeProps {
|
||||
label: string;
|
||||
variant?: AnnotationVariant;
|
||||
facet: AnnotationFacet;
|
||||
value: Role[] | number | boolean;
|
||||
}
|
||||
|
||||
const colorMap: Record<AnnotationVariant, string> = {
|
||||
const colorMap: Record<AnnotationFacet, string> = {
|
||||
audience: "blue",
|
||||
readOnly: "green",
|
||||
destructive: "red",
|
||||
longRun: "yellow",
|
||||
priority: "orange",
|
||||
default: "gray",
|
||||
readOnlyHint: "green",
|
||||
destructiveHint: "red",
|
||||
idempotentHint: "teal",
|
||||
openWorldHint: "grape",
|
||||
longRunHint: "yellow",
|
||||
};
|
||||
|
||||
export function AnnotationBadge({
|
||||
label,
|
||||
variant = "default",
|
||||
}: AnnotationBadgeProps) {
|
||||
function formatLabel(
|
||||
facet: AnnotationFacet,
|
||||
value: Role[] | number | boolean,
|
||||
): string {
|
||||
switch (facet) {
|
||||
case "audience":
|
||||
return `audience: ${(value as Role[]).join(", ")}`;
|
||||
case "priority": {
|
||||
const n = value as number;
|
||||
if (n >= 0.7) return "priority: high";
|
||||
if (n >= 0.4) return "priority: medium";
|
||||
return "priority: low";
|
||||
}
|
||||
case "readOnlyHint":
|
||||
return "read-only";
|
||||
case "destructiveHint":
|
||||
return "destructive";
|
||||
case "idempotentHint":
|
||||
return "idempotent";
|
||||
case "openWorldHint":
|
||||
return "open-world";
|
||||
case "longRunHint":
|
||||
return "long-running";
|
||||
}
|
||||
}
|
||||
|
||||
export function AnnotationBadge({ facet, value }: AnnotationBadgeProps) {
|
||||
const colorScheme = useComputedColorScheme();
|
||||
const color = colorMap[variant];
|
||||
const color = colorMap[facet];
|
||||
const textColor = colorScheme === "dark" ? "black" : "white";
|
||||
return (
|
||||
<Badge color={color} variant="filled" fw={500} c={textColor}>
|
||||
{label}
|
||||
{formatLabel(facet, value)}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ type Story = StoryObj<typeof CapabilityItem>;
|
|||
|
||||
export const Supported: Story = {
|
||||
args: {
|
||||
name: "Tools",
|
||||
capability: "tools",
|
||||
supported: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const SupportedWithCount: Story = {
|
||||
args: {
|
||||
name: "Tools",
|
||||
capability: "tools",
|
||||
supported: true,
|
||||
count: 4,
|
||||
},
|
||||
|
|
@ -26,7 +26,7 @@ export const SupportedWithCount: Story = {
|
|||
|
||||
export const NotSupported: Story = {
|
||||
args: {
|
||||
name: "Completions",
|
||||
capability: "completions",
|
||||
supported: false,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,16 +1,36 @@
|
|||
import { Group, Text } from "@mantine/core";
|
||||
import type {
|
||||
ClientCapabilities,
|
||||
ServerCapabilities,
|
||||
} from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
export type CapabilityKey = keyof ServerCapabilities | keyof ClientCapabilities;
|
||||
|
||||
export interface CapabilityItemProps {
|
||||
name: string;
|
||||
capability: CapabilityKey;
|
||||
supported: boolean;
|
||||
count?: number;
|
||||
}
|
||||
|
||||
const displayLabel: Record<string, string> = {
|
||||
tools: "Tools",
|
||||
resources: "Resources",
|
||||
prompts: "Prompts",
|
||||
logging: "Logging",
|
||||
completions: "Completions",
|
||||
tasks: "Tasks",
|
||||
experimental: "Experimental",
|
||||
roots: "Roots",
|
||||
sampling: "Sampling",
|
||||
elicitation: "Elicitation",
|
||||
};
|
||||
|
||||
export function CapabilityItem({
|
||||
name,
|
||||
capability,
|
||||
supported,
|
||||
count,
|
||||
}: CapabilityItemProps) {
|
||||
const name = displayLabel[capability] ?? String(capability);
|
||||
const label = count != null ? `${name} (${count})` : name;
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ const meta: Meta<typeof ConnectionToggle> = {
|
|||
title: "Elements/ConnectionToggle",
|
||||
component: ConnectionToggle,
|
||||
args: {
|
||||
onChange: fn(),
|
||||
onConnect: fn(),
|
||||
onDisconnect: fn(),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -15,32 +16,31 @@ type Story = StoryObj<typeof ConnectionToggle>;
|
|||
|
||||
export const Connected: Story = {
|
||||
args: {
|
||||
checked: true,
|
||||
loading: false,
|
||||
disabled: false,
|
||||
status: "connected",
|
||||
},
|
||||
};
|
||||
|
||||
export const Disconnected: Story = {
|
||||
args: {
|
||||
checked: false,
|
||||
loading: false,
|
||||
disabled: false,
|
||||
status: "disconnected",
|
||||
},
|
||||
};
|
||||
|
||||
export const Loading: Story = {
|
||||
export const Connecting: Story = {
|
||||
args: {
|
||||
checked: false,
|
||||
loading: true,
|
||||
disabled: false,
|
||||
status: "connecting",
|
||||
},
|
||||
};
|
||||
|
||||
export const Disabled: Story = {
|
||||
args: {
|
||||
checked: false,
|
||||
loading: false,
|
||||
status: "disconnected",
|
||||
disabled: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const Error: Story = {
|
||||
args: {
|
||||
status: "error",
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,24 +1,34 @@
|
|||
import { Switch } from "@mantine/core";
|
||||
import type { ConnectionStatus } from "@inspector/core/mcp/types.js";
|
||||
|
||||
export interface ConnectionToggleProps {
|
||||
checked: boolean;
|
||||
loading: boolean;
|
||||
disabled: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
status: ConnectionStatus;
|
||||
disabled?: boolean;
|
||||
onConnect: () => void;
|
||||
onDisconnect: () => void;
|
||||
}
|
||||
|
||||
export function ConnectionToggle({
|
||||
checked,
|
||||
loading,
|
||||
disabled,
|
||||
onChange,
|
||||
status,
|
||||
disabled = false,
|
||||
onConnect,
|
||||
onDisconnect,
|
||||
}: ConnectionToggleProps) {
|
||||
const isConnected = status === "connected";
|
||||
const isConnecting = status === "connecting";
|
||||
|
||||
return (
|
||||
<Switch
|
||||
size="lg"
|
||||
checked={checked || loading}
|
||||
disabled={disabled || loading}
|
||||
onChange={(event) => onChange(event.currentTarget.checked)}
|
||||
checked={isConnected || isConnecting}
|
||||
disabled={disabled || isConnecting}
|
||||
onChange={(event) => {
|
||||
if (event.currentTarget.checked) {
|
||||
onConnect();
|
||||
} else {
|
||||
onDisconnect();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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/ybVxDMKwjmFQTzCoJ5BcG8gmBeQTCvIJg3mLQX2eIVBPMKgnkFwbyCYF5BMK8gmFcQzCsI5hUE8zqdYF5BMK8gmFcQzCsI5hUE8wqCeQXBvIJgXkEwbzBpL7LFKwjmFQTzCoJ5BcG8gmBeQTCvIJhXEMwrCOZ1OsG8gmBeQTCvIJhXEMwrCOYVBPMKgnkFwbyCYN5g0l5ki1cQzCsI5hUE8wqCeQXBvIJgXkEwryCYVxDM63SCeQXBvIJgXkEwryCYVxDMKwjmFQTzCoJ5BcG8waS9yBavIJhXEMwrCOYVBPMKgnkFwbyCYF5BMK8gmNfpBPMKgnkFwbyCYF5BMK8gmFcQzCsI5hUE8wqCeYNJe5EtXkEwryCYVxDMKwjmFQTzCoJ5BcG8gmBeQTDvBaFNwZ0T5gfxAAAAAElFTkSuQmCC",
|
||||
mimeType: "image/png",
|
||||
block: {
|
||||
type: "image",
|
||||
data: "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAABWUlEQVR4nO3YsQnAMAwAQe+/dLKCRZpD+UA6cVh8p/Oc81z9t1/eJ+/oD/ybVxDMKwjmFQTzCoJ5BcG8gmBeQTCvIJg3mLQX2eIVBPMKgnkFwbyCYF5BMK8gmFcQzCsI5hUE8zqdYF5BMK8gmFcQzCsI5hUE8wqCeQXBvIJgXkEwbzBpL7LFKwjmFQTzCoJ5BcG8gmBeQTCvIJhXEMwrCOZ1OsG8gmBeQTCvIJhXEMwrCOYVBPMKgnkFwbyCYN5g0l5ki1cQzCsI5hUE8wqCeQXBvIJgXkEwryCYVxDM63SCeQXBvIJgXkEwryCYVxDMKwjmFQTzCoJ5BcG8waS9yBavIJhXEMwrCOYVBPMKgnkFwbyCYF5BMK8gmNfpBPMKgnkFwbyCYF5BMK8gmFcQzCsI5hUE8wqCeYNJe5EtXkEwryCYVxDMKwjmFQTzCoJ5BcG8gmBeQTDvBaFNwZ0T5gfxAAAAAElFTkSuQmCC",
|
||||
mimeType: "image/png",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const LongContent: Story = {
|
||||
export const LongJson: Story = {
|
||||
args: {
|
||||
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,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,14 @@ 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;
|
||||
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 +42,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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ export function CopyButton({ value }: CopyButtonProps) {
|
|||
<Tooltip label={copied ? "Copied" : "Copy"}>
|
||||
<ActionIcon
|
||||
variant="subtle"
|
||||
color={copied ? "green" : "gray"}
|
||||
color={copied ? "green" : "var(--inspector-text-primary)"}
|
||||
onClick={copy}
|
||||
fz={24}
|
||||
>
|
||||
{copied ? "\u2713" : "\u2398"}
|
||||
</ActionIcon>
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ type Story = StoryObj<typeof InlineError>;
|
|||
|
||||
export const ShortError: Story = {
|
||||
args: {
|
||||
message: "Connection timeout after 20s",
|
||||
error: { message: "Connection timeout after 20s" },
|
||||
},
|
||||
};
|
||||
|
||||
export const WithRetryCount: Story = {
|
||||
args: {
|
||||
message: "Connection failed",
|
||||
error: { message: "Connection failed" },
|
||||
retryCount: 3,
|
||||
maxRetries: 5,
|
||||
},
|
||||
|
|
@ -25,24 +25,26 @@ export const WithRetryCount: Story = {
|
|||
|
||||
export const WithDetails: Story = {
|
||||
args: {
|
||||
message: "Connection refused",
|
||||
details:
|
||||
"Error: ECONNREFUSED 127.0.0.1:3000\n at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)",
|
||||
error: {
|
||||
message: "Connection refused",
|
||||
data: "Error: ECONNREFUSED 127.0.0.1:3000\n at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const WithDocLink: Story = {
|
||||
args: {
|
||||
message: "Connection failed",
|
||||
error: { message: "Connection failed" },
|
||||
docLink: "https://example.com/troubleshooting",
|
||||
},
|
||||
};
|
||||
|
||||
export const FullError: Story = {
|
||||
args: {
|
||||
message: "Connection refused",
|
||||
details:
|
||||
"Error: ECONNREFUSED 127.0.0.1:3000\n at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)",
|
||||
error: {
|
||||
message: "Connection refused",
|
||||
data: "Error: ECONNREFUSED 127.0.0.1:3000\n at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)",
|
||||
},
|
||||
retryCount: 3,
|
||||
maxRetries: 5,
|
||||
docLink: "https://example.com/troubleshooting",
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import { Alert, Button, Collapse, Group, Stack, Text } from "@mantine/core";
|
|||
import { useState } from "react";
|
||||
|
||||
export interface InlineErrorProps {
|
||||
message: string;
|
||||
details?: string;
|
||||
error: { message: string; data?: unknown };
|
||||
retryCount?: number;
|
||||
maxRetries?: number;
|
||||
docLink?: string;
|
||||
|
|
@ -49,14 +48,20 @@ function formatRetryLabel(retryCount: number, maxRetries?: number): string {
|
|||
: `Retry attempt ${retryCount}`;
|
||||
}
|
||||
|
||||
function formatDetails(data: unknown): string {
|
||||
if (typeof data === "string") return data;
|
||||
return JSON.stringify(data, null, 2);
|
||||
}
|
||||
|
||||
export function InlineError({
|
||||
message,
|
||||
details,
|
||||
error,
|
||||
retryCount,
|
||||
maxRetries,
|
||||
docLink,
|
||||
}: InlineErrorProps) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const details =
|
||||
error.data !== undefined ? formatDetails(error.data) : undefined;
|
||||
const hasExpandable = details !== undefined || docLink !== undefined;
|
||||
|
||||
return (
|
||||
|
|
@ -64,7 +69,7 @@ export function InlineError({
|
|||
<Stack gap="xs">
|
||||
<HeaderRow>
|
||||
<MessageGroup>
|
||||
<ErrorMessage>{message}</ErrorMessage>
|
||||
<ErrorMessage>{error.message}</ErrorMessage>
|
||||
{retryCount !== undefined && (
|
||||
<RetryText>{formatRetryLabel(retryCount, maxRetries)}</RetryText>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const UpdateLabel = Text.withProps({
|
|||
|
||||
const RefreshButton = Button.withProps({
|
||||
size: "sm",
|
||||
variant: "light",
|
||||
variant: "subtle",
|
||||
});
|
||||
|
||||
export function ListChangedIndicator({
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export function ListToggle({
|
|||
}
|
||||
|
||||
return (
|
||||
<Button size="sm" onClick={onToggle}>
|
||||
<Button size="sm" variant="subtle" onClick={onToggle}>
|
||||
<Icon size={20} />
|
||||
</Button>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,73 +11,70 @@ type Story = StoryObj<typeof LogEntry>;
|
|||
|
||||
export const Debug: Story = {
|
||||
args: {
|
||||
timestamp: "2026-03-17T10:00:00Z",
|
||||
level: "debug",
|
||||
message: "Initializing connection pool",
|
||||
entry: {
|
||||
receivedAt: new Date("2026-03-29T20:18:20.000Z"),
|
||||
params: { level: "debug", data: "Initializing connection pool" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const Info: Story = {
|
||||
args: {
|
||||
timestamp: "2026-03-17T10:00:01Z",
|
||||
level: "info",
|
||||
message: "Server started on port 3000",
|
||||
},
|
||||
};
|
||||
|
||||
export const Notice: Story = {
|
||||
args: {
|
||||
timestamp: "2026-03-17T10:00:02Z",
|
||||
level: "notice",
|
||||
message: "Configuration reloaded successfully",
|
||||
entry: {
|
||||
receivedAt: new Date("2026-03-29T20:18:21.000Z"),
|
||||
params: { level: "info", data: "Server started on port 3000" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const Warning: Story = {
|
||||
args: {
|
||||
timestamp: "2026-03-17T10:00:03Z",
|
||||
level: "warning",
|
||||
message: "Memory usage above 80%",
|
||||
entry: {
|
||||
receivedAt: new Date("2026-03-29T20:18:22.000Z"),
|
||||
params: {
|
||||
level: "warning",
|
||||
data: "Connection pool nearing capacity",
|
||||
logger: "pool",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const Error: Story = {
|
||||
args: {
|
||||
timestamp: "2026-03-17T10:00:04Z",
|
||||
level: "error",
|
||||
message: "Failed to connect to database",
|
||||
},
|
||||
};
|
||||
|
||||
export const Critical: Story = {
|
||||
args: {
|
||||
timestamp: "2026-03-17T10:00:05Z",
|
||||
level: "critical",
|
||||
message: "Disk space critically low",
|
||||
},
|
||||
};
|
||||
|
||||
export const Alert: Story = {
|
||||
args: {
|
||||
timestamp: "2026-03-17T10:00:06Z",
|
||||
level: "alert",
|
||||
message: "Service degradation detected",
|
||||
entry: {
|
||||
receivedAt: new Date("2026-03-29T20:18:23.000Z"),
|
||||
params: {
|
||||
level: "error",
|
||||
data: "Failed to connect to database",
|
||||
logger: "db",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const Emergency: Story = {
|
||||
args: {
|
||||
timestamp: "2026-03-17T10:00:07Z",
|
||||
level: "emergency",
|
||||
message: "System is unusable",
|
||||
entry: {
|
||||
receivedAt: new Date("2026-03-29T20:18:24.000Z"),
|
||||
params: {
|
||||
level: "emergency",
|
||||
data: "System is unusable",
|
||||
logger: "kernel",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const WithLogger: Story = {
|
||||
export const WithJsonData: Story = {
|
||||
args: {
|
||||
timestamp: "2026-03-17T10:00:08Z",
|
||||
level: "info",
|
||||
message: "Tool execution completed",
|
||||
logger: "mcp-server",
|
||||
entry: {
|
||||
receivedAt: new Date("2026-03-29T20:18:25.000Z"),
|
||||
params: {
|
||||
level: "info",
|
||||
data: { key: "value", count: 42 },
|
||||
logger: "api",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,24 +1,20 @@
|
|||
import { Group, Text } from "@mantine/core";
|
||||
import type {
|
||||
LoggingLevel,
|
||||
LoggingMessageNotification,
|
||||
} from "@modelcontextprotocol/sdk/types.js";
|
||||
import { LogLevelBadge } from "../LogLevelBadge/LogLevelBadge";
|
||||
|
||||
export type LogLevel =
|
||||
| "debug"
|
||||
| "info"
|
||||
| "notice"
|
||||
| "warning"
|
||||
| "error"
|
||||
| "critical"
|
||||
| "alert"
|
||||
| "emergency";
|
||||
|
||||
export interface LogEntryProps {
|
||||
timestamp: string;
|
||||
level: LogLevel;
|
||||
message: string;
|
||||
logger?: string;
|
||||
export interface LogEntryData {
|
||||
receivedAt: Date;
|
||||
params: LoggingMessageNotification["params"];
|
||||
}
|
||||
|
||||
const levelMessageColor: Record<LogLevel, string | undefined> = {
|
||||
export interface LogEntryProps {
|
||||
entry: LogEntryData;
|
||||
}
|
||||
|
||||
const levelMessageColor: Record<LoggingLevel, string | undefined> = {
|
||||
debug: "dimmed",
|
||||
info: "blue",
|
||||
notice: undefined,
|
||||
|
|
@ -29,10 +25,20 @@ const levelMessageColor: Record<LogLevel, string | undefined> = {
|
|||
emergency: "red",
|
||||
};
|
||||
|
||||
function formatTimestamp(date: Date): string {
|
||||
return date.toLocaleTimeString();
|
||||
}
|
||||
|
||||
function formatLogger(logger: string): string {
|
||||
return `[${logger}]`;
|
||||
}
|
||||
|
||||
function formatData(data: unknown): string {
|
||||
if (data === undefined || data === null) return "";
|
||||
if (typeof data === "string") return data;
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
|
||||
const TimestampText = Text.withProps({
|
||||
size: "sm",
|
||||
ff: "monospace",
|
||||
|
|
@ -45,13 +51,16 @@ const LoggerText = Text.withProps({
|
|||
c: "dimmed",
|
||||
});
|
||||
|
||||
export function LogEntry({ timestamp, level, message, logger }: LogEntryProps) {
|
||||
export function LogEntry({ entry }: LogEntryProps) {
|
||||
const { receivedAt, params } = entry;
|
||||
const message = formatData(params.data);
|
||||
|
||||
return (
|
||||
<Group gap="sm" wrap="nowrap">
|
||||
<TimestampText>{timestamp}</TimestampText>
|
||||
<LogLevelBadge level={level} />
|
||||
{logger && <LoggerText>{formatLogger(logger)}</LoggerText>}
|
||||
<Text size="sm" ff="monospace" c={levelMessageColor[level]}>
|
||||
<TimestampText>{formatTimestamp(receivedAt)}</TimestampText>
|
||||
<LogLevelBadge level={params.level} />
|
||||
{params.logger && <LoggerText>{formatLogger(params.logger)}</LoggerText>}
|
||||
<Text size="sm" ff="monospace" c={levelMessageColor[params.level]}>
|
||||
{message}
|
||||
</Text>
|
||||
</Group>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { Badge, useComputedColorScheme } from "@mantine/core";
|
||||
import type { LogLevel } from "../LogEntry/LogEntry";
|
||||
import type { LoggingLevel } from "@modelcontextprotocol/sdk/types.js";
|
||||
|
||||
export interface LogLevelBadgeProps {
|
||||
level: LogLevel;
|
||||
level: LoggingLevel;
|
||||
}
|
||||
|
||||
const levelColor: Record<LogLevel, string> = {
|
||||
const levelColor: Record<LoggingLevel, string> = {
|
||||
debug: "gray",
|
||||
info: "blue",
|
||||
notice: "teal",
|
||||
|
|
@ -16,7 +16,7 @@ const levelColor: Record<LogLevel, string> = {
|
|||
emergency: "red",
|
||||
};
|
||||
|
||||
const boldLevels: Set<LogLevel> = new Set(["alert", "emergency"]);
|
||||
const boldLevels: Set<LoggingLevel> = new Set(["alert", "emergency"]);
|
||||
|
||||
export function LogLevelBadge({ level }: LogLevelBadgeProps) {
|
||||
const colorScheme = useComputedColorScheme();
|
||||
|
|
|
|||
|
|
@ -12,28 +12,39 @@ type Story = StoryObj<typeof MessageBubble>;
|
|||
export const UserText: Story = {
|
||||
args: {
|
||||
index: 0,
|
||||
role: "user",
|
||||
content: "Hello, my name is John and I like cats",
|
||||
message: {
|
||||
role: "user",
|
||||
content: { type: "text", text: "Hello, my name is John and I like cats" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const AssistantText: Story = {
|
||||
args: {
|
||||
index: 1,
|
||||
role: "assistant",
|
||||
content:
|
||||
"Nice to meet you, John! It's wonderful that you enjoy cats. They're such fascinating and independent creatures. Do you have any cats of your own?",
|
||||
message: {
|
||||
role: "assistant",
|
||||
content: {
|
||||
type: "text",
|
||||
text: "Nice to meet you, John! It's wonderful that you enjoy cats. They're such fascinating and independent creatures. Do you have any cats of your own?",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const UserWithImage: Story = {
|
||||
args: {
|
||||
index: 0,
|
||||
role: "user",
|
||||
content: "Check this out",
|
||||
imageContent: {
|
||||
data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
|
||||
mimeType: "image/png",
|
||||
message: {
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "text", text: "Check this out" },
|
||||
{
|
||||
type: "image",
|
||||
data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
|
||||
mimeType: "image/png",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
@ -41,8 +52,12 @@ export const UserWithImage: Story = {
|
|||
export const LongMessage: Story = {
|
||||
args: {
|
||||
index: 0,
|
||||
role: "user",
|
||||
content:
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.",
|
||||
message: {
|
||||
role: "user",
|
||||
content: {
|
||||
type: "text",
|
||||
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue