@@ -8,15 +8,31 @@ import { Textarea } from "@/components/ui/textarea";
8
8
import DynamicJsonForm , { JsonSchemaType , JsonValue } from "./DynamicJsonForm" ;
9
9
import { generateDefaultValue } from "@/utils/schemaUtils" ;
10
10
import {
11
+ CallToolResultSchema ,
12
+ CompatibilityCallToolResult ,
11
13
ListToolsResult ,
12
14
Tool ,
13
- CallToolResultSchema ,
14
15
} from "@modelcontextprotocol/sdk/types.js" ;
15
16
import { AlertCircle , Send } from "lucide-react" ;
16
17
import { useEffect , useState } from "react" ;
17
18
import ListPane from "./ListPane" ;
18
19
19
- import { CompatibilityCallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
20
+ // Utility function to escape Unicode characters
21
+ function escapeUnicode ( obj : any ) : string {
22
+ return JSON . stringify (
23
+ obj ,
24
+ ( _key : string , value ) => {
25
+ if ( typeof value === "string" ) {
26
+ // Replace non-ASCII characters with their Unicode escape sequences
27
+ return value . replace ( / [ ^ \0 - \x7F ] / g, ( char ) => {
28
+ return "\\u" + ( "0000" + char . charCodeAt ( 0 ) . toString ( 16 ) ) . slice ( - 4 ) ;
29
+ } ) ;
30
+ }
31
+ return value ;
32
+ } ,
33
+ 2 ,
34
+ ) ;
35
+ }
20
36
21
37
const ToolsTab = ( {
22
38
tools,
@@ -54,15 +70,15 @@ const ToolsTab = ({
54
70
< >
55
71
< h4 className = "font-semibold mb-2" > Invalid Tool Result:</ h4 >
56
72
< pre className = "bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64" >
57
- { JSON . stringify ( toolResult , null , 2 ) }
73
+ { escapeUnicode ( toolResult ) }
58
74
</ pre >
59
75
< h4 className = "font-semibold mb-2" > Errors:</ h4 >
60
76
{ parsedResult . error . errors . map ( ( error , idx ) => (
61
77
< pre
62
78
key = { idx }
63
79
className = "bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64"
64
80
>
65
- { JSON . stringify ( error , null , 2 ) }
81
+ { escapeUnicode ( error ) }
66
82
</ pre >
67
83
) ) }
68
84
</ >
@@ -101,7 +117,7 @@ const ToolsTab = ({
101
117
</ audio >
102
118
) : (
103
119
< pre className = "bg-gray-50 dark:bg-gray-800 dark:text-gray-100 whitespace-pre-wrap break-words p-4 rounded text-sm overflow-auto max-h-64" >
104
- { JSON . stringify ( item . resource , null , 2 ) }
120
+ { escapeUnicode ( item . resource ) }
105
121
</ pre >
106
122
) ) }
107
123
</ div >
@@ -113,7 +129,7 @@ const ToolsTab = ({
113
129
< >
114
130
< h4 className = "font-semibold mb-2" > Tool Result (Legacy):</ h4 >
115
131
< pre className = "bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64" >
116
- { JSON . stringify ( toolResult . toolResult , null , 2 ) }
132
+ { escapeUnicode ( toolResult . toolResult ) }
117
133
</ pre >
118
134
</ >
119
135
) ;
0 commit comments