-
Notifications
You must be signed in to change notification settings - Fork 556
Description
Description
I am encountering a persistent connection issue between an MCP client (running within an AI Agent environment) and the mcp-for-unity-server. The client fails to establish a stable connection, reporting a "context canceled" error immediately after the handshake, while the server logs indicate that the requests are being received and processed successfully (200 OK / 202 Accepted).
Environment
OS: Windows
Server: mcp-for-unity-server (FastMCP 2.13.1)
Transport: HTTP (http://localhost:8080/mcp)
Client: Google Deepmind Antigravity Agent (Internal MCP Client)
Symptoms
Client-Side Error
The client repeatedly fails with the following error when attempting to call tools or list resources:
connection closed: calling "resources/list": client is closing: standalone SSE stream: failed to reconnect (session ID: <SESSION_ID>): connection failed after 5 attempts: Get "http://localhost:8080/mcp": context canceled
Note: The <SESSION_ID> changes after restarting the client/IDE, confirming that the client state is resetting, but the error persists with the new session.
Server-Side Logs
The server logs show that the connection is accepted and the initial handshake requests are successful. There are no errors on the server side.
[12/05/25 08:57:57] INFO Starting MCP server 'mcp-for-unity-server' ...
...
2025-12-05 08:57:57,749 - mcp.server.streamable_http_manager - INFO - Created new transport with session ID: 257f88deefb74c59a42e319fa20e2cc6
INFO: ::1:59388 - "POST /mcp HTTP/1.1" 200 OK
INFO: ::1:59389 - "GET /mcp HTTP/1.1" 200 OK
INFO: ::1:59390 - "POST /mcp HTTP/1.1" 202 Accepted
INFO: ::1:59390 - "POST /mcp HTTP/1.1" 200 OK
Troubleshooting Steps Taken
Network Verification:
Confirmed TCP connectivity to localhost:8080 via PowerShell (Test-NetConnection) for both IPv4 (127.0.0.1) and IPv6 (::1).
Confirmed HTTP reachability via curl http://localhost:8080/mcp (returns 406 Not Acceptable as expected for non-SSE clients).
Firewall:
Verified that Python/Uvicorn is allowed through the Windows Firewall for both Private and Public networks.
Client Reset:
Restarted the client IDE to clear any stale session state.
Verified that a new Session ID was generated (e.g., changing from ba226... to 257f8...), but the context canceled error occurred immediately for the new session as well.
Hypothesis
It appears that while the server successfully processes the initial HTTP requests, the SSE (Server-Sent Events) stream connection is either dropping immediately or the client is timing out waiting for the first event. The mismatch between the "healthy" server logs and the client's "context canceled" suggests a potential issue with how the SSE stream is being kept alive or buffered on Windows/localhost.