Skip to content

feature: Implement proactive HTTP client keepalive ping mechanism #576

@peter-kismarczi

Description

@peter-kismarczi

Problem Statement

When our agent performs time-intensive operations (such as web scraping, form filling, waiting for page loads, or processing large datasets) using HTTP protocol, the Go MCP client fails to send periodic ping requests to maintain the connection with the server. During long-running operations, the client remains silent and does not send any 'keep alive' messages, causing the server to interpret this as a dead connection and terminate the session, resulting in the loss of all browser context.

This issue appears to be related to client-side limitations in the Go MCP library implementation. We observe that while Claude Code properly handles connection timeout parameters sent by the Playwright MCP server and maintains the connection by regularly sending ping requests, the Go MCP library-based clients exhibit concerning behavior: they do not appear to respect server timeout parameters and seem unable to proactively send ping requests over HTTP to keep connections alive during extended operations. Attempting to work around this client limitation by sending manual 'keep alive' ping requests from application code introduces additional problems as it breaks the sequence ordering of requests in the MCP protocol.

Verification Scenarios

To demonstrate the client-side problem and validate the solution, we present two scenarios:

Scenario 1: Go MCP Client Failure Link to video
We're using the playwright-mcp image, run it locally with HTTP transport mode, and start a MITM reverse proxy to track the traffic. When assigning a long-running task to a custom agent using the Go MCP library, the client fails to send any ping requests during the operation. The trace reveals that for the same mcp-session-id, a 404 response is received after approximately 10 seconds, indicating the server has terminated the connection due to the client's failure to send keepalive ping messages.

Scenario 2: Claude Code Client Success Link to video
Running the playwright-mcp locally with MITM proxy monitoring, we add it as an MCP server to Claude Code. When assigning the same time-intensive task to Claude, it successfully completes the operation. The trace shows that the session remains active throughout, as Claude Code's client implementation regularly sends ping requests to the server, maintaining the connection and preventing premature termination.

Proposed Solution

Based on our analysis, we believe this client-side issue could be addressed through a few potential approach. One would involve enhancing the Go MCP client to proactively send periodic ping requests to servers during long-running operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions