From aecfa21d47605f9ac3bda7615bd8a8761a61d719 Mon Sep 17 00:00:00 2001 From: Jack Steam Date: Tue, 26 Nov 2024 11:14:55 -0700 Subject: [PATCH 1/3] fix: add static type validation --- client/src/components/ToolsTab.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/components/ToolsTab.tsx b/client/src/components/ToolsTab.tsx index 25d4f15..b7e2cc1 100644 --- a/client/src/components/ToolsTab.tsx +++ b/client/src/components/ToolsTab.tsx @@ -8,6 +8,7 @@ import { CallToolResult, ListToolsResult, Tool, + CallToolResultSchema, } from "@modelcontextprotocol/sdk/types.js"; import { AlertCircle, Send } from "lucide-react"; import { useState } from "react"; @@ -40,7 +41,7 @@ const ToolsTab = ({ if (!toolResult) return null; if ("content" in toolResult) { - const structuredResult = toolResult as CallToolResult; + const structuredResult = CallToolResultSchema.parse(toolResult); const isError = structuredResult.isError ?? false; return ( From fbac5b78bcd15b93338807aae11c9fa3e578a143 Mon Sep 17 00:00:00 2001 From: Jack Steam Date: Tue, 26 Nov 2024 12:47:39 -0600 Subject: [PATCH 2/3] feat: add data validation message --- client/src/components/ToolsTab.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/client/src/components/ToolsTab.tsx b/client/src/components/ToolsTab.tsx index b7e2cc1..320366c 100644 --- a/client/src/components/ToolsTab.tsx +++ b/client/src/components/ToolsTab.tsx @@ -5,7 +5,6 @@ import { Label } from "@/components/ui/label"; import { TabsContent } from "@/components/ui/tabs"; import { Textarea } from "@/components/ui/textarea"; import { - CallToolResult, ListToolsResult, Tool, CallToolResultSchema, @@ -41,7 +40,24 @@ const ToolsTab = ({ if (!toolResult) return null; if ("content" in toolResult) { - const structuredResult = CallToolResultSchema.parse(toolResult); + const parsedResult = CallToolResultSchema.safeParse(toolResult); + if (!parsedResult.success) { + return ( + <> +

Invalid Tool Result:

+
+              {JSON.stringify(toolResult, null, 2)}
+            
+

Errors:

+ {parsedResult.error.errors.map((error) => ( +
+                {JSON.stringify(error, null, 2)}
+              
+ ))} + + ); + } + const structuredResult = parsedResult.data; const isError = structuredResult.isError ?? false; return ( From 60578314aa2aa663dce3f18587888d476b186a00 Mon Sep 17 00:00:00 2001 From: Jack Steam Date: Tue, 26 Nov 2024 13:30:43 -0700 Subject: [PATCH 3/3] Update client/src/components/ToolsTab.tsx Co-authored-by: ashwin-ant --- client/src/components/ToolsTab.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/src/components/ToolsTab.tsx b/client/src/components/ToolsTab.tsx index 320366c..255ab67 100644 --- a/client/src/components/ToolsTab.tsx +++ b/client/src/components/ToolsTab.tsx @@ -49,8 +49,11 @@ const ToolsTab = ({ {JSON.stringify(toolResult, null, 2)}

Errors:

- {parsedResult.error.errors.map((error) => ( -
+            {parsedResult.error.errors.map((error, idx) => (
+              
                 {JSON.stringify(error, null, 2)}
               
))}