@@ -13,10 +13,11 @@ import {
1313 ListToolsResult ,
1414 Tool ,
1515} from "@modelcontextprotocol/sdk/types.js" ;
16- import { Send } from "lucide-react" ;
17- import { useEffect , useState } from "react" ;
16+ import { Copy , Send , CheckCheck } from "lucide-react" ;
17+ import { useCallback , useEffect , useState } from "react" ;
1818import ListPane from "./ListPane" ;
1919import JsonView from "./JsonView" ;
20+ import { toast } from "react-toastify" ;
2021
2122const ToolsTab = ( {
2223 tools,
@@ -43,6 +44,22 @@ const ToolsTab = ({
4344 setParams ( { } ) ;
4445 } , [ selectedTool ] ) ;
4546
47+ const [ copied , setCopied ] = useState ( false ) ;
48+
49+ const handleCopy = useCallback ( ( ) => {
50+ try {
51+ navigator . clipboard . writeText ( JSON . stringify ( toolResult ) ) ;
52+ setCopied ( true ) ;
53+ setTimeout ( ( ) => {
54+ setCopied ( false ) ;
55+ } , 500 ) ;
56+ } catch ( error ) {
57+ toast . error (
58+ `There was an error coping result into the clipboard: ${ error instanceof Error ? error . message : String ( error ) } ` ,
59+ ) ;
60+ }
61+ } , [ toolResult ] ) ;
62+
4663 const renderToolResult = ( ) => {
4764 if ( ! toolResult ) return null ;
4865
@@ -52,7 +69,8 @@ const ToolsTab = ({
5269 return (
5370 < >
5471 < h4 className = "font-semibold mb-2" > Invalid Tool Result:</ h4 >
55- < div className = "p-4 border rounded" >
72+ < div className = "p-4 border rounded relative" >
73+ < Copy className = "size-4 text-primary" />
5674 < JsonView data = { toolResult } />
5775 </ div >
5876 < h4 className = "font-semibold mb-2" > Errors:</ h4 >
@@ -75,7 +93,19 @@ const ToolsTab = ({
7593 { structuredResult . content . map ( ( item , index ) => (
7694 < div key = { index } className = "mb-2" >
7795 { item . type === "text" && (
78- < div className = "p-4 border rounded" >
96+ < div className = "p-4 border rounded relative" >
97+ < Button
98+ size = "icon"
99+ variant = "ghost"
100+ className = "absolute top-2 right-2"
101+ onClick = { handleCopy }
102+ >
103+ { copied ? (
104+ < CheckCheck className = "size-4 dark:text-green-700 text-green-600" />
105+ ) : (
106+ < Copy className = "size-4 text-foreground" />
107+ ) }
108+ </ Button >
79109 < JsonView data = { item . text } />
80110 </ div >
81111 ) }
0 commit comments