Phase 2: Refactor Tools cluster to use MCP SDK types
Replace ad hoc local types with MCP SDK schema types across the Tools group components and ToolsScreen, per the v2 UX interfaces plan. - ToolListItem: accept `tool: Tool` instead of flat `name`/`title` - ToolControls: accept `Tool[]` + `selectedName` instead of `ToolListItemProps[]` - ToolDetailPanel: accept `tool: Tool` instead of flat props; use SDK `ToolAnnotations` (readOnlyHint/destructiveHint/idempotentHint/openWorldHint); use `ProgressNotification['params']` for progress - ToolResultPanel: accept `CallToolResult` instead of `ResultContentItem[]` - ToolsScreen: accept `Tool[]` + `selectedToolName` + `ToolCallState`; derive selected tool via `tools.find()`; own `formValues` state locally - Delete local `ToolAnnotations`, `ResultContentItem` types - Update all stories with real SDK `Tool` fixtures - Update ConnectedView ToolsActive story Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9082e02e65
commit
92ecfcbd6c
1 changed files with 388 additions and 411 deletions
|
|
@ -1,16 +1,9 @@
|
|||
import { Button, Group, Stack, Text, Title } from "@mantine/core";
|
||||
import type { ContentBlock } from "@modelcontextprotocol/sdk/types.js";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
||||
import { ContentViewer } from "../../elements/ContentViewer/ContentViewer";
|
||||
|
||||
export interface ResultContentItem {
|
||||
type: string;
|
||||
text?: string;
|
||||
data?: string;
|
||||
mimeType?: string;
|
||||
}
|
||||
|
||||
export interface ToolResultPanelProps {
|
||||
content: ResultContentItem[];
|
||||
result: CallToolResult;
|
||||
onClear: () => void;
|
||||
}
|
||||
|
||||
|
|
@ -19,41 +12,24 @@ const ClearButton = Button.withProps({
|
|||
size: "sm",
|
||||
});
|
||||
|
||||
function toContentBlock(item: ResultContentItem): ContentBlock | null {
|
||||
if (item.text !== undefined) {
|
||||
return { type: "text", text: item.text };
|
||||
}
|
||||
if (item.data !== undefined && item.mimeType?.startsWith("image")) {
|
||||
return { type: "image", data: item.data, mimeType: item.mimeType };
|
||||
}
|
||||
if (item.data !== undefined && item.mimeType) {
|
||||
return { type: "audio", data: item.data, mimeType: item.mimeType };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function ToolResultPanel({ content, onClear }: ToolResultPanelProps) {
|
||||
export function ToolResultPanel({ result, onClear }: ToolResultPanelProps) {
|
||||
return (
|
||||
<Stack>
|
||||
<Group justify="space-between">
|
||||
<Title order={4}>Results</Title>
|
||||
<ClearButton onClick={onClear}>Clear</ClearButton>
|
||||
</Group>
|
||||
{content.length === 0 ? (
|
||||
{result.content.length === 0 ? (
|
||||
<Text c="dimmed">No results yet</Text>
|
||||
) : (
|
||||
<>
|
||||
{content.map((item, index) => {
|
||||
const block = toContentBlock(item);
|
||||
if (!block) return null;
|
||||
return (
|
||||
<ContentViewer
|
||||
key={index}
|
||||
block={block}
|
||||
copyable={block.type === "text"}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{result.content.map((block, index) => (
|
||||
<ContentViewer
|
||||
key={index}
|
||||
block={block}
|
||||
copyable={block.type === "text"}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
|
|
|
|||
Loading…
Reference in a new issue