Skip to content

mcp: add configurable keepalive failure threshold#982

Open
tdabasinskas wants to merge 2 commits into
modelcontextprotocol:mainfrom
cogvel:feat/configurable-keepalive-failure-threshold
Open

mcp: add configurable keepalive failure threshold#982
tdabasinskas wants to merge 2 commits into
modelcontextprotocol:mainfrom
cogvel:feat/configurable-keepalive-failure-threshold

Conversation

@tdabasinskas
Copy link
Copy Markdown

@tdabasinskas tdabasinskas commented May 29, 2026

mcp: add configurable keepalive failure threshold

Introduce KeepAliveFailureThreshold option in both ClientOptions and ServerOptions to control how many consecutive keepalive ping failures are tolerated before closing the session.

This aligns with the MCP spec's guidance that "multiple failed pings MAY trigger a connection reset," allowing operators to tune resilience against transient network hiccups without immediately tearing down otherwise healthy sessions.

A threshold of 0 or 1 (the default) closes on the first failure, preserving existing behavior. Higher values let isolated misses pass while still closing the session once consecutive failures reach the threshold. A successful ping resets the counter.

Tolerated failures are logged at WARN level; the final failure that closes the session is logged at ERROR level.

This is rework of #979.

Introduce `KeepAliveFailureThreshold` option in both `ClientOptions` and `ServerOptions` to control how many consecutive keepalive ping failures are tolerated before closing the session.

This aligns with the MCP spec's guidance that "multiple failed pings MAY trigger a connection reset," allowing operators to tune resilience against transient network hiccups without immediately tearing down otherwise healthy sessions.

A threshold of 0 or 1 (the default) closes on the first failure, preserving existing behavior. Higher values let isolated misses pass while still closing the session once consecutive failures reach the threshold. A successful ping resets the counter.

Tolerated failures are logged at WARN level; the final failure that closes the session is logged at ERROR level, maintaining observability per modelcontextprotocol#218.
@tdabasinskas tdabasinskas changed the title feat(mcp): add configurable keepalive failure threshold mcp: add configurable keepalive failure threshold May 29, 2026
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.

2 participants