Skip to content

feat: support sse customize httpClient #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

archever
Copy link

@archever archever commented Apr 22, 2025

add support for customize SSE client with http transport and http proxy

Summary by CodeRabbit

  • New Features

    • Added support for configuring a proxy or custom HTTP transport for SSE client connections.
    • Introduced an option to use a custom HTTP client for SSE connections.
  • Chores

    • Updated Go module version and dependencies.

Copy link
Contributor

coderabbitai bot commented Apr 22, 2025

Walkthrough

A new client option function WithHttpClient was added to the SSE transport, allowing users to provide a custom *http.Client instance. This option sets the internal HTTP client of the SSE transport directly, overriding the default client. Additionally, the Go module file was updated to specify the Go version as "1.23.0" instead of "1.23". No other functional or dependency changes were made.

Changes

Files/Paths Change Summary
client/transport/sse.go Added WithHttpClient client option to allow setting a custom *http.Client in the SSE transport.
go.mod Updated Go version from "1.23" to "1.23.0".

📜 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 8735592 and 37dec5a.

📒 Files selected for processing (2)
  • client/transport/sse.go (1 hunks)
  • go.mod (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • go.mod
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/transport/sse.go

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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

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

🧹 Nitpick comments (2)
client/transport/sse.go (2)

49-57: Consider preserving default transport settings

While the proxy implementation works correctly, this approach replaces the entire transport with a new one that only has the proxy setting. Consider preserving other useful transport settings like connection pooling, timeouts, TLS configuration, etc.

func WithProxy(proxy httpproxy.Config) ClientOption {
	return func(sc *SSE) {
-		sc.httpClient.Transport = &http.Transport{
-			Proxy: func(r *http.Request) (*url.URL, error) {
-				return proxy.ProxyFunc()(r.URL)
-			},
-		}
+		// Get the existing transport or create a new one
+		transport := sc.httpClient.Transport
+		if transport == nil {
+			transport = http.DefaultTransport
+		}
+		
+		// Try to preserve existing settings if it's an http.Transport
+		if t, ok := transport.(*http.Transport); ok {
+			// Clone the transport and update the proxy
+			newTransport := t.Clone()
+			newTransport.Proxy = func(r *http.Request) (*url.URL, error) {
+				return proxy.ProxyFunc()(r.URL)
+			}
+			sc.httpClient.Transport = newTransport
+		} else {
+			// If it's not an http.Transport, create a new one
+			sc.httpClient.Transport = &http.Transport{
+				Proxy: func(r *http.Request) (*url.URL, error) {
+					return proxy.ProxyFunc()(r.URL)
+				},
+			}
+		}
	}
}

59-63: Add nil check for transport

It's good practice to validate that the provided transport is not nil to prevent potential nil pointer dereference issues later.

func WithTransport(trans http.RoundTripper) ClientOption {
	return func(sc *SSE) {
+		if trans == nil {
+			return
+		}
		sc.httpClient.Transport = trans
	}
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6760d87 and 8735592.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • client/transport/sse.go (2 hunks)
  • go.mod (1 hunks)
🔇 Additional comments (3)
go.mod (1)

9-9:

✅ Verification successful

Verify dependency compatibility

The new dependencies on golang.org/x/net and golang.org/x/text are appropriate for implementing proxy functionality. However, ensure these specific versions exist and are compatible with your other dependencies.

Also applies to: 15-15


🌐 Web query:

Are golang.org/x/net v0.39.0 and golang.org/x/text v0.24.0 stable releases?

💡 Result:

Stability of golang.org/x/net v0.39.0 and golang.org/x/text v0.24.0

golang.org/x/net v0.39.0:

  • The golang.org/x/net module uses semantic versioning. However, the go.mod version is still v0.x.x, meaning it has not reached major version v1. According to Go ecosystem conventions, a module is only considered formally "stable" after reaching v1.0.0[1][8].
  • The package is widely used, and version tags (like v0.39.0) are regularly published and maintained, including security fixes[5]. But as the documentation notes, "When a project reaches major version v1 it is considered stable"[1][8].
  • Thus, v0.39.0 is not officially marked as a "stable" release, though it is considered mature and is commonly used in production[1][8].

golang.org/x/text v0.24.0:

  • Like x/net, golang.org/x/text also uses v0.x.x versioning and has not reached v1.0.0.
  • The documentation for golang.org/x/text indicates that it is a widely used supplementary package, supports Unicode updates, and is maintained[6][9]. However, backward compatibility is not strictly guaranteed, and the project is not considered "stable" until it hits v1.0.0[6].
  • Therefore, v0.24.0 is not an official "stable" release by Go module conventions, although it is actively used and supported[6][9].

Summary Table

Module Version Officially Stable? Actively Maintained Notes
golang.org/x/net v0.39.0 No Yes Pre-v1, stability once v1.0.0 is reached[1][8]
golang.org/x/text v0.24.0 No Yes Pre-v1, backward compatibility not guaranteed[6]

Conclusion

Neither golang.org/x/net v0.39.0 nor golang.org/x/text v0.24.0 are officially "stable releases" according to Go's semantic versioning policy: both are pre-v1 modules. They are, however, mature, well-maintained, and widely used in production by the Go community[1][6][8]. If you require formal stability guarantees (such as strict semantic versioning and backward compatibility), you should wait for v1.0.0 releases. For practical purposes, current releases are considered reliable for most use cases as long as you review changelogs and test updates accordingly.

Citations:


Dependency Stability Verification

Both golang.org/x/net v0.39.0 and golang.org/x/text v0.24.0 are pre‑v1 modules (not formally “stable” per Go’s semantic versioning), but they are mature, widely used, and actively maintained.

• golang.org/x/net v0.39.0: pre‑v1, regularly updated with security fixes
• golang.org/x/text v0.24.0: pre‑v1, supports Unicode updates but may introduce non‑backward‑compatible changes before v1.0.0

No code changes required—just ensure your compatibility and integration tests pass when upgrading these dependencies.

client/transport/sse.go (2)

18-18: Appropriate import for proxy functionality

The addition of the httpproxy package import is appropriate for the new proxy functionality.


49-63: Note on option ordering

Be aware that WithProxy and WithTransport options will override each other if both are used. The last option applied will determine the final transport configuration. Consider documenting this behavior or providing a more comprehensive option that handles both settings.

@@ -1,15 +1,17 @@
module github.com/mark3labs/mcp-go

go 1.23
go 1.23.0
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Note on Go version specificity

Specifying the patch version (1.23.0) is more precise than just the minor version (1.23). However, ensure that this version aligns with your deployment targets, as Go 1.23 would be a future release as of April 2024.


🌐 Web query:

What is the latest stable version of Go currently available?

💡 Result:

Latest Stable Version of Go

The latest stable version of the Go programming language currently available is Go 1.24.2, which was released on April 1, 2025[1][9]. This version includes security and bug fixes for several packages including net/http, crypto/tls, go/types, and others[1].

Go 1.24 is a major release, introducing notable changes such as full support for generic type aliases and several performance improvements in the runtime and toolchain[2][7]. The 1.24.2 release is the most recent minor revision, providing important security updates and bug fixes to ensure stability and security for developers[1][9].

Citations:


Upgrade Go version in go.mod to the latest stable release

The go.mod file currently specifies:

  • File: go.mod
    Line 3: go 1.23.0

As of April 2025, Go 1.24.2 is the latest stable release, which includes important security patches and performance improvements. Please update the Go version directive to align with supported deployment targets:

--- go.mod
@@ line 3
- go 1.23.0
+ go 1.24.2
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
go 1.23.0
go 1.24.2

@@ -45,6 +46,22 @@ func WithHeaders(headers map[string]string) ClientOption {
}
}

func WithProxy(proxy httpproxy.Config) ClientOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just expose a method to modify httpClient?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would be in favor of that approach which is way more flexible

Copy link
Author

Choose a reason for hiding this comment

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

updated, just expose a httpClient option

@archever archever changed the title feat: support sse transport / proxy option feat: support sse customize httpClient Apr 24, 2025
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.

3 participants