Repository navigation
WIP: fix: end the remote MCP connect wait on a bad reply or no reply - #2007
chiang-daniel wants to merge 1 commit into
Conversation
…mcp_session The remote MCP connect waited forever when the server sent a reply the MCP SDK can't read, such as a web page, or sent no reply. The new message_handler keeps the MCP SDK's error and raises it, so the connect fails at once with that error. The session uses the local session's 30-second read timeout. McpError joins the remote error list so the MCP SDK's text reaches the user. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedIgnore keyword(s) in the title. ⛔ Ignored keywords: 2
Please check the settings in the CodeRabbit UI or the
|
📊 Coverage ReportOverall Coverage: 94% Diff: origin/main...HEAD
Summary
|
Description
REPLACE: what this PR is, in 1 to 2 sentences max.Author Review (required)
Architecture Review (select 1)
NAReview Requested from Code Reviewer (select 1)
[reason - required if selected]Agentic Code Review (must check all before requesting CR)
/spec deep cron this PR or used/specCRs throughoutWhat to Review
REPLACE: 1-4 decisions you made.REPLACE: List of paths/files to review. example libs/code/adapters/KevAdapter.pyUI Review (select all that apply)
personAgentic PR Summary
TLDR: A user's remote MCP connect spun forever, because the server sent a web page and the MCP SDK left the request waiting. This PR fails the connect at once with the MCP SDK's error, and gives each request a 30-second limit, as local MCP has. Targets
main. No companion PRs.Before this PR,
POST /api/projects/{project_id}/connect_remote_mcpwaited with no limit in two cases: the server sent a reply that the MCP SDK cannot read (for example a web page), or the server sent no reply. The spinner in the UI did not stop. The user's log showedUnexpected content type: text/html;charset=utf-8frommcp.client.streamable_http, and then nothing. After this PR, an unreadable reply fails the connect at once, and the error box shows the MCP SDK's text. A server that sends no reply fails after 30 seconds.Implementation
_create_remote_mcp_sessiongivesClientSessionamessage_handler. MCP SDK 1.30.0 sends an unreadable reply to this callback and leaves the request waiting. The callback keeps the error and raises it, so the connect fails with that error and not with "Connection closed"._create_remote_mcp_sessionsetsread_timeout_seconds=timedelta(seconds=30). This is the value that the local MCP session uses._handle_remote_mcp_errornow also looks forMcpError, as the local error list does. The user then sees the MCP SDK's text and not "unhandled errors in a TaskGroup".httpx.MockTransport. They use no sockets.Before you merge
MCPSessionManager.mcp_clientis public inlibs/core. On a remote server, each request in its block now has a 30-second limit,call_toolincluded. Kiln itself usesmcp_clientonly forlist_tools. A remote server that needs more than 30 seconds to start now fails to connect.main, the MCP SDK logs these and the connect continues.Not in this PR
_create_cached_remote_session. That session has no limit and no callback, so an agent run against the same server still waits with no limit. TheMcpErrorchange does improve its connect error text.initializegets past the 30-second limit, because the MCP SDK starts the timer only after it sends the next request. The httpx read timeout of 5 minutes ends it, and the error box shows "unhandled errors in a TaskGroup".Related: KIL-859.
Checks:
uv run ./checks.sh --agent-modegreen. Two agent reviews ran:/spec cr, and Claude Code/code-reviewat high effort. The only code change from them is the comment onend_on_unreadable_reply. The other findings are the items above. A break of each part of the fix (the callback, the kept error,McpError, the limit) makes a new test fail. Tested against fake servers only, not a real Spring AI server. This final version was not run in the desktop app.Docs and skills updated: none needed, no doc or skill names the remote MCP session code or its limits.
Errors the user sees
mainUnexpected content type: text/html;charset=utf-8, at onceunhandled errors in a TaskGroup (1 sub-exception)Timed out while waiting for response to ClientRequest. Waited 30.0 seconds.🤖 Generated with Claude Code