Skip to content

fix(mcp): unwrap StdioConnectionParameters and preserve requestTimeout in initializeAsyncSession - #1982

Open
Amansingh0807 wants to merge 1 commit into
google:mainfrom
Amansingh0807:fix-mcp-async-stdio
Open

Amansingh0807 wants to merge 1 commit into
google:mainfrom
Amansingh0807:fix-mcp-async-stdio

Conversation

@Amansingh0807

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

Problem:
McpSessionManager.initializeAsyncSession(Object connectionParams, McpTransportBuilder transportBuilder) previously passed connectionParams directly to transportBuilder.build(connectionParams) before inspecting its type, and only checked SseServerParameters and StreamableHttpServerParameters afterward.

When StdioConnectionParameters was passed:

  1. DefaultMcpTransportBuilder.build(...) immediately threw:
    IllegalArgumentException: DefaultMcpTransportBuilder supports only ServerParameters, SseServerParameters, or StreamableHttpServerParameters, but got com.google.adk.tools.mcp.AutoValue_StdioConnectionParameters.
  2. Any custom timeoutDuration() configured on StdioConnectionParameters was ignored and defaulted to 5 minutes (Duration.ofMinutes(5)).
  3. createAsyncSession() also omitted this.transportBuilder, unlike createSession().

Solution:

  1. Extracted a shared resolveTransportConfig(Object connectionParams, McpTransportBuilder transportBuilder) helper (using a private TransportConfig record and DEFAULT_TIMEOUT = Duration.ofMinutes(5)) used by both initializeSession and initializeAsyncSession so parameter unwrapping and timeout extraction are handled uniformly without code duplication.
  2. Unwraps StdioConnectionParameters to stdioConnectionParameters.serverParams().toServerParameters() before calling transportBuilder.build(...) and sets requestTimeout = stdioConnectionParameters.timeoutDuration().
  3. Updated createAsyncSession() to forward this.transportBuilder to initializeAsyncSession(this.connectionParams, this.transportBuilder), matching createSession().

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Summary of Passed Java Test Results (.\mvnw.cmd test -pl core -Dtest="com.google.adk.tools.mcp.*Test" -DfailIfNoTests=false):

[INFO] +-- com.google.adk.tools.mcp.McpSessionManagerTest
[INFO] | +-- [OK] initializeAsyncSession_withStdioConnectionParameters_succeeds - 0.227 ss
[INFO] | +-- [OK] createAsyncSession_withInjectedTransportBuilder_usesCustomBuilder - 0.308 ss
[INFO] | +-- [OK] initializeAsyncSession_withStdioConnectionParameters_unwrapsServerParameters - 0.007 ss
[INFO] | +-- [OK] initializeAsyncSession_withUnsupportedParams_throwsIllegalArgumentException - 0.002 ss
...
[INFO] BUILD SUCCESS

All MCP unit tests in core (AbstractMcpToolTest, ConversionUtilsTest, DefaultMcpTransportBuilderTest, McpAsyncToolsetTest, McpSessionManagerTest, McpToolsetReservedNamesTest, McpToolsetTest, StdioServerParametersTest) passed with 0 failures and 0 errors.

Manual End-to-End (E2E) Tests:
N/A (verified via unit tests with both DefaultMcpTransportBuilder and mocked McpTransportBuilder capturing unwrapped ServerParameters).


Checklist

  • I have read the CONTRIBUTING.md document.
  • My pull request contains a single commit.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

  • Single squashed commit (3482d23e fix(mcp): unwrap StdioConnectionParameters and preserve requestTimeout in initializeAsyncSession) following Conventional Commits and Google Java Style conventions with Apache 2.0 license headers.

cc @hemasekhar-p @damianmomotgoogle @dosadczuk @MiloszSobczyk

@hemasekhar-p hemasekhar-p self-assigned this Dec 2, 2026
@hemasekhar-p

Copy link
Copy Markdown
Contributor

Hi @Amansingh0807, Thank you for your contribution and for taking the time to submit this pull request. Our team is currently reviewing your changes, and we will reach out if we need any further information.

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.

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

2 participants