Skip to content

feat: capture and log container stderr when MCP connection fails#615

Merged
lpcox merged 1 commit intomainfrom
lpcox/print-failed-container-logs
Feb 3, 2026
Merged

feat: capture and log container stderr when MCP connection fails#615
lpcox merged 1 commit intomainfrom
lpcox/print-failed-container-logs

Conversation

@lpcox
Copy link
Collaborator

@lpcox lpcox commented Feb 3, 2026

When a container/process fails to launch, the stderr output is now captured and logged to help diagnose issues. This is particularly useful for debugging container startup failures where the error message is written to stderr.

The SDK's CommandTransport only uses stdin/stdout for the MCP protocol, so we can safely capture stderr separately for debugging purposes.

When a container/process fails to launch, the stderr output is now captured
and logged to help diagnose issues. This is particularly useful for debugging
container startup failures where the error message is written to stderr.

The SDK's CommandTransport only uses stdin/stdout for the MCP protocol,
so we can safely capture stderr separately for debugging purposes.
Copilot AI review requested due to automatic review settings February 3, 2026 22:09
@lpcox lpcox merged commit 16b80f1 into main Feb 3, 2026
6 checks passed
@lpcox lpcox deleted the lpcox/print-failed-container-logs branch February 3, 2026 22:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds stderr capture and logging functionality to help diagnose MCP container/process startup failures. When a connection to an MCP backend server fails, the stderr output from the failed process is now captured and logged to provide better debugging information.

Changes:

  • Added stderr capture using a bytes.Buffer before attempting MCP connection
  • Log captured stderr output when connection fails, with formatted output for better readability
  • Added explanatory comments about why stderr can be safely captured (CommandTransport uses stdin/stdout)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +218 to +225
stderrOutput := strings.TrimSpace(stderrBuf.String())
if stderrOutput != "" {
logger.LogErrorMd("backend", "MCP backend stderr output:\n%s", stderrOutput)
log.Printf(" 📋 Container/Process stderr output:")
for _, line := range strings.Split(stderrOutput, "\n") {
log.Printf(" %s", line)
}
}
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential race condition: When client.Connect fails and the context is cancelled (line 208), the process may still be writing to stderr. Reading stderrBuf.String() immediately could miss output or cause a data race with concurrent writes. Consider calling cmd.Wait() after the context cancellation to ensure the process has fully terminated and all stderr output has been written to the buffer before reading it. This is especially important for container/process diagnostics which is the purpose of this feature.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant