Skip to content

fix(mcp): McpSessionManager.initializeAsyncSession throws IllegalArgumentException on StdioConnectionParameters and ignores requestTimeout #1981

In review

Description

@Amansingh0807

Please make sure you read the contribution guide and file the issues in the right place.
Contribution guide.

🔴 Required Information

Describe the Bug:
McpSessionManager.initializeAsyncSession(Object connectionParams, McpTransportBuilder transportBuilder) throws an IllegalArgumentException whenever StdioConnectionParameters is passed, and also ignores any custom timeoutDuration() configured on StdioConnectionParameters.

In synchronous McpSessionManager.initializeSession(...) (core/src/main/java/com/google/adk/tools/mcp/McpSessionManager.java, lines 62–77), connectionParams is inspected before calling transportBuilder.build(...):

  • If connectionParams instanceof StdioConnectionParameters stdioConnectionParameters, it unwraps stdioConnectionParameters.serverParams().toServerParameters() into transportBuilderParams and extracts requestTimeout = stdioConnectionParameters.timeoutDuration().
  • It then passes transportBuilderParams to transportBuilder.build(transportBuilderParams).

However, in McpSessionManager.initializeAsyncSession(...) (core/src/main/java/com/google/adk/tools/mcp/McpSessionManager.java, lines 101–120):

  1. transportBuilder.build(connectionParams) is called immediately on line 105 with the raw connectionParams object.
  2. There is no instanceof StdioConnectionParameters branch at all (lines 106–112 only handle SseServerParameters and StreamableHttpServerParameters).
  3. DefaultMcpTransportBuilder.build(Object connectionParams) (DefaultMcpTransportBuilder.java, lines 45–89) only accepts ServerParameters, SseServerParameters, or StreamableHttpServerParameters, so passing StdioConnectionParameters throws IllegalArgumentException immediately.
  4. Even if a custom McpTransportBuilder accepted StdioConnectionParameters, requestTimeout remains null and silently falls back to the 5-minute default (Duration.ofMinutes(5)), ignoring stdioConnectionParameters.timeoutDuration().

Steps to Reproduce:

  1. Construct a StdioServerParameters instance (e.g., StdioServerParameters.builder().command("echo").build()).
  2. Wrap it in StdioConnectionParameters with a custom timeout (e.g., StdioConnectionParameters.builder().serverParams(serverParams).timeout(10.0f).build()).
  3. Call McpSessionManager.initializeAsyncSession(connectionParams) (or new McpSessionManager(connectionParams).createAsyncSession()).
  4. Observe IllegalArgumentException thrown by DefaultMcpTransportBuilder.build.

Expected Behavior:
McpSessionManager.initializeAsyncSession should unwrap StdioConnectionParameters to stdioConnectionParameters.serverParams().toServerParameters() before calling transportBuilder.build(...), and set requestTimeout = stdioConnectionParameters.timeoutDuration() — matching the behavior of synchronous McpSessionManager.initializeSession.

Observed Behavior:
McpSessionManager.initializeAsyncSession immediately crashes with:

java.lang.IllegalArgumentException: DefaultMcpTransportBuilder supports only ServerParameters, SseServerParameters, or StreamableHttpServerParameters, but got com.google.adk.tools.mcp.AutoValue_StdioConnectionParameters

Environment Details:

  • ADK Library Version (see maven dependency): 1.16.1-SNAPSHOT (latest main)
  • OS: Windows
  • Java Version (java -version): Java 25 (compiled with release 17)

Model Information:

  • Which model is being used: N/A (MCP Toolset / McpSessionManager)

🟡 Optional Information

Regression:
No (present since async session initialization was introduced).

Logs:
Local reproduction test output (.\mvnw.cmd test -pl core -Dtest=McpSessionManagerReproTest):

REPRODUCED EXCEPTION: DefaultMcpTransportBuilder supports only ServerParameters, SseServerParameters, or StreamableHttpServerParameters, but got com.google.adk.tools.mcp.AutoValue_StdioConnectionParameters

Additional Context:
McpSessionManager.initializeSession (lines 66–77) already implements the correct unwrapping and timeout extraction logic:

Object transportBuilderParams = connectionParams;
if (connectionParams instanceof StdioConnectionParameters stdioConnectionParameters) {
  transportBuilderParams = stdioConnectionParameters.serverParams().toServerParameters();
  requestTimeout = stdioConnectionParameters.timeoutDuration();
} else if (connectionParams instanceof SseServerParameters sseServerParams) {
  initializationTimeout = sseServerParams.timeout();
  requestTimeout = sseServerParams.sseReadTimeout();
} else if (connectionParams instanceof StreamableHttpServerParameters streamableParams) {
  initializationTimeout = streamableParams.timeout();
  requestTimeout = streamableParams.readTimeout();
}
McpClientTransport transport = transportBuilder.build(transportBuilderParams);

Applying the same pattern in initializeAsyncSession resolves both the IllegalArgumentException and the ignored requestTimeout.

Minimal Reproduction Code:

@Test
public void initializeAsyncSession_withStdioConnectionParameters_throwsIllegalArgumentException() {
  StdioServerParameters serverParams = StdioServerParameters.builder().command("echo").build();
  StdioConnectionParameters connectionParams =
      StdioConnectionParameters.builder().serverParams(serverParams).timeout(10.0f).build();

  IllegalArgumentException thrown =
      assertThrows(
          IllegalArgumentException.class,
          () -> McpSessionManager.initializeAsyncSession(connectionParams));

  assertThat(thrown)
      .hasMessageThat()
      .contains(
          "DefaultMcpTransportBuilder supports only ServerParameters, SseServerParameters, or"
              + " StreamableHttpServerParameters");
}

How often has this issue occurred?:

  • Always (100%)

cc @hemasekhar-p @damianmomotgoogle @dosadczuk @MiloszSobczyk

Activity

  1. Amansingh0807 commented on Dec 1, 2026

    @Amansingh0807
    ContributorAuthor

    Hi @hemasekhar-p, I have opened up a PR for this issue.
    PTAL whenever you have a moment.
    Thank you.

  2. self-assigned this
    on Dec 2, 2026
  3. added theissue type on Dec 2, 2026
  4. hemasekhar-p commented on Dec 2, 2026

    @hemasekhar-p
    Contributor

    Hi @Amansingh0807, thank you for reporting this issue and for your contribution. I have successfully reproduced the bug using your inputs. The issue and your corresponding pull request are currently under review by our team. We will reach out if we require any additional information.

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

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions