Skip to content

mcp: add configurable keepalive failure threshold#982

Merged
guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
cogvel:feat/configurable-keepalive-failure-threshold
May 31, 2026
Merged

mcp: add configurable keepalive failure threshold#982
guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
cogvel:feat/configurable-keepalive-failure-threshold

Conversation

@tdabasinskas
Copy link
Copy Markdown
Contributor

@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
@guglielmo-san guglielmo-san merged commit 8805aa8 into modelcontextprotocol:main May 31, 2026
9 checks passed
@tdabasinskas tdabasinskas deleted the feat/configurable-keepalive-failure-threshold branch May 31, 2026 10:02
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