diff --git a/client/src/components/History.tsx b/client/src/components/History.tsx index 532d3b1..7ce7dcf 100644 --- a/client/src/components/History.tsx +++ b/client/src/components/History.tsx @@ -1,6 +1,7 @@ import { ServerNotification } from "@modelcontextprotocol/sdk/types.js"; import { Copy } from "lucide-react"; import { useState } from "react"; +import JsonView from "./JsonView"; const HistoryAndNotifications = ({ requestHistory, @@ -75,7 +76,7 @@ const HistoryAndNotifications = ({
- {JSON.stringify(JSON.parse(request.request), null, 2)}
+
{request.response && (
@@ -92,11 +93,7 @@ const HistoryAndNotifications = ({
- {JSON.stringify(
- JSON.parse(request.response),
- null,
- 2,
- )}
+
)}
@@ -147,7 +144,9 @@ const HistoryAndNotifications = ({
- {JSON.stringify(notification, null, 2)}
+
)}
diff --git a/client/src/components/JsonView.tsx b/client/src/components/JsonView.tsx
new file mode 100644
index 0000000..21d65d8
--- /dev/null
+++ b/client/src/components/JsonView.tsx
@@ -0,0 +1,210 @@
+import { useState, memo } from "react";
+import { JsonValue } from "./DynamicJsonForm";
+
+interface JsonViewProps {
+ data: JsonValue;
+ name?: string;
+ initialExpandDepth?: number;
+}
+
+function tryParseJson(str: string): { success: boolean; data: JsonValue } {
+ const trimmed = str.trim();
+ if (
+ !(trimmed.startsWith("{") && trimmed.endsWith("}")) &&
+ !(trimmed.startsWith("[") && trimmed.endsWith("]"))
+ ) {
+ return { success: false, data: str };
+ }
+ try {
+ return { success: true, data: JSON.parse(str) };
+ } catch {
+ return { success: false, data: str };
+ }
+}
+
+const JsonView = memo(
+ ({ data, name, initialExpandDepth = 2 }: JsonViewProps) => {
+ const normalizedData =
+ typeof data === "string"
+ ? tryParseJson(data).success
+ ? tryParseJson(data).data
+ : data
+ : data;
+
+ return (
+
- {resourceContent}
+
) : selectedTemplate ? (
- {JSON.stringify(request.request, null, 2)}
+
- {escapeUnicode(toolResult)}
+
- {item.text}
+
)}
{item.type === "image" && (
@@ -101,7 +102,7 @@ const ToolsTab = ({
) : (
- {escapeUnicode(item.resource)}
+
))}
- {escapeUnicode(toolResult.toolResult)}
+
>
);