Skip to content

refactor: adds Client/Reqeust customizer for HttpClientSseClientTransport #117

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

Conversation

Aliaksie
Copy link
Contributor

@Aliaksie Aliaksie commented Apr 7, 2025

This PR improves the construction pattern for HttpClientSseClientTransport by enforcing usage via a builder. It also introduces support for customizing HttpClient.Builder and HttpRequest.Builder before the transport is created. This provides a cleaner, more extensible way to configure HTTP behavior. Related to issue

Motivation and Context

I came across this project and really liked its design and goals, so I wanted to start contributing.

How Has This Been Tested?

Breaking Changes

Yes — this change makes the constructor for HttpClientSseClientTransport protected/private, which is a breaking change for users relying on direct instantiation.

To migrate, users should use the new builder-based approach for constructing HttpClientSseClientTransport.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

let me know if i missed something and need to add or if these changes don't make sense no problem just close this pr :-)

@Aliaksie Aliaksie changed the title refactor: adds HttpClientSseClientTransport customizer for HttpClientSseClientTransport refactor: adds Client/Reqeust customizer for HttpClientSseClientTransport Apr 7, 2025

/**
* Creates a new builder with the specified base URI.
* @param baseUri the base URI of the MCP server
*/
public Builder(String baseUri) {
Builder(String baseUri) {
Copy link
Member

Choose a reason for hiding this comment

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

We need to deprecate it first in order to avoid breaking the users. It is currently public.

Copy link
Contributor Author

@Aliaksie Aliaksie Apr 8, 2025

Choose a reason for hiding this comment

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

You're absolutely right — to avoid breaking existing users, I've marked all currently public constructors as @Deprecated and added clear Javadoc indicating that they will be removed in a future release.
In addition, I introduced an alternative package-private constructor, which will be used in the new builder-based approach.

Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

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

Left some comments around backwards compatibility, but this is a useful change, thanks!

* @param requestBuilder the HTTP request builder to use
* @param baseUri the base URI of the MCP server
* @param sseEndpoint the SSE endpoint path
* @param objectMapper the object mapper for JSON serialization/deserialization
* @throws IllegalArgumentException if objectMapper, clientBuilder, or headers is null
*/
public HttpClientSseClientTransport(HttpClient.Builder clientBuilder, HttpRequest.Builder requestBuilder,
String baseUri, String sseEndpoint, ObjectMapper objectMapper) {
HttpClientSseClientTransport(HttpClient httpClient, HttpRequest.Builder requestBuilder, String baseUri,
Copy link
Member

Choose a reason for hiding this comment

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

We need to deprecate it first in order to avoid breaking the users. It is currently public.

Copy link
Contributor Author

@Aliaksie Aliaksie Apr 8, 2025

Choose a reason for hiding this comment

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

You're absolutely right — to avoid breaking existing users, I've marked all currently public constructors as @Deprecated and added clear Javadoc indicating that they will be removed in a future release.
In addition, I introduced an alternative package-private constructor, which will be used in the new builder-based approach.

@tzolov tzolov self-assigned this Apr 9, 2025
@tzolov tzolov added this to the 0.9.0 milestone Apr 9, 2025
@tzolov tzolov added client enhancement New feature or request labels Apr 9, 2025
tzolov added a commit that referenced this pull request Apr 9, 2025
…customization API (#117)

- Add builder customizeClient() and customizeRequest() methods
- Enable HTTP client and request configuration through consumer-based customization
- Deprecate direct constructors in favor of the more flexible builder approach
- Add test coverage for customization capabilities

Co-authored-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
@tzolov
Copy link
Contributor

tzolov commented Apr 9, 2025

Thanks @Aliaksie

Rebased, added tests and merged at fab434c

@tzolov tzolov closed this Apr 9, 2025
@Aliaksie Aliaksie deleted the issue114/clean-httpClientSseClientTransport branch April 15, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants