Skip to content

"Client failed to initialize by explicit API call" bugfix #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

codezkk
Copy link
Contributor

@codezkk codezkk commented Aug 1, 2025

sink.next() must be executed, otherwise in the case of empty return (such as notify), the deliveredSink of sendMessage will not be able to process the stream correctly, resulting in Client failed to initialize by explicit API call

Motivation and Context

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

sink.must() must be executed, otherwise in the case of empty return (such as notify), the deliveredSink of sendMessage will not be able to process the stream correctly, resulting in Client failed to initialize by explicit API call
@codezkk codezkk changed the title Update ResponseSubscribers.java "Client failed to initialize by explicit API call" bugfix Aug 1, 2025
@codezkk
Copy link
Contributor Author

codezkk commented Aug 1, 2025

a blocking issue that I hope to resolve soon

@xyjspace
Copy link

xyjspace commented Aug 1, 2025

great

@tzolov
Copy link
Contributor

tzolov commented Aug 1, 2025

@codezkk thanks you for reveling this issue.
Any suggestions to reproduce and add test for it?

@tzolov tzolov requested review from chemicL and tzolov August 1, 2025 09:40
@codezkk
Copy link
Contributor Author

codezkk commented Aug 1, 2025

@codezkk thanks you for reveling this issue. Any suggestions to reproduce and add test for it?

When building HttpClientStreamableHttpTransport, initailize will call notify, which will be triggered when processing the notify response. I think the main problem is that the responseEventSink of HttpClientStreamableHttpTransport#sendMessage does not correctly handle sink.next().
It is very easy to reproduce this problem, for example:

HttpClientStreamableHttpTransport build = HttpClientStreamableHttpTransport
.builder("http://xxx/mcp")
.build();

var client = McpClient.async(build)
.initializationTimeout(Duration.ofSeconds(3))
.build();
client.initialize().block();

@tzolov
Copy link
Contributor

tzolov commented Aug 1, 2025

@codezkk thanks for the replay.
We have an streamable integration tests. The simple test is doing what you are explaining without showing an issues.

I would appreciate if the PRs like this are accompanied with proper tests.

tzolov added a commit to tzolov/mcp-java-sdk that referenced this pull request Aug 4, 2025
…col versions

- Add ProtocolVersions interface with version constants
- Change protocolVersion() to protocolVersions() returning List<String>
- Streamable HTTP clients now support both 2024-11-05 and 2025-03-26
- Fixes compatibility with MCP servers that return 2024-11-05 instead of 2025-03-26

Resolves modelcontextprotocol#436
Related to modelcontextprotocol#438

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
tzolov added a commit that referenced this pull request Aug 4, 2025
…col versions

- Add ProtocolVersions interface with version constants
- Change protocolVersion() to protocolVersions() returning List<String>
- Streamable HTTP clients now support both 2024-11-05 and 2025-03-26
- Fixes compatibility with MCP servers that return 2024-11-05 instead of 2025-03-26

Resolves #436
Related to #438

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
tzolov added a commit that referenced this pull request Aug 4, 2025
…col versions

- Add ProtocolVersions interface with version constants
- Change protocolVersion() to protocolVersions() returning List<String>
- Streamable HTTP clients now support both 2024-11-05 and 2025-03-26
- Fixes compatibility with MCP servers that return 2024-11-05 instead of 2025-03-26

Resolves #436
Related to #438

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
@tzolov
Copy link
Contributor

tzolov commented Aug 4, 2025

Hi @codezkk, have you managed to reproduce the issue with a test? If not should i close this PR?

@tzolov tzolov added the waiting for user Waiting for user feedback or more details label Aug 4, 2025
@skuznyuk
Copy link

skuznyuk commented Aug 4, 2025

Also seeing this issue, this PR fixed the error I was seeing (dropping the connection on initialize because its blocking on the initialized notification call).

@072ashin
Copy link

072ashin commented Aug 4, 2025

is there a plan to release this patch as 0.11.1?

@codezkk
Copy link
Contributor Author

codezkk commented Aug 4, 2025

Hi @codezkk, have you managed to reproduce the issue with a test? If not should i close this PR?

Sorry for being delayed by other things, I will deal with it today

Tests for the "Client failed to initialize by explicit API call" problem.
@codezkk
Copy link
Contributor Author

codezkk commented Aug 5, 2025

Hi @codezkk, have you managed to reproduce the issue with a test? If not should i close this PR?

test has been added @tzolov I am building an MCP gateway to connect to different clients and servers. This problem is exactly the compatibility issue in this scenario.

@tzolov tzolov removed the waiting for user Waiting for user feedback or more details label Aug 5, 2025
@tzolov
Copy link
Contributor

tzolov commented Aug 5, 2025

Thanks for adding a tests @codezkk I will have a look later today

@tzolov
Copy link
Contributor

tzolov commented Aug 5, 2025

is there a plan to release this patch as 0.11.1?
We plan a bug fix 0.11.1 release soon (next few days). If this turn to be a real issue (as it seems to) it will be part for 0.11.1 too

@tzolov tzolov added this to the 0.12.0 milestone Aug 6, 2025
@tzolov tzolov added the bug Something isn't working label Aug 6, 2025
@tzolov tzolov self-assigned this Aug 6, 2025
@tzolov
Copy link
Contributor

tzolov commented Aug 6, 2025

thank you @codezkk
Rebased, cleaned, squashed and merged at 5aba8a0
back-ported to 0.11.x

@tzolov tzolov closed this Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants