@@ -60,7 +60,7 @@ export function McpServers({
6060 const [ toolForms , setToolForms ] = useState < Record < string , Record < string , any > > > ( { } )
6161 const [ toolExecutionLogs , setToolExecutionLogs ] = useState < Record < string , string > > ( { } )
6262 const logRef = useRef < HTMLDivElement > ( null )
63- const executionLogRef = useRef < HTMLTextAreaElement > ( null )
63+ const executionLogRefs = useRef < Record < string , HTMLTextAreaElement | null > > ( { } )
6464
6565 // Extract connection properties
6666 const { state, tools, error, log, authUrl, disconnect, authenticate } =
@@ -211,33 +211,51 @@ export function McpServers({
211211 } ) )
212212 }
213213
214+ // Helper function to clean and update execution log
215+ const updateExecutionLog = ( toolName : string , newContent : string ) => {
216+ setToolExecutionLogs ( prev => {
217+ const currentLog = prev [ toolName ] || ''
218+ const updatedLog = currentLog + newContent
219+ // Remove blank lines and rejoin
220+ const cleanedLog = updatedLog
221+ . split ( '\n' )
222+ . filter ( line => line . trim ( ) !== '' )
223+ . join ( '\n' )
224+ return {
225+ ...prev ,
226+ [ toolName ] : cleanedLog + '\n'
227+ }
228+ } )
229+ }
230+
214231 // Handle tool execution
215232 const handleRunTool = async ( tool : Tool ) => {
216233 const args = toolForms [ tool . name ] || { }
217234 const argsStr = JSON . stringify ( args )
218235
219236 // Add execution start message
220237 const startMessage = `Calling ${ tool . name } (${ argsStr } )\n`
221- setToolExecutionLogs ( prev => ( {
222- ...prev ,
223- [ tool . name ] : ( prev [ tool . name ] || '' ) + startMessage
224- } ) )
238+ updateExecutionLog ( tool . name , startMessage )
225239
226240 try {
227241 const result = await connectionData . callTool ( tool . name , args )
228242 const resultStr = typeof result === 'string' ? result : JSON . stringify ( result , null , 2 )
229- setToolExecutionLogs ( prev => ( {
230- ...prev ,
231- [ tool . name ] : ( prev [ tool . name ] || '' ) + `${ resultStr } \n\n`
232- } ) )
243+ updateExecutionLog ( tool . name , `${ resultStr } \n` )
233244 } catch ( error ) {
234- setToolExecutionLogs ( prev => ( {
235- ...prev ,
236- [ tool . name ] : ( prev [ tool . name ] || '' ) + `Error: ${ error } \n\n`
237- } ) )
245+ updateExecutionLog ( tool . name , `Error: ${ error } \n` )
238246 }
239247 }
240248
249+ // Auto-scroll execution logs to bottom when they change
250+ useEffect ( ( ) => {
251+ Object . keys ( toolExecutionLogs ) . forEach ( toolName => {
252+ const textarea = executionLogRefs . current [ toolName ]
253+ if ( textarea ) {
254+ textarea . scrollTop = textarea . scrollHeight
255+ }
256+ } )
257+ } , [ toolExecutionLogs ] )
258+
241259 // Clear execution log for specific tool
242260 const clearExecutionLog = ( toolName : string ) => {
243261 setToolExecutionLogs ( prev => ( {
@@ -432,9 +450,10 @@ export function McpServers({
432450 </ button >
433451 </ div >
434452 < textarea
453+ ref = { ( el ) => { executionLogRefs . current [ tool . name ] = el } }
435454 value = { toolExecutionLogs [ tool . name ] }
436455 readOnly
437- className = "w-full h-32 p-2 border border-gray-200 rounded text-xs font-mono bg-gray-50 resize-none placeholder-gray-300"
456+ className = "w-full h-32 p-2 border border-gray-200 rounded text-[10px] font-mono bg-gray-50 resize-none placeholder-gray-300"
438457 placeholder = "Tool execution results will appear here..."
439458 />
440459 </ div >
0 commit comments