fix: suppress verbose MCP debug messages from console output#1501
fix: suppress verbose MCP debug messages from console output#1501Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
Move redirect_stderr_to_logger() to before KimiCLI.create() so that verbose debug/trace messages from mcp-remote and similar libraries are captured into the log file instead of leaking to the console. At this point CLI parsing is already complete, so startup errors are not affected. Fixes MoonshotAI#1214 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1eefc2110f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| # Enable stderr redirection before MCP loading to capture verbose | ||
| # debug messages from mcp-remote and similar libraries. CLI parsing | ||
| # is already complete at this point, so startup errors have been shown. | ||
| redirect_stderr_to_logger() |
There was a problem hiding this comment.
Don't hide startup stderr from stdio MCP servers
load_mcp_tools() runs inside KimiCLI.create() whenever MCP startup is not deferred (for example --print, --wire, --acp, or shell mode with an initial prompt), and FastMCP's stdio transport forwards the server's stderr to the client's stderr. Redirecting fd 2 before KimiCLI.create() therefore suppresses all startup messages from those servers, not just the noisy mcp-remote traces. That breaks MCP servers that print required bootstrap/auth instructions on stderr (device-code URLs, missing-runtime hints, etc.): users no longer see the actionable message on the console, only in kimi.log.
Useful? React with 👍 / 👎.
Related Issue
Resolve #1214
Description
When using the
-Cflag (or any mode that loads MCP servers), verbose debug/trace messages from themcp-remotelibrary were printed directly to the console during startup. This happened becauseredirect_stderr_to_logger()was called afterKimiCLI.create(), but MCP server loading occurs insideKimiCLI.create().This PR moves the
redirect_stderr_to_logger()call to just beforeKimiCLI.create(), so that stderr output from MCP server initialization is captured into the log file instead of cluttering the console. At this point, CLI argument parsing is already complete, so any startup errors (e.g., config parsing / BadParameter) will have already been displayed to the user.Changes
src/kimi_cli/cli/__init__.py: Movedredirect_stderr_to_logger()from afterKimiCLI.create()to before it, and updated the surrounding comments to reflect the new placement rationale.Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.