@@ -588,9 +588,7 @@ public static class Builder {
588588
589589 private ObjectMapper objectMapper ;
590590
591- private HttpClient .Builder clientBuilder = HttpClient .newBuilder ()
592- .version (HttpClient .Version .HTTP_1_1 )
593- .connectTimeout (Duration .ofSeconds (10 ));
591+ private HttpClient .Builder clientBuilder = HttpClient .newBuilder ().version (HttpClient .Version .HTTP_1_1 );
594592
595593 private String endpoint = DEFAULT_ENDPOINT ;
596594
@@ -602,6 +600,8 @@ public static class Builder {
602600
603601 private AsyncHttpRequestCustomizer httpRequestCustomizer = AsyncHttpRequestCustomizer .NOOP ;
604602
603+ private Duration connectTimeout = Duration .ofSeconds (10 );
604+
605605 /**
606606 * Creates a new builder with the specified base URI.
607607 * @param baseUri the base URI of the MCP server
@@ -738,6 +738,17 @@ public Builder asyncHttpRequestCustomizer(AsyncHttpRequestCustomizer asyncHttpRe
738738 return this ;
739739 }
740740
741+ /**
742+ * Sets the connection timeout for the HTTP client.
743+ * @param connectTimeout the connection timeout duration
744+ * @return this builder
745+ */
746+ public Builder connectTimeout (Duration connectTimeout ) {
747+ Assert .notNull (connectTimeout , "connectTimeout must not be null" );
748+ this .connectTimeout = connectTimeout ;
749+ return this ;
750+ }
751+
741752 /**
742753 * Construct a fresh instance of {@link HttpClientStreamableHttpTransport} using
743754 * the current builder configuration.
@@ -746,8 +757,10 @@ public Builder asyncHttpRequestCustomizer(AsyncHttpRequestCustomizer asyncHttpRe
746757 public HttpClientStreamableHttpTransport build () {
747758 ObjectMapper objectMapper = this .objectMapper != null ? this .objectMapper : new ObjectMapper ();
748759
749- return new HttpClientStreamableHttpTransport (objectMapper , clientBuilder .build (), requestBuilder , baseUri ,
750- endpoint , resumableStreams , openConnectionOnStartup , httpRequestCustomizer );
760+ HttpClient httpClient = this .clientBuilder .connectTimeout (this .connectTimeout ).build ();
761+
762+ return new HttpClientStreamableHttpTransport (objectMapper , httpClient , requestBuilder , baseUri , endpoint ,
763+ resumableStreams , openConnectionOnStartup , httpRequestCustomizer );
751764 }
752765
753766 }
0 commit comments