Skip to content

Commit c48670f

Browse files
Add copy button to JSON & fix button styles override.
1 parent e9a90b9 commit c48670f

File tree

4 files changed

+27
-33
lines changed

4 files changed

+27
-33
lines changed

client/src/components/JsonView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const JsonView = memo(
3333
: data;
3434

3535
return (
36-
<div className="font-mono text-sm transition-all duration-300 ">
36+
<div className="font-mono text-sm transition-all duration-300">
3737
<JsonNode
3838
data={normalizedData as JsonValue}
3939
name={name}

client/src/components/ToolsTab.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import {
1313
ListToolsResult,
1414
Tool,
1515
} from "@modelcontextprotocol/sdk/types.js";
16-
import { AlertCircle, Send } from "lucide-react";
17-
import { useEffect, useState } from "react";
16+
import { AlertCircle, Copy, Send, CheckCheck } from "lucide-react";
17+
import { useCallback, useEffect, useState } from "react";
1818
import ListPane from "./ListPane";
1919
import JsonView from "./JsonView";
20+
import { toast } from 'react-toastify'
2021

2122
const ToolsTab = ({
2223
tools,
@@ -44,6 +45,20 @@ const ToolsTab = ({
4445
setParams({});
4546
}, [selectedTool]);
4647

48+
const [copied, setCopied] = useState(false)
49+
50+
const handleCopy = useCallback(() => {
51+
try {
52+
navigator.clipboard.writeText(JSON.stringify(toolResult))
53+
setCopied(true)
54+
setTimeout(() => {
55+
setCopied(false)
56+
}, 500)
57+
} catch (error) {
58+
toast.error(`There was an error coping result into the clipboard: ${error instanceof Error ? error.message : String(error)}`)
59+
}
60+
}, [toolResult])
61+
4762
const renderToolResult = () => {
4863
if (!toolResult) return null;
4964

@@ -53,7 +68,8 @@ const ToolsTab = ({
5368
return (
5469
<>
5570
<h4 className="font-semibold mb-2">Invalid Tool Result:</h4>
56-
<div className="p-4 border rounded">
71+
<div className="p-4 border rounded relative">
72+
<Copy className="size-4 text-primary" />
5773
<JsonView data={toolResult} />
5874
</div>
5975
<h4 className="font-semibold mb-2">Errors:</h4>
@@ -76,7 +92,12 @@ const ToolsTab = ({
7692
{structuredResult.content.map((item, index) => (
7793
<div key={index} className="mb-2">
7894
{item.type === "text" && (
79-
<div className="p-4 border rounded">
95+
<div className="p-4 border rounded relative">
96+
<Button size="icon" variant="ghost" className="absolute top-2 right-2" onClick={handleCopy}>
97+
{copied ?
98+
<CheckCheck className="size-4 dark:text-green-700 text-green-600" />
99+
: <Copy className="size-4 text-foreground" />}
100+
</Button>
80101
<JsonView data={item.text} />
81102
</div>
82103
)}
@@ -234,7 +255,7 @@ const ToolsTab = ({
234255
...params,
235256
[key]:
236257
prop.type === "number" ||
237-
prop.type === "integer"
258+
prop.type === "integer"
238259
? Number(e.target.value)
239260
: e.target.value,
240261
})

client/src/components/__tests__/ToolsTab.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ describe("ToolsTab", () => {
8181
expect(newInput.value).toBe("");
8282
});
8383

84-
8584
it("should display error message when error prop is provided", () => {
8685
const errorMessage = "Test error message";
8786
renderToolsTab({

client/src/index.css

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,6 @@ h1 {
3838
line-height: 1.1;
3939
}
4040

41-
button {
42-
border-radius: 8px;
43-
border: 1px solid transparent;
44-
padding: 0.6em 1.2em;
45-
font-size: 1em;
46-
font-weight: 500;
47-
font-family: inherit;
48-
background-color: #1a1a1a;
49-
cursor: pointer;
50-
transition: border-color 0.25s;
51-
}
52-
button:hover {
53-
border-color: #646cff;
54-
}
55-
button:focus,
56-
button:focus-visible {
57-
outline: 4px auto -webkit-focus-ring-color;
58-
}
59-
60-
button[role="checkbox"] {
61-
padding: 0;
62-
}
63-
6441
@media (prefers-color-scheme: light) {
6542
:root {
6643
color: #213547;
@@ -69,9 +46,6 @@ button[role="checkbox"] {
6946
a:hover {
7047
color: #747bff;
7148
}
72-
button {
73-
background-color: #f9f9f9;
74-
}
7549
}
7650

7751
@layer base {

0 commit comments

Comments
 (0)