Skip to content

fix: redirect stdio MCP stderr to logs#2259

Open
he-yufeng wants to merge 2 commits into
MoonshotAI:mainfrom
he-yufeng:fix/mcp-stdio-log-file
Open

fix: redirect stdio MCP stderr to logs#2259
he-yufeng wants to merge 2 commits into
MoonshotAI:mainfrom
he-yufeng:fix/mcp-stdio-log-file

Conversation

@he-yufeng
Copy link
Copy Markdown

@he-yufeng he-yufeng commented May 13, 2026

Summary

  • route stdio MCP subprocess stderr to ~/.kimi/logs/mcp/<server>.log instead of the interactive terminal
  • keep non-stdio MCP server setup on the existing MCPConfig path
  • add a focused regression test for sanitized per-server log paths

Notes

This addresses the stderr leak described in #2251. It is separate from MCP logging notifications handled in #1637; those are in-protocol log messages, while this patch covers the child process stderr stream that FastMCP 3.2.4 defaults to sys.stderr.

To verify

  • uv run pytest tests\core\test_mcp_stdio_logging.py -q -p no:cacheprovider --basetemp .tmp\pytest
  • uv run pytest tests\cli\test_mcp_oauth.py::test_load_mcp_tools_treats_unreadable_oauth_storage_as_unauthorized -q -p no:cacheprovider --basetemp .tmp\pytest-oauth
  • uv run ruff check src\kimi_cli\soul\toolset.py tests\core\test_mcp_stdio_logging.py
  • uv run ruff format --check src\kimi_cli\soul\toolset.py tests\core\test_mcp_stdio_logging.py
  • uv run pyright src\kimi_cli\soul\toolset.py tests\core\test_mcp_stdio_logging.py

Open in Devin Review

Copy link
Copy Markdown

@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: e6a6f9c641

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/kimi_cli/soul/toolset.py Outdated
Comment on lines +99 to +103
if isinstance(server_config, StdioMCPServer):
log_path = _mcp_stdio_log_path(server_name)
log_path.parent.mkdir(parents=True, exist_ok=True)
transport = StdioTransport(
command=server_config.command,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve transforming stdio MCP configs

_build_mcp_client now treats any StdioMCPServer instance as a plain stdio transport and constructs StdioTransport directly, which bypasses server_config.to_transport(). In FastMCP, transforming stdio configs (e.g., with tools/include_tags/exclude_tags) subclass StdioMCPServer, so this branch silently drops those transforms and exposes unfiltered tools whenever users configure a transforming stdio server. The previous Client(MCPConfig(...)) path preserved that behavior, so this is a functional regression for transformed stdio MCP setups.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
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 3 additional findings.

Open in Devin Review

@he-yufeng
Copy link
Copy Markdown
Author

Addressed the review point. Plain StdioMCPServer configs still get a StdioTransport with a log file, but transforming stdio configs now keep the FastMCP MCPConfig transport path so tools / include_tags / exclude_tags are preserved.

Validated locally:

  • .venv\Scripts\python.exe -m pytest tests\core\test_mcp_stdio_logging.py -q --basetemp .tmp\pytest -p no:cacheprovider
  • .venv\Scripts\python.exe -m ruff check src\kimi_cli\soul\toolset.py tests\core\test_mcp_stdio_logging.py
  • .venv\Scripts\python.exe -m ruff format --check src\kimi_cli\soul\toolset.py tests\core\test_mcp_stdio_logging.py
  • .venv\Scripts\python.exe -m py_compile src\kimi_cli\soul\toolset.py tests\core\test_mcp_stdio_logging.py
  • git diff --check

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.

1 participant