Class HttpClientStreamableHttpTransport.Builder
java.lang.Object
io.modelcontextprotocol.client.transport.HttpClientStreamableHttpTransport.Builder
- Enclosing class:
- HttpClientStreamableHttpTransport
Builder for
HttpClientStreamableHttpTransport.-
Method Summary
Modifier and TypeMethodDescriptionasyncHttpRequestCustomizer(McpAsyncHttpClientRequestCustomizer asyncHttpRequestCustomizer) Sets the customizer forHttpRequest.Builder, to modify requests before executing them.build()Construct a fresh instance ofHttpClientStreamableHttpTransportusing the current builder configuration.clientBuilder(HttpClient.Builder clientBuilder) Sets the HTTP client builder.connectTimeout(Duration connectTimeout) Sets the connection timeout for the HTTP client.customizeClient(Consumer<HttpClient.Builder> clientCustomizer) Customizes the HTTP client builder.customizeRequest(Consumer<HttpRequest.Builder> requestCustomizer) Customizes the HTTP client builder.Configure the endpoint to make HTTP requests against.httpRequestCustomizer(McpSyncHttpClientRequestCustomizer syncHttpRequestCustomizer) Sets the customizer forHttpRequest.Builder, to modify requests before executing them.jsonMapper(McpJsonMapper jsonMapper) Configure a customMcpJsonMapperimplementation to use.openConnectionOnStartup(boolean openConnectionOnStartup) Configure whether the client should open an SSE connection upon startup.requestBuilder(HttpRequest.Builder requestBuilder) Sets the HTTP request builder.resumableStreams(boolean resumableStreams) Configure whether to use the stream resumability feature by keeping track of SSE event ids.supportedProtocolVersions(List<String> supportedProtocolVersions) Sets the list of supported protocol versions used in version negotiation.
-
Method Details
-
clientBuilder
Sets the HTTP client builder.- Parameters:
clientBuilder- the HTTP client builder- Returns:
- this builder
-
customizeClient
public HttpClientStreamableHttpTransport.Builder customizeClient(Consumer<HttpClient.Builder> clientCustomizer) Customizes the HTTP client builder.- Parameters:
clientCustomizer- the consumer to customize the HTTP client builder- Returns:
- this builder
-
requestBuilder
Sets the HTTP request builder.- Parameters:
requestBuilder- the HTTP request builder- Returns:
- this builder
-
customizeRequest
public HttpClientStreamableHttpTransport.Builder customizeRequest(Consumer<HttpRequest.Builder> requestCustomizer) Customizes the HTTP client builder.- Parameters:
requestCustomizer- the consumer to customize the HTTP request builder- Returns:
- this builder
-
jsonMapper
Configure a customMcpJsonMapperimplementation to use.- Parameters:
jsonMapper- instance to use- Returns:
- the builder instance
-
endpoint
Configure the endpoint to make HTTP requests against.- Parameters:
endpoint- endpoint to use- Returns:
- the builder instance
-
resumableStreams
Configure whether to use the stream resumability feature by keeping track of SSE event ids.- Parameters:
resumableStreams- iftrueevent ids will be tracked and upon disconnection, the last seen id will be used upon reconnection as a header to resume consuming messages.- Returns:
- the builder instance
-
openConnectionOnStartup
public HttpClientStreamableHttpTransport.Builder openConnectionOnStartup(boolean openConnectionOnStartup) Configure whether the client should open an SSE connection upon startup. Not all servers support this (although it is in theory possible with the current specification), so use with caution. By default, this value isfalse.- Parameters:
openConnectionOnStartup- iftruetheHttpClientStreamableHttpTransport.connect(Function)method call will try to open an SSE connection before sending any JSON-RPC request- Returns:
- the builder instance
-
httpRequestCustomizer
public HttpClientStreamableHttpTransport.Builder httpRequestCustomizer(McpSyncHttpClientRequestCustomizer syncHttpRequestCustomizer) Sets the customizer forHttpRequest.Builder, to modify requests before executing them.This overrides the customizer from
asyncHttpRequestCustomizer(McpAsyncHttpClientRequestCustomizer).Do NOT use a blocking
McpSyncHttpClientRequestCustomizerin a non-blocking context. UseasyncHttpRequestCustomizer(McpAsyncHttpClientRequestCustomizer)instead.- Parameters:
syncHttpRequestCustomizer- the request customizer- Returns:
- this builder
-
asyncHttpRequestCustomizer
public HttpClientStreamableHttpTransport.Builder asyncHttpRequestCustomizer(McpAsyncHttpClientRequestCustomizer asyncHttpRequestCustomizer) Sets the customizer forHttpRequest.Builder, to modify requests before executing them.This overrides the customizer from
httpRequestCustomizer(McpSyncHttpClientRequestCustomizer).Do NOT use a blocking implementation in a non-blocking context.
- Parameters:
asyncHttpRequestCustomizer- the request customizer- Returns:
- this builder
-
connectTimeout
Sets the connection timeout for the HTTP client.- Parameters:
connectTimeout- the connection timeout duration- Returns:
- this builder
-
supportedProtocolVersions
public HttpClientStreamableHttpTransport.Builder supportedProtocolVersions(List<String> supportedProtocolVersions) Sets the list of supported protocol versions used in version negotiation. By default, the client will send the latest of those versions in theMCP-Protocol-Versionheader.Setting this value only updates the values used in version negotiation, and does NOT impact the actual capabilities of the transport. It should only be used for compatibility with servers having strict requirements around the
MCP-Protocol-Versionheader.- Parameters:
supportedProtocolVersions- protocol versions supported by this transport- Returns:
- this builder
- See Also:
-
build
Construct a fresh instance ofHttpClientStreamableHttpTransportusing the current builder configuration.- Returns:
- a new instance of
HttpClientStreamableHttpTransport
-