Skip to content

SSE Server drops client connection at 5 min. #414

Description

@albayrakonur

Bug description
I developed a MCP server with webmvc SSE endpoint but when a client connects via /sse endpoint, after appx 5 min later server drops connection. This is happen because Client-side needs from server-side to ping itself. Current release doesnt support this and

Environment
JDK:17
Spring Boot: 3.5.3
Spring AI: 1.0.0

Steps to reproduce
You can reproduce this bug on any setup. I try with Spring example with webmvc https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/weather/starter-webmvc-server You can start this app and just connect it with cursor or vscode and then 5min later client will got an error.

Client-side servername: LOCAL-SERVER,
"LOCAL-SERVER": {
"url": "http://localhost:8080/sse"
}

2025-07-18 21:18:05.422 [info] user-LOCAL-SERVER: Handling CreateClient action
2025-07-18 21:18:05.422 [info] user-LOCAL-SERVER: Creating streamableHttp transport
2025-07-18 21:18:05.422 [info] user-LOCAL-SERVER: Connecting to streamableHttp server
2025-07-18 21:18:05.432 [error] user-LOCAL-SERVER: Client error for command Error POSTing to endpoint (HTTP 404): {"timestamp":"2025-07-18T18:18:05.431+00:00","status":404,"error":"Not Found","path":"/sse"}
2025-07-18 21:18:05.433 [info] user-LOCAL-SERVER: Client closed for command
2025-07-18 21:18:05.433 [error] user-LOCAL-SERVER: Error connecting to streamableHttp server, falling back to SSE: Error POSTing to endpoint (HTTP 404): {"timestamp":"2025-07-18T18:18:05.431+00:00","status":404,"error":"Not Found","path":"/sse"}
2025-07-18 21:18:05.433 [error] user-LOCAL-SERVER: Error connecting to streamableHttp server, falling back to SSE: Error POSTing to endpoint (HTTP 404): {"timestamp":"2025-07-18T18:18:05.431+00:00","status":404,"error":"Not Found","path":"/sse"}
2025-07-18 21:18:05.433 [info] user-LOCAL-SERVER: Connecting to SSE server
2025-07-18 21:18:05.448 [info] user-LOCAL-SERVER: Successfully connected to streamableHttp server
2025-07-18 21:18:05.448 [info] user-LOCAL-SERVER: Storing streamableHttp client
2025-07-18 21:18:05.449 [info] user-LOCAL-SERVER: Handling ListOfferings action
2025-07-18 21:18:05.449 [info] user-LOCAL-SERVER: Listing offerings
2025-07-18 21:18:05.449 [info] user-LOCAL-SERVER: Connected to streamableHttp server, fetching offerings
2025-07-18 21:18:05.452 [info] listOfferings: Found 3 tools
2025-07-18 21:18:05.452 [info] user-LOCAL-SERVER: Found 3 tools
2025-07-18 21:23:09.107 [error] user-LOCAL-SERVER: Client error for command SSE error: TypeError: terminated: Body Timeout Error

Expected behavior
You can add periodic ping option to keep alive for each client connection. (time)

Same issue: https://github.com/modelcontextprotocol/typescript-sdk/issues/270

Activity

  1. changed the title [-]SSE Server drop client connection at 5 min.[/-] [+]SSE Server drops client connection at 5 min.[/+] on Jul 18, 2025
  2. tzolov commented on Jul 21, 2025

    @tzolov
    Contributor

    Related to #353

  3. tzolov commented on Jul 21, 2025

    @tzolov
    Contributor

    @albayrakonur, please check this comment.
    In the meantime please consider using the McpAsyncServer#loggingNotification and McpSyncServer#loggingNotification for the same purpose heatbeating

  4. added this to the 0.11.0 milestone on Jul 21, 2025
  5. self-assigned this
    on Jul 21, 2025
  6. added 3 commits that reference this issue on Jul 30, 2025
    08b1d03
    03f20ab
    1840f63
  7. added a commit that references this issue on Jul 30, 2025
    ee2c891
  8. viyaviya commented on Aug 6, 2025

    @viyaviya

    I tried it locally, but it seems that the issue has not been resolved. Below is the log I reproduced

    1. client init success
    client
    2025-08-06 18:36:09.556 DEBUG [TID: N/A] [HttpClient-1-Worker-0] io.modelcontextprotocol.spec.McpSchema - Received JSON message: {"jsonrpc":"2.0","id":"a2ab5686-0","result":{"protocolVersion":"2024-11-05","capabilities":{"completions":{},"logging":{},"prompts":{"listChanged":true},"resources":{"subscribe":false,"listChanged":true},"tools":{"listChanged":true}},"serverInfo":{"name":"action-server","version":"1.0.0"}}}
    server

    2025-08-06 18:36:09.553 DEBUG [TID: N/A] [http-nio-8080-exec-4] io.modelcontextprotocol.spec.McpServerSession - Received request: JSONRPCRequest[jsonrpc=2.0, method=initialize, id=a2ab5686-0, params={protocolVersion=2024-11-05, capabilities={}, clientInfo={name=Spring AI MCP Client, version=0.3.1}}]
    2. client send ping/5s
    client log
    2025-08-06 18:36:10.152 DEBUG [TID: N/A] [pool-12-thread-1] io.modelcontextprotocol.spec.McpClientSession - Sending message for method ping 2025-08-06 18:36:10.155 DEBUG [TID: N/A] [HttpClient-1-Worker-0] io.modelcontextprotocol.spec.McpSchema - Received JSON message: {"jsonrpc":"2.0","id":"a2ab5686-1","result":{}}
    3. server send ping/30s
    client log
    2025-08-06 18:36:13.536 DEBUG [TID: N/A] [HttpClient-1-Worker-3] io.modelcontextprotocol.spec.McpSchema - Received JSON message: {"jsonrpc":"2.0","method":"ping","id":"c5a37778-c744-4a5e-9108-75be2fe5fb89-0"} 2025-08-06 18:36:13.537 DEBUG [TID: N/A] [HttpClient-1-Worker-3] io.modelcontextprotocol.spec.McpClientSession - Received request: JSONRPCRequest[jsonrpc=2.0, method=ping, id=c5a37778-c744-4a5e-9108-75be2fe5fb89-0, params=null] 2025-08-06 18:36:13.539 DEBUG [TID: N/A] [HttpClient-1-Worker-3] io.modelcontextprotocol.client.McpAsyncClient - Received ping: 2025-08-06T18:36:13.5388951
    4. After about 5 minutes
    ping timeout , try next init
    2025-08-06 18:40:36.793 DEBUG [TID: N/A] [pool-12-thread-1] io.modelcontextprotocol.spec.McpClientSession - Sending message for method initialize 2025-08-06 18:40:36.803 DEBUG [TID: N/A] [HttpClient-2-Worker-2] io.modelcontextprotocol.spec.McpSchema - Received JSON message: {"jsonrpc":"2.0","id":"20fb107a-0","result":{"protocolVersion":"2024-11-05","capabilities":{"completions":{},"logging":{},"prompts":{"listChanged":true},"resources":{"subscribe":false,"listChanged":true},"tools":{"listChanged":true}},"serverInfo":{"name":"action-server","version":"1.0.0"}}}

  9. viyaviya commented on Aug 6, 2025

    @viyaviya

    A new discovery has been made: after the client initiates around 60 pings, subsequent requests will encounter issues. During this period, no other messages are sent to the server; only ping operations are performed

  10. added a commit that references this issue on Jun 25, 2026
    7f007e3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions