Skip to content

Handle MCP transport timeouts and disconnects - #452

Open
anthonyivn2 wants to merge 2 commits into
databricks:mainfrom
anthonyivn2:fix/allow-longer-timeout-limit
Open

Handle MCP transport timeouts and disconnects#452
anthonyivn2 wants to merge 2 commits into
databricks:mainfrom
anthonyivn2:fix/allow-longer-timeout-limit

Conversation

@anthonyivn2

@anthonyivn2 anthonyivn2 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • configure the MCP HTTP client with timeout values matching the MCP Python SDK’s recommended client defaults: 30 seconds for connect/write/pool and 300 seconds for reads
  • raise exceptions yielded by MCP transport streams instead of forwarding them as messages
  • treat unexpected upstream EOF as a transport failure while preserving clean shutdown when the client closes stdin

Issues the PR resolves

Align the custom HTTP client with MCP SDK timeouts

Problem: ucode supplies its own HTTPX client to attach Databricks per-request authentication. This bypasses the SDK client factory and its timeout configuration, leaving HTTPX’s 5-second read-inactivity default in effect. A slow GitHub MCP response can therefore disconnect while the operation is still valid.

The MCP protocol does not mandate timeout values. The 30-second connect/write/pool timeout and 300-second read timeout come from the MCP Python SDK implementation in v2.1.1.

Fix: explicitly configure these values on ucode’s authenticated client so it retains the SDK-recommended timeout behavior.

Code: src/ucode/mcp_proxy.py_run()

Propagate errors yielded by MCP streams

Problem: MCP read streams can yield an Exception instead of a protocol message. The proxy previously forwarded every yielded value to stdio, so it did not recognize this value as a transport failure.

Fix: detect and raise yielded exceptions. The bridge terminates with the original error, allowing the client to observe that the MCP connection failed.

Code: src/ucode/mcp_proxy.py_pump()

Fail when the upstream stream closes unexpectedly

Problem: some transport failures surface to the proxy only as upstream EOF. Both proxy directions previously treated EOF as normal completion. The upstream pump could therefore finish successfully while the client-input pump continued waiting on stdin, leaving the proxy alive but unable to receive tool responses. Claude would continue showing the tool call as running.

Fix: treat completion of the upstream pump as an error. The error cancels the client-input pump and terminates the proxy. The client-input pump remains the normal control path, so Claude closing stdin still cancels the upstream task and shuts down cleanly.

Code: src/ucode/mcp_proxy.py_pump_upstream() and _run()

Testing

  • uv run --frozen pytest tests/test_mcp_proxy.py -q — 27 passed
  • uv run --frozen ruff check .
  • git diff --check

@anthonyivn2
anthonyivn2 force-pushed the fix/allow-longer-timeout-limit branch from 4f55378 to fea8136 Compare September 2, 2026 13:52
@anthonyivn2
anthonyivn2 marked this pull request as ready for review September 2, 2026 14:10
Comment thread src/ucode/mcp_proxy.py Outdated
Comment thread src/ucode/mcp_proxy.py Outdated
Comment thread src/ucode/mcp_proxy.py
Anthony Ivan added 2 commits September 3, 2026 01:00
Signed-off-by: Anthony Ivan <anthony.ivan@databricks.com>
Signed-off-by: Anthony Ivan <anthony.ivan@databricks.com>
@anthonyivn2
anthonyivn2 force-pushed the fix/allow-longer-timeout-limit branch from 82b0168 to b985ada Compare September 2, 2026 17:01
@sunishsheth2009

Copy link
Copy Markdown
Collaborator

Approved the PR, can we confirm that this PR will resolve this issue?

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