fix: gracefully degrade on MCP server connection failure#1450
Open
fix: gracefully degrade on MCP server connection failure#1450
Conversation
…rashing When an MCP server fails to connect (e.g. missing binary), log a warning and continue with remaining servers instead of raising MCPRuntimeError. Also catch all exceptions in MCPTool.__call__ to handle runtime server disconnections gracefully by returning ToolError.
…ailure The MCP background connection code sent multiple mutually-exclusive toasts (failure, unauthorized, success) at the end of _connect(), causing the last one to overwrite earlier ones. Consolidate into a single final_toast variable with priority: failure > unauthorized > success. Also remove stray top-level code in test_toolset.py that caused NameError on import.
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.
Related Issue
Description
When an MCP server fails to connect (e.g., network issues or misconfiguration), the CLI previously raised
MCPRuntimeErrorand crashed the entire session. Similarly, if an MCP tool call encountered a runtime error (e.g., server disconnected mid-call), the unhandled exception would propagate and crash the session.This PR makes two key improvements:
Graceful degradation on MCP connection failure: Instead of crashing, failed servers are logged as warnings and skipped. The remaining healthy servers still load normally. A single consolidated toast notification is emitted with priority: connection failure > authorization needed > success, preventing a success toast from overriding a failure toast.
Resilient MCP tool execution: When an MCP tool call fails at runtime, the error is caught and returned as a
ToolErrorinstead of crashing the session, allowing the conversation to continue.Changes
src/kimi_cli/soul/toolset.py: ReplacedMCPRuntimeErrorraise with warning logs + graceful skip on connection failure; consolidated toast notifications into a single emit with priority logic; wrapped MCP tool call exceptions inToolErrorinstead of re-raisingtests/core/test_toolset.py: Added 4 new test cases covering failure toast, authorization toast, success toast, and failure-over-unauthorized priority.gitignore: Added playwright report/test-results pathsChecklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.