Skip to content

Commit 5396310

Browse files
committed
Fix: Update MCP console handling to properly display stdout and error messages with correct styling
1 parent 9e4e9ad commit 5396310

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/services/mcp/McpHub.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,12 @@ export class McpHub {
499499
if (isInfoOrStartupMessage) {
500500
// Log normal informational messages
501501
console.log(`Server "${name}" info:`, output)
502-
// Add to connection history with stdout level so they appear in white
502+
// Tag the message with stdout_info so we can identify it in the UI
503+
// but map it to "info" level for type compatibility
503504
const connection = this.findConnection(name, source)
504505
if (connection) {
505-
this.appendErrorMessage(connection, output, "stdout")
506+
// Add a prefix to identify this as a stdout message that's been mapped to info
507+
this.appendErrorMessage(connection, `[STDOUT] ${output}`, "info")
506508
await this.notifyWebviewOfServerChanges()
507509
}
508510
} else {
@@ -530,7 +532,8 @@ export class McpHub {
530532
console.log(`Server "${name}" stdout:`, output)
531533
const connection = this.findConnection(name, source)
532534
if (connection) {
533-
this.appendErrorMessage(connection, output, "stdout")
535+
// Add a prefix to identify this as a stdout message that's been mapped to info
536+
this.appendErrorMessage(connection, `[STDOUT] ${output}`, "info")
534537
await this.notifyWebviewOfServerChanges()
535538
}
536539
})
@@ -619,14 +622,14 @@ export class McpHub {
619622
connection.server.errorHistory = []
620623
}
621624

622-
// Map "stdout" to "info" to avoid TypeScript errors
623-
// while still allowing them to be displayed differently in the UI
624-
const mappedLevel = level === "stdout" ? "info" : level
625+
// Note: We no longer need to map "stdout" to "info" here
626+
// as we're now adding the [STDOUT] prefix to the message itself
627+
// and directly using "info" level in the calling code
625628

626629
connection.server.errorHistory.push({
627630
message: truncatedError,
628631
timestamp: Date.now(),
629-
level: mappedLevel,
632+
level: level,
630633
})
631634

632635
// Keep only the last 100 errors

webview-ui/src/components/mcp/McpErrorRow.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export const McpErrorRow = ({ error }: McpErrorRowProps) => {
1212
// Add debugging to log what level is coming in
1313
console.log(`McpErrorRow level: ${error.level} for message: ${error.message.substring(0, 20)}...`)
1414

15+
// First check for explicitly prefixed stdout messages
16+
if (error.level === "info" && error.message.startsWith("[STDOUT]")) {
17+
// Use regular foreground color for stdout messages
18+
return "var(--vscode-foreground)"
19+
}
20+
1521
// Check if this is a stdout message (mapped to info in backend)
1622
// Common patterns for stdout messages
1723
const isStdoutMessage =
@@ -44,10 +50,15 @@ export const McpErrorRow = ({ error }: McpErrorRowProps) => {
4450
}
4551
}, [error.level, error.message])
4652

53+
// Strip [STDOUT] prefix from the message for cleaner display
54+
const displayMessage = error.message.startsWith("[STDOUT]")
55+
? error.message.substring("[STDOUT]".length).trim()
56+
: error.message
57+
4758
return (
4859
<div className="text-sm bg-vscode-textCodeBlock-background border-l-2 p-2" style={{ borderColor: color }}>
4960
<div className="mb-1" style={{ color }}>
50-
{error.message}
61+
{displayMessage}
5162
</div>
5263
<div className="text-xs text-vscode-descriptionForeground">
5364
{formatRelative(error.timestamp, new Date())}

0 commit comments

Comments
 (0)