Skip to content

Support server to client notifications from the stateless transport #472

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Randgalt
Copy link
Contributor

@Randgalt Randgalt commented Aug 8, 2025

The MCP spec allows stateless servers to send notifications to the client during a request. The response needs to be upgraded to SSE and the notifications are send in a stream until the final result is sent.

This commit adds a sendNotification method to the transport context allowing each transport implementation to implement it or not. In this commit, HttpServletStatelessServerTransport implements the method and when the caller first sends a notification, the response is changed to TEXT_EVENT_STREAM and events are then streamed until the final result.

This change will allow future features such as logging, list changes, etc. should we ever decide to support sessions in some manner. Even if we don't support sessions, sending progress notifications is a useful feature by itself.

Motivation and Context

We would like to have support for progress notifications in the stateless implementation.

How Has This Been Tested?

  • testNotifications() added to HttpServletStatelessIntegrationTests
  • manual testing with the MCP inspector

Breaking Changes

none

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

@Randgalt Randgalt force-pushed the joranz/support-stateless-notifications branch 2 times, most recently from efd322f to fdb7799 Compare August 8, 2025 08:02
* @param method notification method name
* @param params any parameters or {@code null}
*/
default void sendNotification(String method, Object params) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to this might be a separate McpNotifier instance that would be accessed by calling McpTransportContext.get() with a lib-defined key. wdyt?

@Randgalt Randgalt force-pushed the joranz/support-stateless-notifications branch from fdb7799 to 27ef5a6 Compare August 8, 2025 08:31
The MCP spec allows stateless servers to send notifications to the
client during a request. The response needs to be upgraded to SSE
and the notifications are send in a stream until the final result
is sent.

This commit adds a `sendNotification` method to the transport
context allowing each transport implementation to implement it
or not. In this commit, HttpServletStatelessServerTransport
implements the method and when the caller first sends a
notification, the response is changed to `TEXT_EVENT_STREAM`
and events are then streamed until the final result.

This change will allow future features such as logging, list
changes, etc. should we ever decide to support sessions in
some manner. Even if we don't support sessions, sending progress
notifications is a useful feature by itself.
@Randgalt Randgalt force-pushed the joranz/support-stateless-notifications branch from 27ef5a6 to 3f83ef2 Compare August 8, 2025 08:56
@Randgalt
Copy link
Contributor Author

Randgalt commented Aug 8, 2025

@tzolov do you have plans to support sessions for the stateless transport/server? We have some ideas that we will likely implement in our own code but could contribute here if there's interest.

@Randgalt
Copy link
Contributor Author

Randgalt commented Aug 9, 2025

Noe: I've only done HttpServletStatelessServerTransport. I'm changing this to Draft so that I can get feedback. Is this PR worth pursuing for the other transports?

@Randgalt Randgalt marked this pull request as draft August 9, 2025 14:37
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.

1 participant