@@ -66,10 +66,20 @@ const ToolsTab = ({
6666 const [ isToolRunning , setIsToolRunning ] = useState ( false ) ;
6767 const [ isOutputSchemaExpanded , setIsOutputSchemaExpanded ] = useState ( false ) ;
6868 const [ isMetaExpanded , setIsMetaExpanded ] = useState ( false ) ;
69+ const [ hasValidationErrors , setHasValidationErrors ] = useState ( false ) ;
6970 const formRefs = useRef < Record < string , DynamicJsonFormRef | null > > ( { } ) ;
7071 const { toast } = useToast ( ) ;
7172 const { copied, setCopied } = useCopy ( ) ;
7273
74+ // Function to check if any form has validation errors
75+ const checkValidationErrors = ( ) => {
76+ const errors = Object . values ( formRefs . current ) . some (
77+ ( ref ) => ref && ! ref . validateJson ( ) . isValid ,
78+ ) ;
79+ setHasValidationErrors ( errors ) ;
80+ return errors ;
81+ } ;
82+
7383 useEffect ( ( ) => {
7484 const params = Object . entries (
7585 selectedTool ?. inputSchema . properties ?? [ ] ,
@@ -82,6 +92,12 @@ const ToolsTab = ({
8292 ) ,
8393 ] ) ;
8494 setParams ( Object . fromEntries ( params ) ) ;
95+
96+ // Reset validation errors when switching tools
97+ setHasValidationErrors ( false ) ;
98+
99+ // Clear form refs for the previous tool
100+ formRefs . current = { } ;
85101 } , [ selectedTool ] ) ;
86102
87103 return (
@@ -199,6 +215,8 @@ const ToolsTab = ({
199215 ...params ,
200216 [ key ] : newValue ,
201217 } ) ;
218+ // Check validation after a short delay to allow form to update
219+ setTimeout ( checkValidationErrors , 100 ) ;
202220 } }
203221 />
204222 </ div >
@@ -235,6 +253,8 @@ const ToolsTab = ({
235253 ...params ,
236254 [ key ] : newValue ,
237255 } ) ;
256+ // Check validation after a short delay to allow form to update
257+ setTimeout ( checkValidationErrors , 100 ) ;
238258 } }
239259 />
240260 </ div >
@@ -317,10 +337,7 @@ const ToolsTab = ({
317337 < Button
318338 onClick = { async ( ) => {
319339 // Validate JSON inputs before calling tool
320- const hasValidationErrors = Object . values (
321- formRefs . current ,
322- ) . some ( ( ref ) => ref && ! ref . validateJson ( ) . isValid ) ;
323- if ( hasValidationErrors ) return ;
340+ if ( checkValidationErrors ( ) ) return ;
324341
325342 try {
326343 setIsToolRunning ( true ) ;
@@ -329,7 +346,7 @@ const ToolsTab = ({
329346 setIsToolRunning ( false ) ;
330347 }
331348 } }
332- disabled = { isToolRunning }
349+ disabled = { isToolRunning || hasValidationErrors }
333350 >
334351 { isToolRunning ? (
335352 < >
0 commit comments