Skip to content

Conversation

caarlos0
Copy link
Contributor

@caarlos0 caarlos0 commented Aug 2, 2025

So it logs to a logger instead of stdout.
I also deprecated WithLogger and added a WithHTTPLogger, so its more consistent.

If you agree with these changes, I'll add tests, docs, etc.


Description

Fixes #<issue_number> (if applicable)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • MCP spec compatibility implementation
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Tests only (no functional changes)
  • Other (please describe):

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly

MCP Spec Compliance

  • This PR implements a feature defined in the MCP specification
  • Link to relevant spec section: Link text
  • Implementation follows the specification exactly

Additional Information

Summary by CodeRabbit

  • New Features

    • Added support for structured logging in the SSE and Stdio clients, allowing injection of custom loggers for enhanced error reporting.
    • Introduced improved logging for error events during SSE and Stdio transport operations.
    • Expanded documentation with examples on configuring clients with custom loggers and enhanced logging setup.
  • Refactor

    • Updated naming for HTTP logger configuration to improve clarity, while maintaining backward compatibility with a deprecated function.
  • Tests

    • Added tests to verify proper error logging for SSE stream errors and Stdio response writing failures.
  • Documentation

    • Enhanced client transport docs with detailed examples on logging configuration and client customization.

So it logs to a logger instead of stdout.

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Copy link
Contributor

coderabbitai bot commented Aug 2, 2025

Walkthrough

Structured logging support was added to the SSE and Stdio clients by introducing logger fields and associated configuration options. For the StreamableHTTP transport, the logger configuration function was renamed for clarity, with a deprecated wrapper retained for backward compatibility. New tests were added to verify error logging in SSE and Stdio transports. Minor formatting and documentation updates were also made.

Changes

Cohort / File(s) Change Summary
SSE Client Logging Enhancements
client/transport/sse.go, client/sse.go, client/transport/sse_test.go
Added a logger field to the SSE struct, replaced fmt.Printf with structured logging, introduced WithSSELogger option, added a test verifying error logging of JSON unmarshaling errors, and removed extraneous blank lines.
Stdio Client Logging Enhancements
client/transport/stdio.go, client/transport/stdio_test.go
Added a logger field to the Stdio struct, replaced direct fmt.Printf error output with structured logging, introduced WithCommandLogger option, and added a test verifying error logging on response writing failure.
HTTP Logger Option Renaming and Deprecation
client/transport/streamable_http.go, client/transport/streamable_http_test.go
Renamed WithLogger to WithHTTPLogger, added a deprecated wrapper for backward compatibility, and cleaned up trailing blank lines in tests.
Documentation Updates
www/docs/pages/clients/transports.mdx
Added examples demonstrating client creation with custom logging and configuration options for STDIO, StreamableHTTP, and SSE transports. Included a new "Logging Configuration" section with a custom logger example.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • ezynda3

Suggested labels

type: enhancement

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 379ad17 and 08f1637.

📒 Files selected for processing (1)
  • client/transport/stdio_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/transport/stdio_test.go
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ezynda3
Copy link
Contributor

ezynda3 commented Aug 3, 2025

@caarlos0 this looks good. Please add some tests and possibly some documentation in www/docs and it should be ready to merge

@caarlos0 caarlos0 changed the title feat: allow to set a custom logger in the SSE client feat: allow to set a custom logger in the SSE and STDIO client Aug 4, 2025
@caarlos0 caarlos0 changed the title feat: allow to set a custom logger in the SSE and STDIO client feat: allow to set a custom logger in the SSE and STDIO clients Aug 4, 2025
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
@caarlos0
Copy link
Contributor Author

caarlos0 commented Aug 4, 2025

@ezynda3 added tests, docs, and also implemented with logger for STDIO 🙏🏻

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 896af7c and 379ad17.

📒 Files selected for processing (8)
  • client/sse.go (0 hunks)
  • client/transport/sse.go (7 hunks)
  • client/transport/sse_test.go (9 hunks)
  • client/transport/stdio.go (7 hunks)
  • client/transport/stdio_test.go (2 hunks)
  • client/transport/streamable_http.go (1 hunks)
  • client/transport/streamable_http_test.go (0 hunks)
  • www/docs/pages/clients/transports.mdx (19 hunks)
💤 Files with no reviewable changes (2)
  • client/sse.go
  • client/transport/streamable_http_test.go
✅ Files skipped from review due to trivial changes (2)
  • client/transport/stdio.go
  • www/docs/pages/clients/transports.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
  • client/transport/streamable_http.go
  • client/transport/sse.go
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: leavez
PR: mark3labs/mcp-go#114
File: client/transport/sse.go:137-179
Timestamp: 2025-04-06T10:07:06.685Z
Learning: The SSE client implementation in the MCP-Go project uses a 30-second timeout for reading SSE events to match the behavior of the original implementation before the transport layer refactoring.
📚 Learning: the sse client implementation in the mcp-go project uses a 30-second timeout for reading sse events ...
Learnt from: leavez
PR: mark3labs/mcp-go#114
File: client/transport/sse.go:137-179
Timestamp: 2025-04-06T10:07:06.685Z
Learning: The SSE client implementation in the MCP-Go project uses a 30-second timeout for reading SSE events to match the behavior of the original implementation before the transport layer refactoring.

Applied to files:

  • client/transport/sse_test.go
📚 Learning: in the mcptest package, prefer returning errors from helper functions rather than calling t.fatalf()...
Learnt from: octo
PR: mark3labs/mcp-go#149
File: mcptest/mcptest.go:0-0
Timestamp: 2025-04-21T21:26:32.945Z
Learning: In the mcptest package, prefer returning errors from helper functions rather than calling t.Fatalf() directly, giving callers flexibility in how to handle errors.

Applied to files:

  • client/transport/sse_test.go
  • client/transport/stdio_test.go
📚 Learning: in the mark3labs/mcp-go project, the mcpserver.capabilities field is a struct value (servercapabilit...
Learnt from: ezynda3
PR: mark3labs/mcp-go#461
File: server/sampling.go:22-26
Timestamp: 2025-06-30T07:13:17.052Z
Learning: In the mark3labs/mcp-go project, the MCPServer.capabilities field is a struct value (serverCapabilities), not a pointer, so it cannot be nil and doesn't require nil checking. Only pointer fields within the capabilities struct should be checked for nil.

Applied to files:

  • client/transport/sse_test.go
  • client/transport/stdio_test.go
📚 Learning: in go, when accessing fields or methods of embedded structs, use the direct field name without the e...
Learnt from: sunerpy
PR: mark3labs/mcp-go#484
File: server/session.go:175-175
Timestamp: 2025-07-10T09:30:05.381Z
Learning: In Go, when accessing fields or methods of embedded structs, use the direct field name without the embedded field path (e.g., `notification.Method` instead of `notification.Notification.Method`). Using the full path triggers golangci-lint QF1008 warning and violates Go conventions for embedded fields.

Applied to files:

  • client/transport/sse_test.go
📚 Learning: in mcp-go project, the maintainer prefers keeping builder pattern apis simple without excessive vali...
Learnt from: davidleitw
PR: mark3labs/mcp-go#451
File: mcp/tools.go:1192-1217
Timestamp: 2025-06-26T09:38:18.629Z
Learning: In mcp-go project, the maintainer prefers keeping builder pattern APIs simple without excessive validation for edge cases. The WithOutput* functions are designed to assume correct usage rather than defensive programming, following the principle of API simplicity over comprehensive validation.

Applied to files:

  • client/transport/stdio_test.go
🪛 GitHub Check: lint
client/transport/stdio_test.go

[failure] 556-556:
Error return value of stdoutWriter.Write is not checked (errcheck)

🪛 GitHub Actions: golangci-lint
client/transport/stdio_test.go

[error] 556-556: golangci-lint: Error return value of stdoutWriter.Write is not checked (errcheck)

🔇 Additional comments (3)
client/transport/stdio_test.go (1)

8-8: LGTM!

The new imports are appropriately added to support the new test functionality - io for pipe operations, strings for string checking, and require for enhanced assertions.

Also applies to: 13-13, 20-20

client/transport/sse_test.go (2)

7-7: LGTM!

The import reordering follows Go conventions for better code organization, grouping standard library and third-party imports appropriately.

Also applies to: 9-10, 17-17


870-914: Excellent error logging test implementation.

This test effectively verifies that JSON unmarshaling errors in SSE streams are properly logged. The test design is solid:

  • Mock server sends invalid JSON to trigger the error condition
  • Custom logger captures error messages for verification
  • Proper cleanup and timeout handling
  • Uses testify/require for enhanced assertions

The test ensures the logging improvements in the SSE transport work correctly under error conditions.

@ezynda3 ezynda3 merged commit 6da5cd1 into mark3labs:main Aug 5, 2025
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.

5 participants