Skip to content

Conversation

@wenhaozhao
Copy link

allow to pass timout config while create mcp-client

@vorburger
Copy link
Member

allow to pass timout config while create mcp-client

@wenhaozhao can you elaborate on how this would be used?

if (connectionParams instanceof SseServerParameters sseServerParams)

How would one configure this? It might be useful to document this.

PS: Looks like this could be a solution for #285 from @rsaulo.

@wenhaozhao
Copy link
Author

allow to pass timout config while create mcp-client

@wenhaozhao can you elaborate on how this would be used?

if (connectionParams instanceof SseServerParameters sseServerParams)

How would one configure this? It might be useful to document this.

PS: Looks like this could be a solution for #285 from @rsaulo.

McpSyncClient is a wrapper around McpAsyncClient that provides a blocking API via block(). When sending requests, the timeout parameter becomes effective within the reactor-chain.

image

so, you can config timeout like this:

    McpSessionManager mcpManager = new McpSessionManager(SseServerParameters.builder()
            .url("http://127.0.0.1:28080/sse")
            .timeout(Duration.ofSeconds(120L)) //set init timeout
            .sseReadTimeout(Duration.ofSeconds(600L)) // set read timout
            .build());
    var mcpClient = mcpManager.createSession();
    var mcpTools = mcpClient.client().listTools().tools().stream()
            .map(tool -> new McpTool(tool, mcpClient, mcpManager))
            .toList();

@wenhaozhao
Copy link
Author

allow to pass timout config while create mcp-client

@wenhaozhao can you elaborate on how this would be used?

if (connectionParams instanceof SseServerParameters sseServerParams)

How would one configure this? It might be useful to document this.

PS: Looks like this could be a solution for #285 from @rsaulo.

and there a another pr #273, also include timeout config

@vorburger vorburger requested review from Copilot and vorburger July 22, 2025 09:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for passing timeout configuration when initializing an MCP client. The changes allow customizable initialization and request timeouts to be extracted from connection parameters instead of using hardcoded values.

  • Extracts timeout values from SseServerParameters when available
  • Replaces hardcoded 10-second timeout with configurable timeouts
  • Falls back to default 10-second timeouts when no custom values are provided

Comment on lines 63 to 72
.initializationTimeout(initializationTimeout == null ? Duration.ofSeconds(10) : initializationTimeout)
.requestTimeout(requestTimeout == null ? Duration.ofSeconds(10) : requestTimeout)
.capabilities(ClientCapabilities.builder().build())
.build();
InitializeResult initResult = client.initialize();
logger.debug("Initialize Client Result: {}", initResult);

return client;
}
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

[nitpick] The ternary operator with null checks makes the code less readable. Consider extracting the default timeout logic into a helper method or using Optional.ofNullable().orElse() for cleaner null handling.

Copilot uses AI. Check for mistakes.
Comment on lines 63 to 64
.initializationTimeout(initializationTimeout == null ? Duration.ofSeconds(10) : initializationTimeout)
.requestTimeout(requestTimeout == null ? Duration.ofSeconds(10) : requestTimeout)
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

The default timeout value Duration.ofSeconds(10) is duplicated. Consider extracting this magic number into a named constant to improve maintainability and ensure consistency.

Suggested change
.initializationTimeout(initializationTimeout == null ? Duration.ofSeconds(10) : initializationTimeout)
.requestTimeout(requestTimeout == null ? Duration.ofSeconds(10) : requestTimeout)
.initializationTimeout(initializationTimeout == null ? DEFAULT_TIMEOUT : initializationTimeout)
.requestTimeout(requestTimeout == null ? DEFAULT_TIMEOUT : requestTimeout)

Copilot uses AI. Check for mistakes.
@vorburger
Copy link
Member

so, you can config timeout like this:

Awesome! We should probably document this, somehow somewhere? Would you be willing to raise a PR to add a short section e.g. on https://github.com/google/adk-docs/blob/main/docs/get-started/streaming/quickstart-streaming-java.md for https://google.github.io/adk-docs/get-started/streaming/quickstart-streaming-java/ about this?

@vorburger
Copy link
Member

so, you can config timeout like this:

Awesome! We should probably document this (...) https://google.github.io/adk-docs/get-started/streaming/quickstart-streaming-java/ about this?

Probably better on https://google.github.io/adk-docs/tools/mcp-tools, actually?

@wenhaozhao wenhaozhao force-pushed the feat-mcp_client_timeout branch from 9f6f419 to a4a625a Compare July 23, 2025 01:43
@wenhaozhao
Copy link
Author

so, you can config timeout like this:

Awesome! We should probably document this (...) https://google.github.io/adk-docs/get-started/streaming/quickstart-streaming-java/ about this?

Probably better on https://google.github.io/adk-docs/tools/mcp-tools, actually?

https://google.github.io/adk-docs/tools/mcp-tools maybe better, but it's written in python.
Can you add java sections for me?

@vorburger vorburger self-assigned this Jul 23, 2025
Copy link
Member

@vorburger vorburger left a comment

Choose a reason for hiding this comment

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

Could you address the build failure due to the code format? (It's something we just added.)

@wenhaozhao
Copy link
Author

Could you address the build failure due to the code format? (It's something we just added.)

fine, i've resloved

@wenhaozhao wenhaozhao force-pushed the feat-mcp_client_timeout branch from 99984af to d255167 Compare July 24, 2025 02:05
@copybara-service copybara-service bot merged commit be252c5 into google:main Jul 24, 2025
7 checks passed
@vorburger
Copy link
Member

https://google.github.io/adk-docs/tools/mcp-tools maybe better, but it's written in python. Can you add java sections for me?

Watch new issue #297 re. the missing doc (in general about MCP, not about this timeout); maybe once that's resolved, you could add this.

@rsaulo
Copy link

rsaulo commented Jul 27, 2025

Just tested with main branch and it is working.

For me is working and it is OK.

Just a comment, now I see that in McpSessionManager, the class uses the sseReadTimeout parameter from SseServerParameters to set the requestTimeout, BUT, this parameter has a default of 5 MINUTES on the SseServerParameters builder, what is turning this parameter as 5 minutes forever. I understand that we need a specific parameter on SseServerParameters like "mcpClientRequestTimeout" to use here as sseReadTimeout is not the same as requestTimeout. But for my use case it is working!! Thanks.

@vorburger , thanks for the quick attention on this matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants