Skip to content

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

@mingdaoai

Description

@mingdaoai

Problem

When starting kimi -C (or kimi --continue) with OAuth MCP servers configured (e.g., Todoist), verbose debug messages from the mcp-remote library are printed directly to the console during MCP server connection. These messages include protocol traces like:

[16850] Using existing client port: 39725
[16850] Discovering OAuth server configuration...
[16850] Connecting to remote server: https://ai.todoist.net/mcp
[16850] Using transport strategy: http-first
[16852] Connected to remote server using StreamableHTTPClientTransport
[Local→Remote] initialize
{"jsonrpc": "2.0", "id": 0, "method": "initialize", ...}

This is noisy and distracting for users.

How to Reproduce

  1. Install the Todoist MCP server:

    kimi mcp add --transport http --auth oauth todoist https://ai.todoist.net/mcp
    
  2. Authorize the MCP server:

    kimi mcp auth todoist
    
  3. Start kimi with -C to continue a session (or start a new session):

    kimi -C
    
  4. The verbose debug messages will appear on startup.

Reference: https://developer.todoist.com/api/v1/#tag/Todoist-MCP

Root Cause

In src/kimi_cli/cli/__init__.py, the redirect_stderr_to_logger() call was placed after KimiCLI.create() (line 499), which meant:

  1. CLI parsing errors would be hidden if redirected too early
  2. But MCP loading happens inside KimiCLI.create(), so the verbose messages printed before redirection

Proposed Fix

Move redirect_stderr_to_logger() to before KimiCLI.create() so MCP verbose messages are captured to the log file.

In src/kimi_cli/cli/__init__.py, change:

instance = await KimiCLI.create(
    session,
    ...
)
# Install stderr redirection only after initialization succeeded...
redirect_stderr_to_logger()

To:

# Enable stderr redirection before MCP loading to capture verbose debug
# messages from mcp-remote library. CLI parsing is done by now, so startup
# errors would have already been shown.
redirect_stderr_to_logger()
instance = await KimiCLI.create(
    session,
    ...
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions