Skip to content

Commit 722df4d

Browse files
authored
Merge pull request #82 from jacksteamdev/fix-1
Add Runtime Type Validation for Tool Results
2 parents 3c4cb17 + 407e304 commit 722df4d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

client/src/components/ToolsTab.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { Label } from "@/components/ui/label";
55
import { TabsContent } from "@/components/ui/tabs";
66
import { Textarea } from "@/components/ui/textarea";
77
import {
8-
CallToolResult,
98
ListToolsResult,
109
Tool,
10+
CallToolResultSchema,
1111
} from "@modelcontextprotocol/sdk/types.js";
1212
import { AlertCircle, Send } from "lucide-react";
1313
import { useState } from "react";
@@ -40,7 +40,27 @@ const ToolsTab = ({
4040
if (!toolResult) return null;
4141

4242
if ("content" in toolResult) {
43-
const structuredResult = toolResult as CallToolResult;
43+
const parsedResult = CallToolResultSchema.safeParse(toolResult);
44+
if (!parsedResult.success) {
45+
return (
46+
<>
47+
<h4 className="font-semibold mb-2">Invalid Tool Result:</h4>
48+
<pre className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64">
49+
{JSON.stringify(toolResult, null, 2)}
50+
</pre>
51+
<h4 className="font-semibold mb-2">Errors:</h4>
52+
{parsedResult.error.errors.map((error, idx) => (
53+
<pre
54+
key={idx}
55+
className="bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-4 rounded text-sm overflow-auto max-h-64"
56+
>
57+
{JSON.stringify(error, null, 2)}
58+
</pre>
59+
))}
60+
</>
61+
);
62+
}
63+
const structuredResult = parsedResult.data;
4464
const isError = structuredResult.isError ?? false;
4565

4666
return (

0 commit comments

Comments
 (0)