import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; 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 { ListToolsResult, Tool, CallToolResultSchema, } from "@modelcontextprotocol/sdk/types.js"; import { AlertCircle, Send } from "lucide-react"; import { useState } from "react"; import ListPane from "./ListPane"; import { CompatibilityCallToolResult } from "@modelcontextprotocol/sdk/types.js"; const ToolsTab = ({ tools, listTools, callTool, selectedTool, setSelectedTool, toolResult, nextCursor, error, }: { tools: Tool[]; listTools: () => void; callTool: (name: string, params: Record) => void; selectedTool: Tool | null; setSelectedTool: (tool: Tool) => void; toolResult: CompatibilityCallToolResult | null; nextCursor: ListToolsResult["nextCursor"]; error: string | null; }) => { const [params, setParams] = useState>({}); const renderToolResult = () => { if (!toolResult) return null; if ("content" in toolResult) { const parsedResult = CallToolResultSchema.safeParse(toolResult); if (!parsedResult.success) { return ( <>

Invalid Tool Result:

              {JSON.stringify(toolResult, null, 2)}
            

Errors:

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

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

{structuredResult.content.map((item, index) => (
{item.type === "text" && (
                  {item.text}
                
)} {item.type === "image" && ( Tool result image )} {item.type === "resource" && (
                  {JSON.stringify(item.resource, null, 2)}
                
)}
))} ); } else if ("toolResult" in toolResult) { return ( <>

Tool Result (Legacy):

            {JSON.stringify(toolResult.toolResult, null, 2)}
          
); } }; return ( ( <> {tool.name} {tool.description} )} title="Tools" buttonText={nextCursor ? "List More Tools" : "List Tools"} isButtonDisabled={!nextCursor && tools.length > 0} />

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

{error ? ( Error {error} ) : selectedTool ? (

{selectedTool.description}

{Object.entries(selectedTool.inputSchema.properties ?? []).map( ([key, value]) => (
{ /* @ts-expect-error value type is currently unknown */ value.type === "string" ? (