From 52a409c1e25e18008bdcaf2468e637d4ca6cf1a7 Mon Sep 17 00:00:00 2001 From: Glen Maddern Date: Tue, 10 Jun 2025 21:18:30 +1000 Subject: [PATCH] bit more tidying before publish --- .../inspector/src/components/McpServers.tsx | 47 +++++++++++++------ examples/inspector/vite.config.ts | 2 +- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/examples/inspector/src/components/McpServers.tsx b/examples/inspector/src/components/McpServers.tsx index c4670ea..b568463 100644 --- a/examples/inspector/src/components/McpServers.tsx +++ b/examples/inspector/src/components/McpServers.tsx @@ -60,7 +60,7 @@ export function McpServers({ const [toolForms, setToolForms] = useState>>({}) const [toolExecutionLogs, setToolExecutionLogs] = useState>({}) const logRef = useRef(null) - const executionLogRef = useRef(null) + const executionLogRefs = useRef>({}) // Extract connection properties const { state, tools, error, log, authUrl, disconnect, authenticate } = @@ -211,6 +211,23 @@ export function McpServers({ })) } + // Helper function to clean and update execution log + const updateExecutionLog = (toolName: string, newContent: string) => { + setToolExecutionLogs(prev => { + const currentLog = prev[toolName] || '' + const updatedLog = currentLog + newContent + // Remove blank lines and rejoin + const cleanedLog = updatedLog + .split('\n') + .filter(line => line.trim() !== '') + .join('\n') + return { + ...prev, + [toolName]: cleanedLog + '\n' + } + }) + } + // Handle tool execution const handleRunTool = async (tool: Tool) => { const args = toolForms[tool.name] || {} @@ -218,26 +235,27 @@ export function McpServers({ // Add execution start message const startMessage = `Calling ${tool.name}(${argsStr})\n` - setToolExecutionLogs(prev => ({ - ...prev, - [tool.name]: (prev[tool.name] || '') + startMessage - })) + updateExecutionLog(tool.name, startMessage) try { const result = await connectionData.callTool(tool.name, args) const resultStr = typeof result === 'string' ? result : JSON.stringify(result, null, 2) - setToolExecutionLogs(prev => ({ - ...prev, - [tool.name]: (prev[tool.name] || '') + `${resultStr}\n\n` - })) + updateExecutionLog(tool.name, `${resultStr}\n`) } catch (error) { - setToolExecutionLogs(prev => ({ - ...prev, - [tool.name]: (prev[tool.name] || '') + `Error: ${error}\n\n` - })) + updateExecutionLog(tool.name, `Error: ${error}\n`) } } + // Auto-scroll execution logs to bottom when they change + useEffect(() => { + Object.keys(toolExecutionLogs).forEach(toolName => { + const textarea = executionLogRefs.current[toolName] + if (textarea) { + textarea.scrollTop = textarea.scrollHeight + } + }) + }, [toolExecutionLogs]) + // Clear execution log for specific tool const clearExecutionLog = (toolName: string) => { setToolExecutionLogs(prev => ({ @@ -432,9 +450,10 @@ export function McpServers({