feat(client): add periodic ping support for connection health monitoring#1645
Open
Br1an67 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Open
feat(client): add periodic ping support for connection health monitoring#1645Br1an67 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Br1an67 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
Add configurable periodic ping functionality to the Client class as specified in the MCP protocol. This allows automatic connection health monitoring by sending ping requests at a configurable interval. Changes: - Add PingConfig interface with enabled and intervalMs options - Add ping configuration option to ClientOptions - Start periodic ping after successful connection initialization - Stop periodic ping on client close - Emit errors via onerror callback when ping fails - Default to disabled (opt-in feature) - Default interval of 30 seconds when enabled The implementation follows the MCP specification recommendation that implementations SHOULD periodically issue pings to detect connection health.
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
…nding The MockTransport class in ping.test.ts was not responding to initialize and ping requests, causing client.connect() to hang indefinitely and tests to timeout. Updated MockTransport.send() to properly respond to these requests with appropriate JSON-RPC responses.
…fault Add underscore separator to 30000 -> 30_000 for better readability and to satisfy unicorn/numeric-separators-style lint rule. Also apply prettier formatting to ping.test.ts. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1000
Summary
This PR implements the missing periodic ping functionality for the MCP TypeScript SDK Client, as specified in the MCP protocol. The implementation allows automatic connection health monitoring by sending ping requests at a configurable interval.
Changes
PingConfiginterface to configure periodic ping optionspingconfiguration option toClientOptions_startPeriodicPing()method to begin periodic ping after connection_stopPeriodicPing()method to stop periodic ping on closeclose()method to ensure periodic ping is stopped when disconnectingonerrorcallback without stopping the intervalUsage
Testing
Added comprehensive test suite covering:
Diff Stats