Skip to content

Commit 351b696

Browse files
mcp-bridge: fix disconnect handling + error formatting
1 parent 9305910 commit 351b696

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tools/server/mcp-bridge/lib/sse-proxy.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ class ProxySSE {
392392

393393
currentTurn++;
394394
} catch (error) {
395+
// Check if error is due to client disconnection (stop button)
396+
if (sessionState.clientDisconnected) {
397+
this._log('Client disconnection during LLM call (expected)');
398+
break;
399+
}
400+
395401
// Handle LLM backend communication errors
396402
this._log(`Error during LLM call: ${error.message}`);
397403

@@ -404,7 +410,7 @@ class ProxySSE {
404410
choices: [
405411
{
406412
delta: {
407-
content: `\n\nUpstream LLM error:\n\`\`\`\n${errorDetails}\n\`\`\`\n`
413+
content: `\n\n\`\`\`\nUpstream LLM error:\n${errorDetails}\n\`\`\`\n`
408414
},
409415
finish_reason: 'stop'
410416
}
@@ -430,7 +436,7 @@ class ProxySSE {
430436
const warningChunk = {
431437
choices: [
432438
{
433-
delta: { content: '\n\nTurn limit reached' }
439+
delta: { content: '\n\n```\nTurn limit reached\n```\n' }
434440
}
435441
]
436442
};

0 commit comments

Comments
 (0)