Skip to content

Sends a heartbeat (ping) to all connected clients to keep connection… #353

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

FrolikovEA
Copy link

@FrolikovEA FrolikovEA commented Jun 29, 2025

…s alive. This method sends ping notifications to all active sessions without expecting a response, which helps prevent connection timeouts.

@return A Mono that completes when heartbeat has been sent to all sessions

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

…s alive. This method sends ping notifications to all active sessions without expecting a response, which helps prevent connection timeouts.

 @return A Mono that completes when heartbeat has been sent to all sessions
@FrolikovEA
Copy link
Author

Sends a heartbeat (ping) to all connected clients to keep connections alive. This method sends ping notifications to all active sessions without expecting a response, which helps prevent connection timeouts.
@return A Mono that completes when heartbeat has been sent to all sessions

@tzolov
Copy link
Contributor

tzolov commented Jul 1, 2025

@FrolikovEA can you elaborate on this? What connection timeouts do you see.
Also we just added the server ping() support, e.g. you can send pings but only from within the context of a running server operation (e.g. tool call, resource read, ....): #347

@FrolikovEA
Copy link
Author

Good afternoon
this is a standard problem when using nargs in cursor
this method will help to periodically ping all sessions so that the connection does not drop.
for example, this is how I call it in Spring

@Bean
public Disposable heartbeatLoop(WebFluxSseServerTransportProvider provider) {
    return Flux.interval(Duration.ofSeconds(40))
            .flatMap(t -> provider.sendHeartbeat())
            .subscribe();
}

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.

3 participants