fix(health): unauthenticated liveness probe for authorization_code gateways + POST ping for StreamableHTTP#4496
Open
ecthelion77 wants to merge 1 commit intoIBM:mainfrom
Conversation
Replace the full MCP SDK client session.initialize() with a lightweight JSON-RPC POST for StreamableHTTP health checks. The SDK opens a GET SSE stream after initialize which returns 405 on servers that don't support server-initiated messages (M365, Kubernetes MCP, GitHub MCP). For authorization_code OAuth gateways, the health check no longer marks the gateway as failed when the system account has no stored token. Instead, it proceeds without auth — a 401/403 proves the server is alive, while timeouts/DNS/connection errors indicate a real outage. Signed-off-by: Olivier Gintrand <[email protected]>
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 #4495
Summary
The gateway health check marks all
authorization_codeOAuth gateways as unreachable after pod restarts because the system account (PLATFORM_ADMIN_EMAIL) has no stored OAuth tokens. This PR introduces an unauthenticated liveness probe strategy: when no token is available, the health check proceeds without auth — HTTP 401/403 proves the server is alive, while timeouts/DNS/connection errors indicate a real outage.Additionally, replaces the full MCP SDK
ClientSession.initialize()for StreamableHTTP health checks with a lightweight JSON-RPC POSTinitializerequest. The SDK opens a GET SSE stream after initialize which returns 405 on servers that don't support server-initiated messages (the MCP spec says GET is optional).Changes
mcpgateway/services/gateway_service.py—_check_single_gateway_health():1. Unauthenticated liveness probe (
unauthenticated_probeflag)For
authorization_codegateways, the health check now:_handle_gateway_failure()unauthenticated_probe = Trueso that HTTP 401/403 responses are treated as "server alive" for both SSE and StreamableHTTP transports_handle_gateway_failureas beforePreviously, the code did an early return to
_handle_gateway_failure()whenuser_emailwas missing or when no stored token was found, making it impossible for authorization_code gateways to pass health checks under a system account.2. Lightweight StreamableHTTP health check
Replaced the full SDK client session:
The MCP SDK
ClientSession.initialize()opens a GET SSE stream after the initialize handshake. Servers that don't support server-initiated messages (M365 MCP, Kubernetes MCP, GitHub MCP) return 405 on GET, causing a false health failure. A successful POSTinitializeis sufficient proof of health per the MCP spec.3. Observability
Added
health.probe_type: unauthenticated_livenessspan attribute when probing without auth, for tracing visibility.Testing
Validated in production with 13 gateways (8
authorization_code+ 5 non-OAuth). After deployment:reachable=truereachable=falseafter every pod restartSigned-off-by: Olivier Gintrand [email protected]