feat: MCP 服务器手动重连功能#84
Open
dengmik-commits wants to merge 1 commit into
Open
Conversation
Replace automatic retry with user-initiated reconnect: - Failed servers show error details and a [Reconnect] option - Reconnect reads latest config from disk (no restart needed) - Single attempt per reconnect, no backoff/retry
Collaborator
|
@dengmik-commits 高优问题:reconnect后界面会显示 MCP 服务已经重连成功,但实际对话时模型仍然用不到这个服务提供的工具。也就是说用户会看到“Ready”,但后续让模型调用该 MCP 工具时可能还是失败或根本不会被调用。 复现步骤:
|
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.



概述
当前 MCP 服务器初始化失败后直接标记
failed,无法恢复。本 PR 增加了手动重连机制:用户可在/mcp界面进入失败的服务器详情,选择 Reconnect 触发单次重连。设计
关键约束:
变更
src/mcp/mcp-client.tsonDisconnect回调参数,区分主动断开与进程崩溃isConnected()方法safeReject修复进程退出竞态条件:close 事件可能在 sendRequest 注册前触发,导致 connect() 永远等待超时.cmd)src/mcp/mcp-manager.tsMcpServerStatus.status类型新增"reconnecting"initialize()拆分出connectServer():单次尝试,失败直接setStatus("failed")reconnect(name, config?):接受可选的最新配置,更新缓存并重连onServerCrash():运行时崩溃清理旧条目并标记failed,不自动重连DEEPCODE_MCP_TIMEOUT(单次连接超时,默认 30s)src/session.tsreconnectMcpServer(name, config?)委托给 McpManagersrc/ui/App.tsxMcpStatusList传入onReconnect回调resolveCurrentSettings()保证每次重连都读取最新配置src/ui/McpStatusList.tsxenterDetail允许failed/reconnecting服务器进入详情ServerDetailView新增onReconnectpropfailed服务器渲染[Reconnect]菜单项,默认>光标选中ItemRow支持action类型,选中时显示>前缀Enter to reconnect · Esc back · Ctrl+C closesrc/tests/session.test.tsSessionManager marks MCP server as failed on single failed attempt (no auto-retry)— 确认失败后无自动重连SessionManager reconnect succeeds on previously failed server— 确认手动重连成功验证
自动化测试
手动验证流程
1. 制造失败: 将
~/.deepcode/settings.json中 fetch 服务器包名改为不存在的包:"fetch": { "command": "npx", - "args": ["-y", "mcp-fetch-server"] + "args": ["-y", "mcp-fetch-server-BROKEN"] }2. 启动 deepcode,执行
/mcp:3. Enter 进入详情:
4. Enter 触发重连(包名仍然错误)—— 返回列表,看到
↻ Reconnecting...后再次✗ Failed。5. 改回正确包名:
6. 再次 Enter →
[Reconnect]→ Enter —— fetch 恢复✓ Ready。关键: 步骤 5-6 无需重启 deepcode,
reconnect()每次从磁盘实时读取最新配置。