Skip to content

fix(examples): redirect hook output to stderr in everything server#828

Merged
ezynda3 merged 1 commit into
mark3labs:mainfrom
blackwell-systems:fix/everything-stderr-hooks
Apr 30, 2026
Merged

fix(examples): redirect hook output to stderr in everything server#828
ezynda3 merged 1 commit into
mark3labs:mainfrom
blackwell-systems:fix/everything-stderr-hooks

Conversation

@blackwell-systems

@blackwell-systems blackwell-systems commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • All 8 fmt.Printf calls in the everything server's hooks wrote to stdout
  • In stdio mode, stdout is the JSON-RPC transport, so hook output corrupts the protocol stream
  • The longRunningOperation tool's time.Sleep creates a timing window that makes this reliably reproducible, but any hook firing during a tool call can trigger it
  • Fix: redirect all hook output to fmt.Fprintf(os.Stderr, ...)

Test plan

  • go build ./examples/everything/ passes
  • Verified with mcp-assert: longRunningOperation no longer crashes the stdio transport

Fixes #826

Summary by CodeRabbit

  • Bug Fixes
    • Fixed hook logging output redirection to prevent interference with JSON-RPC communication in stdio mode. Hook logs are now properly separated from the primary output stream.

All fmt.Printf calls in the hooks wrote to stdout, which is the
JSON-RPC transport in stdio mode. When a tool handler sleeps
(longRunningOperation), hook output interleaves with protocol framing
and corrupts the connection.

Redirected all hook output to os.Stderr. Hooks remain functional for
debugging but no longer interfere with the stdio transport.

Fixes mark3labs#826
@mark-iii-labs-huly

Copy link
Copy Markdown

Connected to Huly®: MCP_G-393

@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9e406292-d44e-4669-98b4-b61afc9b000e

📥 Commits

Reviewing files that changed from the base of the PR and between 092e9be and 66104ef.

📒 Files selected for processing (1)
  • examples/everything/main.go

Walkthrough

Hook logging output in examples/everything/main.go is redirected from stdout to stderr across all hook lifecycle callbacks (before any, initialization, success/error, tool call before/after), with a comment noting that stdout is reserved for JSON-RPC in stdio mode.

Changes

Cohort / File(s) Summary
Hook logging output redirection
examples/everything/main.go
All fmt.Printf calls in hook callbacks replaced with fmt.Fprintf(os.Stderr, ...) to prevent stdout pollution, preserving stdio transport protocol integrity. Added clarifying comment about stdout reservation for JSON-RPC.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: redirecting hook output to stderr in the everything server example.
Description check ✅ Passed The description covers the problem, root cause, and solution clearly, though it doesn't follow the template structure with formal sections.
Linked Issues check ✅ Passed The PR directly addresses issue #826 by fixing the root cause: redirecting all hook output from stdout to stderr prevents corruption of the JSON-RPC stdio transport.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the hook output issue in examples/everything/main.go as specified in issue #826; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ezynda3 ezynda3 merged commit dc2ea91 into mark3labs:main Apr 30, 2026
4 checks passed
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.

examples/everything: longRunningOperation crashes stdio transport

2 participants