Skip to content
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

Refactor server side to handle multiple clients #31

Closed
wants to merge 21 commits into from

Conversation

chemicL
Copy link
Member

@chemicL chemicL commented Mar 5, 2025

This PR introduces an internal concept of a server session maintained with a particular client alongside with a user-facing concept of an exchange, which provides means to communicate with the client as part of a server handler.

We are trying to avoid breaking changes by introducing deprecations with occasional breakages for those enhancing the core SDK. These are listed in the migration document.

chemicL and others added 16 commits March 19, 2025 18:42
WARN: This is still work in progress and does not compile.

Breaking changes:

* McpAsyncServer
  * getClientCapabilities deprecated + throws
  * getClientInfo deprecated + throws
  * listRoots deprecated + throws
  * createMessage deprecated + throws
* McpTransport
  * connect deprecated - should only belong to McpClientTransport
* ServerMcpTransport
  * connect default implementation that throws

The major change is the introduction of ServerMcpSession for per-client
communication. The user should be exposed to a limited abstraction that
hides the session called ServerMcpExchange which currently exposes
sampling and roots.

Signed-off-by: Dariusz Jędrzejczyk <[email protected]>
Signed-off-by: Dariusz Jędrzejczyk <[email protected]>
…change

This commit changes the parameter type in sync handler interfaces from McpAsyncServerExchange to McpSyncServerExchange
for better API consistency. It also adds proper wrapping of async exchanges in sync exchanges when bridging between
async and sync contexts in the adapter methods.

Signed-off-by: Christian Tzolov <[email protected]>
Add StdioServerTransportProvider implementation that uses reactive streams for
both inbound and outbound message processing.

- Using Flux for asynchronous message handling
- Implementing separate inbound and outbound processing pipelines
- Improving error handling with proper propagation

Signed-off-by: Christian Tzolov <[email protected]>
This commit introduces WebMvcSseServerTransportProvider as a replacement for the now-deprecated WebMvcSseServerTransport.
The new provider-based implementation offers improved session management and better alignment with the MCP specification.

Additional changes:

- Deprecate WebMvcSseServerTransport and StdioServerTransport
- Add corresponding deprecated test classes to maintain backward compatibility
- Increase test timeouts from 300ms to 1000ms/2000ms for more reliable testing
- Minor rename of ClientMcpTransport to McpClientTransport for naming consistency

Signed-off-by: Christian Tzolov <[email protected]>
…sed implementation

Introduces HttpServletSseServerTransportProvider as a replacement for HttpServletSseServerTransport,
following the provider pattern used by other transport implementations. The new implementation offers
the same functionality but with a more consistent API aligned with the McpServerTransportProvider interface.

- Mark HttpServletSseServerTransport as @deprecated (to be removed in 0.9.0)
- Add new HttpServletSseServerTransportProvider implementation
- Update test classes to use the new provider-based implementation
- Add separate test classes for deprecated implementation

Signed-off-by: Christian Tzolov <[email protected]>
Changed visibility of toSpecification() methods from package-private to public in all registration classes:

- AsyncToolRegistration
- AsyncResourceRegistration
- AsyncPromptRegistration
- SyncToolRegistration
- SyncResourceRegistration
- SyncPromptRegistration

Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
@tzolov tzolov force-pushed the refactor-server-session branch from f5fed84 to 6da69b4 Compare March 19, 2025 17:52
chemicL and others added 5 commits March 20, 2025 08:39
…tMcpSession to McpClientSession

- Replace the ClientMcpTransport interface with McpClientTransport and deprecate former
- Replace the DefaultMcpSession with McpClientSession and deprecate DefaultMcpSession
- Change all client transport implementation to implement the McpClientTransport instead of ClientMcpTransport
- The McpMockTransport implements McpClientTransport instead of ClientMcpTransport

Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
tzolov added a commit that referenced this pull request 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: Dariusz Jędrzejczyk <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
@tzolov tzolov added this to the 0.8.0 milestone Mar 20, 2025
@tzolov
Copy link
Contributor

tzolov commented Mar 20, 2025

squashed and merged at f50f88c

@tzolov tzolov closed this Mar 20, 2025
tzolov added a commit that referenced this pull request 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]>
@chemicL chemicL deleted the refactor-server-session branch March 21, 2025 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants