Skip to content

fix: suppress verbose MCP debug messages from console output#1501

Closed
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/suppress-mcp-debug-output
Closed

fix: suppress verbose MCP debug messages from console output#1501
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/suppress-mcp-debug-output

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 19, 2026

Related Issue

Resolve #1214

Description

When using the -C flag (or any mode that loads MCP servers), verbose debug/trace messages from the mcp-remote library were printed directly to the console during startup. This happened because redirect_stderr_to_logger() was called after KimiCLI.create(), but MCP server loading occurs inside KimiCLI.create().

This PR moves the redirect_stderr_to_logger() call to just before KimiCLI.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: Moved redirect_stderr_to_logger() from after KimiCLI.create() to before it, and updated the surrounding comments to reflect the new placement rationale.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

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>
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +530 to +533
# 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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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.

Verbose MCP debug messages printed to console when starting with -C flag and OAuth MCP servers

2 participants