import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { TabsContent } from "@/components/ui/tabs"; import { Textarea } from "@/components/ui/textarea"; import DynamicJsonForm, { JsonSchemaType, JsonValue } from "./DynamicJsonForm"; import { generateDefaultValue } from "@/utils/schemaUtils"; import { CallToolResultSchema, CompatibilityCallToolResult, ListToolsResult, Tool, } from "@modelcontextprotocol/sdk/types.js"; import { Loader2, Send } from "lucide-react"; import { useEffect, useState } from "react"; import ListPane from "./ListPane"; import JsonView from "./JsonView"; const ToolsTab = ({ tools, listTools, clearTools, callTool, selectedTool, setSelectedTool, toolResult, nextCursor, }: { tools: Tool[]; listTools: () => void; clearTools: () => void; callTool: (name: string, params: Record) => Promise; selectedTool: Tool | null; setSelectedTool: (tool: Tool | null) => void; toolResult: CompatibilityCallToolResult | null; nextCursor: ListToolsResult["nextCursor"]; error: string | null; }) => { const [params, setParams] = useState>({}); const [isToolRunning, setIsToolRunning] = useState(false); useEffect(() => { setParams({}); }, [selectedTool]); const renderToolResult = () => { if (!toolResult) return null; if ("content" in toolResult) { const parsedResult = CallToolResultSchema.safeParse(toolResult); if (!parsedResult.success) { return ( <>

Invalid Tool Result:

Errors:

{parsedResult.error.errors.map((error, idx) => ( ))} ); } const structuredResult = parsedResult.data; const isError = structuredResult.isError ?? false; return ( <>

Tool Result: {isError ? "Error" : "Success"}

{structuredResult.content.map((item, index) => (
{item.type === "text" && } {item.type === "image" && ( Tool result image )} {item.type === "resource" && (item.resource?.mimeType?.startsWith("audio/") ? ( ) : ( ))}
))} ); } else if ("toolResult" in toolResult) { return ( <>

Tool Result (Legacy):

); } }; return (
{ clearTools(); setSelectedTool(null); }} setSelectedItem={setSelectedTool} renderItem={(tool) => ( <> {tool.name} {tool.description} )} title="Tools" buttonText={nextCursor ? "List More Tools" : "List Tools"} isButtonDisabled={!nextCursor && tools.length > 0} />

{selectedTool ? selectedTool.name : "Select a tool"}

{selectedTool ? (

{selectedTool.description}

{Object.entries(selectedTool.inputSchema.properties ?? []).map( ([key, value]) => { const prop = value as JsonSchemaType; return (
{prop.type === "boolean" ? (
setParams({ ...params, [key]: checked, }) } />
) : prop.type === "string" ? (