@@ -13,10 +13,11 @@ import {
13
13
ListToolsResult ,
14
14
Tool ,
15
15
} 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" ;
18
18
import ListPane from "./ListPane" ;
19
19
import JsonView from "./JsonView" ;
20
+ import { toast } from "react-toastify" ;
20
21
21
22
const ToolsTab = ( {
22
23
tools,
@@ -43,6 +44,22 @@ const ToolsTab = ({
43
44
setParams ( { } ) ;
44
45
} , [ selectedTool ] ) ;
45
46
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
+
46
63
const renderToolResult = ( ) => {
47
64
if ( ! toolResult ) return null ;
48
65
@@ -52,7 +69,8 @@ const ToolsTab = ({
52
69
return (
53
70
< >
54
71
< 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" />
56
74
< JsonView data = { toolResult } />
57
75
</ div >
58
76
< h4 className = "font-semibold mb-2" > Errors:</ h4 >
@@ -75,7 +93,19 @@ const ToolsTab = ({
75
93
{ structuredResult . content . map ( ( item , index ) => (
76
94
< div key = { index } className = "mb-2" >
77
95
{ 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 >
79
109
< JsonView data = { item . text } />
80
110
</ div >
81
111
) }
0 commit comments