Skip to content

fix(mcp): prevent handshake hang when local stdio server exits early#888

Open
harryfan1985 wants to merge 2 commits into
GCWing:mainfrom
harryfan1985:fix/mcp-handshake-hang
Open

fix(mcp): prevent handshake hang when local stdio server exits early#888
harryfan1985 wants to merge 2 commits into
GCWing:mainfrom
harryfan1985:fix/mcp-handshake-hang

Conversation

@harryfan1985
Copy link
Copy Markdown
Contributor

Summary

Fixes #887 — three related issues that cause the MCP service list to hang on "加载中…" when a local stdio server fails to start.

Changes

1. Add 30s request timeout to local connections (connection.rs)

MCPConnection::new_local previously set request_timeout: None, causing send_request_and_wait to block forever when the server process exited before completing the handshake. Now defaults to 30s.

2. Drain pending waiters on channel close (connection.rs)

When the message channel closes (server process exits), handle_messages now clears all pending oneshot waiters so callers receive a clean MCPRuntimeError instead of hanging indefinitely.

3. Inject shell PATH on macOS (process_manager.rs)

macOS GUI apps have a minimal default PATH (/usr/bin:/bin:/usr/sbin:/sbin) with no Homebrew paths. create_tokio_command now resolves the user's shell PATH via zsh -ilc and injects it so shebang-driven tools (npx, uvx, node, etc.) work correctly.

4. Frontend timeout fallback (McpToolsConfig.tsx)

Added a 15s Promise.race timeout in loadServers as a defensive UI fallback — ensures setMcpLoading(false) always runs.

- Add 30s request timeout to MCPConnection::new_local to prevent
  permanent hang when server process exits before handshake completes
- Drain pending request waiters when message channel closes so
  callers receive a clean error instead of blocking forever
- Inject shell PATH on macOS in create_tokio_command so that
  shebang-driven tools (npx, uvx, node, etc.) resolve correctly
  when spawned from the GUI app (which has minimal default PATH)
- Add 15s Promise.race timeout in McpToolsConfig loadServers as
  defensive frontend fallback for stuck MCP server loads

Closes GCWing#887
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.

MCP local stdio: handshake hangs indefinitely when server process exits before responding

1 participant