fix(ai-chat): bound MCP server loading with timeouts and fix SSE interop hang#1740
Merged
Conversation
…rop hang A single unresponsive MCP server hung the whole /chat request forever: servers were loaded serially with no timeout, and @ai-sdk/mcp drops SSE events that carry no explicit `event:` field (agentgateway emits bare `data:` frames), so the muster tools/list response was silently discarded and the request promise never settled. - Load MCP servers in parallel, each bounded by a timeout (15s default, configurable via aiChat.mcp[].timeoutMs); hanging servers degrade gracefully into failedServers instead of blocking the chat. - Patch @ai-sdk/mcp to default the SSE event type to "message" when the event field is absent, per the SSE specification. Co-authored-by: Cursor <cursoragent@cursor.com>
JS Dependency Audit0 added · 0 removed · 287 total (0 vs base) Projects audited
No change in vulnerabilities compared to the base branch. Full current vulnerability list (287)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Production AI chat on the dev portal hung forever on every request after the muster MCP server started participating in chat (#1735 populated its auth token for the first time). Two compounding bugs:
getMcpToolsloaded MCP servers serially with no time bound, so one hanging server blocked the whole/chatrequest indefinitely.@ai-sdk/mcponly processes SSE events whoseevent:field is literallymessage. MCP responses proxied through agentgateway are SSE frames with baredata:lines (noevent:field), which per the SSE spec default to themessagetype. The client silently dropped every response — initialize/tools-list promises never settled, with no error on either side.Changes
aiChat.mcp[].timeoutMs). Timed-out servers land infailedServers(already surfaced to the system prompt) and their cache entry is evicted so the next request retries.yarn patchfor@ai-sdk/mcp@1.0.46: treat SSE events without an explicitevent:field asmessageevents (SSE spec § interpretation of omitted event type). Will be dropped once fixed upstream.Tests (written first, red → green)
getMcpTools.test.ts: hanging initialize, hanging tools/list, cache eviction after timeout, healthy-server baseline — all hung before the fix.mcpSseInterop.test.ts: real@ai-sdk/mcpclient against a minimal MCP server that mimics agentgateway's bare-data:SSE framing — timed out before the patch, passes with it.Test plan
Made with Cursor