Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public McpClientTransport build(Object connectionParams) {
} else if (connectionParams instanceof StreamableHttpServerParameters streamableParams) {
return HttpClientStreamableHttpTransport.builder(streamableParams.url())
.connectTimeout(streamableParams.timeout())
// HttpClientStreamableHttpTransport uses connectTimeout for general HTTP ops
// and sseReadTimeout for the SSE stream part.
.asyncHttpRequestCustomizer(
(builder, method, uri, body) -> {
streamableParams.headers().forEach((key, value) -> builder.header(key, value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static McpSyncClient initializeSession(
requestTimeout = sseServerParams.sseReadTimeout();
} else if (connectionParams instanceof StreamableHttpServerParameters streamableParams) {
initializationTimeout = streamableParams.timeout();
requestTimeout = streamableParams.sseReadTimeout();
requestTimeout = streamableParams.readTimeout();
}
McpSyncClient client =
McpClient.sync(transport)
Expand Down Expand Up @@ -100,7 +100,7 @@ public static McpAsyncClient initializeAsyncSession(
requestTimeout = sseServerParams.sseReadTimeout();
} else if (connectionParams instanceof StreamableHttpServerParameters streamableParams) {
initializationTimeout = streamableParams.timeout();
requestTimeout = streamableParams.sseReadTimeout();
requestTimeout = streamableParams.readTimeout();
}
return McpClient.async(transport)
.initializationTimeout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class StreamableHttpServerParameters {
private final String url;
private final Map<String, String> headers;
private final Duration timeout;
private final Duration sseReadTimeout;
private final Duration readTimeout;
private final boolean terminateOnClose;

/**
Expand All @@ -37,20 +37,20 @@ public class StreamableHttpServerParameters {
* @param url The base URL for the MCP Streamable HTTP server.
* @param headers Optional headers to include in requests.
* @param timeout Timeout for HTTP operations (default: 30 seconds).
* @param sseReadTimeout Timeout for reading data from the SSE stream (default: 5 minutes).
* @param readTimeout Timeout for reading data from the streamed http events(default: 5 minutes).
* @param terminateOnClose Whether to terminate the session on close (default: true).
*/
public StreamableHttpServerParameters(
String url,
Map<String, String> headers,
@Nullable Duration timeout,
@Nullable Duration sseReadTimeout,
@Nullable Duration readTimeout,
@Nullable Boolean terminateOnClose) {
Assert.hasText(url, "url must not be empty");
this.url = url;
this.headers = headers == null ? Collections.emptyMap() : headers;
this.timeout = timeout == null ? Duration.ofSeconds(30) : timeout;
this.sseReadTimeout = sseReadTimeout == null ? Duration.ofMinutes(5) : sseReadTimeout;
this.readTimeout = readTimeout == null ? Duration.ofMinutes(5) : readTimeout;
this.terminateOnClose = terminateOnClose == null || terminateOnClose;
}

Expand All @@ -66,29 +66,33 @@ public Duration timeout() {
return timeout;
}

public Duration sseReadTimeout() {
return sseReadTimeout;
public Duration readTimeout() {
return readTimeout;
}

public boolean terminateOnClose() {
return terminateOnClose;
}

public static Builder builder(String url) {
return new Builder(url);
public static Builder builder() {
return new Builder();
}

/** Builder for {@link StreamableHttpServerParameters}. */
public static class Builder {
private final String url;
private String url;
private Map<String, String> headers = Collections.emptyMap();
private Duration timeout = Duration.ofSeconds(30);
private Duration sseReadTimeout = Duration.ofMinutes(5);
private Duration readTimeout = Duration.ofMinutes(5);
private boolean terminateOnClose = true;

private Builder(String url) {
protected Builder() {}

@CanIgnoreReturnValue
public Builder url(String url) {
Assert.hasText(url, "url must not be empty");
this.url = url;
return this;
}

@CanIgnoreReturnValue
Expand All @@ -104,8 +108,8 @@ public Builder timeout(Duration timeout) {
}

@CanIgnoreReturnValue
public Builder sseReadTimeout(Duration sseReadTimeout) {
this.sseReadTimeout = sseReadTimeout;
public Builder readTimeout(Duration readTimeout) {
this.readTimeout = readTimeout;
return this;
}

Expand All @@ -117,7 +121,7 @@ public Builder terminateOnClose(boolean terminateOnClose) {

public StreamableHttpServerParameters build() {
return new StreamableHttpServerParameters(
url, headers, timeout, sseReadTimeout, terminateOnClose);
url, headers, timeout, readTimeout, terminateOnClose);
}
}
}