Skip to content

Why do we need broadcast messages to clients? #9

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
JadenHuang2023 opened this issue Feb 15, 2025 · 7 comments
Closed

Why do we need broadcast messages to clients? #9

JadenHuang2023 opened this issue Feb 15, 2025 · 7 comments
Labels
bug Something isn't working lifecycle server
Milestone

Comments

@JadenHuang2023
Copy link

logger.debug("Attempting to broadcast message to {} active sessions", sessions.size());

Why do we broadcast responses to all clients instead of just sending them to the current requesting client?

@tzolov
Copy link
Contributor

tzolov commented Feb 18, 2025

@JadenHuang2023, Thanks for the relevant question.
Some server notifications (tools/resource/prompt list changes) should be broadcast to all clients, while server requests related to Roots and Sampling should only go to the initiating client's session. Later is not implemented correctly at the moment. We'll fix this behavior soon.

@JadenHuang2023
Copy link
Author

@tzolov Thanks for your response.
The result of the tool call/tool list, etc should also only be sent to the current requesting client.

@taobaorun
Copy link

https://stackoverflow.com/questions/79456135/java-mcp-sdk-webflux-server-transport-sendmessage-is-broadcasts

The current version of the tool call is also broadcast to all clients。

@marianogonzalez
Copy link
Contributor

marianogonzalez commented Feb 25, 2025

@tzolov will the behavior fix you're describing include avoiding broadcast for tool/call or resource/read responses? Do you happen to have an ETA on that fix? Thanks!

@tzolov
Copy link
Contributor

tzolov commented Feb 26, 2025

@taobaorun, @marianogonzalez we're developing a proper client session management solution that will address all issues mentioned above, including handling for listRoots and createMessage (sampling).

Some early experiments are available at https://github.com/modelcontextprotocol/java-sdk/tree/server-session-support2, and we expect to finalize the solution soon.

@tzolov tzolov added bug Something isn't working server labels Feb 26, 2025
@tzolov tzolov added this to the 0.8.0 milestone Feb 26, 2025
@chemicL chemicL marked this as a duplicate of #29 Mar 4, 2025
@chemicL chemicL marked this as not a duplicate of #29 Mar 4, 2025
@He-Pin
Copy link
Contributor

He-Pin commented Mar 17, 2025

We need some session management too, which can only send to a dedicated sink.

@chemicL
Copy link
Member

chemicL commented Mar 17, 2025

@He-Pin the implementation is happening in #31

@tzolov tzolov closed this as completed in f50f88c Mar 20, 2025
tzolov added a commit that referenced this issue Mar 20, 2025
tzolov added a commit that referenced this issue Mar 20, 2025
This commit introduces a major refactoring of the MCP Java SDK to implement a session-based architecture
for server-side implementations. The changes improve the SDK's ability to handle multiple concurrent
client connections and provide an API better aligned with the MCP specification.

Key changes:

- Introduce McpServerTransportProvider interface to manage client connections
- Rename ClientMcpTransport to McpClientTransport and ServerMcpTransport to McpServerTransport
- Add exchange objects (McpAsyncServerExchange, McpSyncServerExchange) for client interaction
- Update handler signatures to include exchange parameter: (args) -> result to (exchange, args) -> result
- Rename Registration classes to Specification classes
- Update method names (e.g., rootsChangeConsumers to rootsChangeHandlers)
- Deprecate old interfaces and classes for removal in 0.9.0
- Add migration guide (migration-0.8.0.md)

Resolves #9, #15

Co-authored-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
tzolov added a commit that referenced this issue Mar 20, 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 lifecycle server
Projects
None yet
Development

No branches or pull requests

6 participants