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,18 +1,34 @@
|
|||
import { useState } from "react";
|
||||
import { Card, Flex, Stack, Text } from "@mantine/core";
|
||||
import type {
|
||||
CallToolResult,
|
||||
ProgressNotification,
|
||||
Tool,
|
||||
} from "@modelcontextprotocol/sdk/types.js";
|
||||
import { ToolControls } from "../../groups/ToolControls/ToolControls";
|
||||
import { ToolDetailPanel } from "../../groups/ToolDetailPanel/ToolDetailPanel";
|
||||
import { ToolResultPanel } from "../../groups/ToolResultPanel/ToolResultPanel";
|
||||
import type { ToolListItemProps } from "../../groups/ToolListItem/ToolListItem";
|
||||
import type { ToolDetailPanelProps } from "../../groups/ToolDetailPanel/ToolDetailPanel";
|
||||
import type { ToolResultPanelProps } from "../../groups/ToolResultPanel/ToolResultPanel";
|
||||
|
||||
export interface ToolCallState {
|
||||
status: "idle" | "pending" | "ok" | "error";
|
||||
result?: CallToolResult;
|
||||
error?: string;
|
||||
progress?: Pick<
|
||||
ProgressNotification["params"],
|
||||
"progress" | "total" | "message"
|
||||
>;
|
||||
}
|
||||
|
||||
export interface ToolsScreenProps {
|
||||
tools: ToolListItemProps[];
|
||||
selectedTool?: ToolDetailPanelProps;
|
||||
result?: ToolResultPanelProps;
|
||||
tools: Tool[];
|
||||
selectedToolName?: string;
|
||||
callState?: ToolCallState;
|
||||
listChanged: boolean;
|
||||
onRefreshList: () => void;
|
||||
onSelectTool: (name: string) => void;
|
||||
onCallTool: (name: string, args: Record<string, unknown>) => void;
|
||||
onCancelCall?: () => void;
|
||||
onClearResult?: () => void;
|
||||
}
|
||||
|
||||
const ScreenLayout = Flex.withProps({
|
||||
|
|
@ -46,18 +62,28 @@ const EmptyState = Text.withProps({
|
|||
|
||||
export function ToolsScreen({
|
||||
tools,
|
||||
selectedTool,
|
||||
result,
|
||||
selectedToolName,
|
||||
callState,
|
||||
listChanged,
|
||||
onRefreshList,
|
||||
onSelectTool,
|
||||
onCallTool,
|
||||
onCancelCall,
|
||||
onClearResult,
|
||||
}: ToolsScreenProps) {
|
||||
const [formValues, setFormValues] = useState<Record<string, unknown>>({});
|
||||
const selectedTool = selectedToolName
|
||||
? tools.find((t) => t.name === selectedToolName)
|
||||
: undefined;
|
||||
const isExecuting = callState?.status === "pending";
|
||||
|
||||
return (
|
||||
<ScreenLayout>
|
||||
<Sidebar>
|
||||
<SidebarCard>
|
||||
<ToolControls
|
||||
tools={tools}
|
||||
selectedName={selectedToolName}
|
||||
listChanged={listChanged}
|
||||
onRefreshList={onRefreshList}
|
||||
onSelectTool={onSelectTool}
|
||||
|
|
@ -67,15 +93,26 @@ export function ToolsScreen({
|
|||
|
||||
<ContentCard flex={1}>
|
||||
{selectedTool ? (
|
||||
<ToolDetailPanel {...selectedTool} />
|
||||
<ToolDetailPanel
|
||||
tool={selectedTool}
|
||||
formValues={formValues}
|
||||
isExecuting={isExecuting}
|
||||
progress={callState?.progress}
|
||||
onFormChange={setFormValues}
|
||||
onExecute={() => onCallTool(selectedTool.name, formValues)}
|
||||
onCancel={() => onCancelCall?.()}
|
||||
/>
|
||||
) : (
|
||||
<EmptyState>Select a tool to view details</EmptyState>
|
||||
)}
|
||||
</ContentCard>
|
||||
|
||||
<ContentCard flex={1}>
|
||||
{result ? (
|
||||
<ToolResultPanel {...result} />
|
||||
{callState?.result ? (
|
||||
<ToolResultPanel
|
||||
result={callState.result}
|
||||
onClear={() => onClearResult?.()}
|
||||
/>
|
||||
) : (
|
||||
<EmptyState>Results will appear here</EmptyState>
|
||||
)}
|
||||
|
|
|
|||
Loading…
Reference in a new issue