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.objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Configure theObjectMapperto 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.
-
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
-
objectMapper
public HttpClientStreamableHttpTransport.Builder objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Configure theObjectMapperto use.- Parameters:
objectMapper- 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
-
build
Construct a fresh instance ofHttpClientStreamableHttpTransportusing the current builder configuration.- Returns:
- a new instance of
HttpClientStreamableHttpTransport
-