fix(mcp): handle MCP server connection failures (#769)#772
Open
xiaoju111a wants to merge 2 commits intoMoonshotAI:mainfrom
Open
fix(mcp): handle MCP server connection failures (#769)#772xiaoju111a wants to merge 2 commits intoMoonshotAI:mainfrom
xiaoju111a wants to merge 2 commits intoMoonshotAI:mainfrom
Conversation
…I#769) - Change MCP connection failures from fatal errors to warnings - Allow CLI to start even when some MCP servers fail to connect - Successfully connected MCP servers remain available - Improves fault tolerance and user experience Fixes MoonshotAI#769
Change 'if unauthorized_servers' to 'elif' to prevent showing misleading 'mcp servers connected' toast when servers fail to connect.
Closed
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
Fixes #769 #1102
Related Issue
Problem
Currently, when Kimi Code CLI starts, if any configured MCP (Model Context Protocol) server fails to connect, the CLI immediately exits with a fatal error. This "all-or-nothing" approach prevents users from accessing the interactive interface even when they only need built-in tools or other working MCP servers.
Root Cause
The original design used a "fail fast" principle for synchronous MCP loading. Later, the code was refactored to support background loading (
in_background=Trueby default) for faster startup. However, the error handling wasn't updated accordingly - the background task still raisedMCPRuntimeErroron connection failures, which caused delayed crashes whenwait_for_mcp_tools()was called.Solution
This PR changes the behavior to be more fault-tolerant:
toolset.py:302, replacedraise MCPRuntimeError(...)withlogger.warning(...)MCPRuntimeErrorfrom docstrings inagent.pyandapp.pyto reflect the new behaviorChanges Made
Modified Files:
src/kimi_cli/soul/toolset.py- Changed error raising to warning loggingsrc/kimi_cli/soul/agent.py- Updated docstringsrc/kimi_cli/app.py- Updated docstringImpact Analysis
MCPRuntimeErrorbeing raisedTesting
Manual Testing Steps
~/.kimi/mcp.json:{ "mcpServers": { "broken-server": { "command": "nonexistent-command", "args": [] } } }kimi "hello world"Expected behavior:
Before this fix:
MCPRuntimeErrorChecklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.