Skip to content

Commit 4e7d76a

Browse files
Sbussisoclaude
andcommitted
fix(mcp-setup): pause before exit so the terminal stays open
User reported the script "just closes when you run it with the client still on so I couldn't read the terminal." Confirmed root cause: when the script is launched into a fresh PowerShell window (double-click, Run dialog, or any parent process that runs powershell.exe and exits) the host closes as soon as the script returns — wiping the "Setup did NOT complete" / "Skipped (still running)" output the previous commit was specifically meant to surface. Add a Wait-ForExitKey / wait_for_exit_key call before each summary exit point in both scripts. The pause: - Skips when SOURCEBOX_SENTRY_MCP_NO_PAUSE=1 (CI / scripted callers won't hang waiting for keyboard input) - Skips when there's no interactive console (PowerShell: not ConsoleHost or not UserInteractive; bash: no tty and no /dev/tty) - Otherwise prompts "Press Enter to close..." and reads one line Only added to the three end-of-script summary exits, not the early arg-validation / cancel exits — those don't fire after the user has spent time selecting clients, so a sudden close isn't the same UX trap. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f7b0b44 commit 4e7d76a

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

backend/scripts/mcp-setup.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,23 @@ foreach ($idx in $selected) {
345345
Configure-Client -Name $c.Name -ConfigPath $c.Path
346346
}
347347

348+
# Wait for the user before exiting so the terminal window doesn't slam
349+
# shut on them mid-summary. Only relevant when the script was launched
350+
# into a fresh PowerShell window (double-click, "Run" dialog, or a
351+
# parent process that runs powershell.exe and exits) -- in those cases
352+
# the host closes as soon as the script returns. Skip when:
353+
# - SOURCEBOX_SENTRY_MCP_NO_PAUSE=1 (CI / scripted callers)
354+
# - We're not in an interactive console (piped stdin, no UI)
355+
function Wait-ForExitKey {
356+
if ($env:SOURCEBOX_SENTRY_MCP_NO_PAUSE -eq '1') { return }
357+
if (-not [Environment]::UserInteractive) { return }
358+
if ($Host.Name -ne 'ConsoleHost') { return }
359+
360+
Write-Host ""
361+
Write-Host " Press Enter to close..." -ForegroundColor DarkGray
362+
try { $null = Read-Host } catch { }
363+
}
364+
348365
# -- Summary -------------------------------------------
349366
#
350367
# Three possible end-states; pick the right banner + exit code for each.
@@ -399,6 +416,7 @@ if ($configuredCount -eq 0) {
399416
$dashUrl = $ServerUrl -replace "/mcp$", "/mcp"
400417
Write-Host " $dashUrl" -ForegroundColor Cyan
401418
Write-Host ""
419+
Wait-ForExitKey
402420
exit 1
403421
} elseif ($skippedCount -gt 0 -or $failedCount -gt 0) {
404422
# At least one configured, but at least one didn't. Don't claim
@@ -416,6 +434,7 @@ if ($configuredCount -eq 0) {
416434
# Exit 0 -- the script did configure something, the user just needs
417435
# a follow-up run for the rest. Use the warning banner to make that
418436
# visible without breaking shell pipelines that key off exit codes.
437+
Wait-ForExitKey
419438
exit 0
420439
} else {
421440
# Clean success.
@@ -429,5 +448,6 @@ if ($configuredCount -eq 0) {
429448
$dashUrl = $ServerUrl -replace "/mcp$", "/mcp"
430449
Write-Host " $dashUrl" -ForegroundColor Cyan
431450
Write-Host ""
451+
Wait-ForExitKey
432452
exit 0
433453
}

backend/scripts/mcp-setup.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,24 @@ for idx in "${SELECTED[@]}"; do
335335
configure_client "${CLIENT_NAMES[$idx]}" "${CLIENT_CONFIGS[$idx]}"
336336
done
337337

338+
# Wait for the user before exiting so a terminal launched just to run
339+
# this script doesn't slam shut on them mid-summary. Skip when:
340+
# - SOURCEBOX_SENTRY_MCP_NO_PAUSE=1 (CI / scripted callers)
341+
# - We're not attached to a tty (curl|bash | piped output)
342+
wait_for_exit_key() {
343+
if [[ "${SOURCEBOX_SENTRY_MCP_NO_PAUSE:-0}" == "1" ]]; then return; fi
344+
# If neither stdin nor /dev/tty is usable, we're being piped or run
345+
# under a context with no controlling terminal — don't block forever.
346+
if [[ ! -t 0 ]] && [[ ! -e /dev/tty ]]; then return; fi
347+
echo ""
348+
echo -e " ${DIM}Press Enter to close...${NC}"
349+
if [[ -t 0 ]]; then
350+
read -r _ || true
351+
else
352+
read -r _ </dev/tty || true
353+
fi
354+
}
355+
338356
# ── Summary ───────────────────────────────────────────
339357
#
340358
# Three possible end-states; pick the right banner + exit code for each.
@@ -394,6 +412,7 @@ if [[ $CONFIGURED_COUNT -eq 0 ]]; then
394412
echo -e " ${DIM}Manage your MCP keys at:${NC}"
395413
echo -e " ${CYAN}${DASHBOARD_URL}${NC}"
396414
echo ""
415+
wait_for_exit_key
397416
exit 1
398417
elif [[ $SKIPPED_COUNT -gt 0 || $FAILED_COUNT -gt 0 ]]; then
399418
# At least one configured, but at least one didn't. Don't claim
@@ -410,6 +429,7 @@ elif [[ $SKIPPED_COUNT -gt 0 || $FAILED_COUNT -gt 0 ]]; then
410429
# Exit 0 -- the script did configure something, the user just needs
411430
# a follow-up run for the rest. Use the warning banner to make that
412431
# visible without breaking shell pipelines that key off exit codes.
432+
wait_for_exit_key
413433
exit 0
414434
else
415435
# Clean success.
@@ -422,5 +442,6 @@ else
422442
echo -e " ${DIM}Manage your MCP keys at:${NC}"
423443
echo -e " ${CYAN}${DASHBOARD_URL}${NC}"
424444
echo ""
445+
wait_for_exit_key
425446
exit 0
426447
fi

0 commit comments

Comments
 (0)