fix: configure_logging targets 'mcp' logger instead of root logger (fixes #2527)#2534
Open
weiguangli-io wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Conversation
…modelcontextprotocol#2527) Previously configure_logging() called logging.basicConfig(), which adds a RichHandler at INFO level to the **root** logger. This caused every library (httpx, urllib3, openai, …) to emit INFO records through Rich → stderr. In stdio MCP servers spawned by Node.js hosts (Claude Desktop, Cline, …) the kernel's stderr SNDBUF (8 KB on macOS) fills under modest log volume, and write(2) blocks the asyncio event loop, deadlocking the server. Changes: - configure_logging() now targets logging.getLogger("mcp") instead of the root logger via basicConfig. - Sets mcp_logger.propagate = False so records don't reach any root handlers. - Made idempotent: skips setup if the mcp logger already has handlers, allowing application code to configure logging before MCPServer.__init__. - Default log level changed from "INFO" to "WARNING" to reduce noise from MCP's own internals in production/stdio deployments. - MCPServer.__init__ log_level parameter default also changed to "WARNING". - Added regression tests in tests/issues/test_2527_fastmcp_logger_pollution.py. Fixes modelcontextprotocol#2527 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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 #2527 —
MCPServer.__init__calledconfigure_logging()which usedlogging.basicConfig()to install aRichHandleron the root logger at INFO level. This caused every third-party library (httpx, urllib3, openai, qdrant-client, …) to emit INFO records through Rich → stderr. In stdio MCP servers spawned by Node.js hosts (Claude Desktop, Cline, qwen-code), the kernel's stderr SNDBUF (8 KB on macOS) fills under modest log volume andwrite(2)blocks the asyncio event loop, deadlocking the server.Changes
configure_logging()now configureslogging.getLogger("mcp")instead of the root logger viabasicConfig.mcp_logger.propagate = Falseso records don't bubble up to any root handlers.mcplogger already has handlers, allowing applications to configure logging before constructingMCPServer."INFO"→"WARNING"— reduces noise from transitive dependencies in production/stdio deployments. Users can passlog_level="INFO"(or"DEBUG") explicitly when they want verbose output.MCPServer.__init__log_levelparameter default also changed to"WARNING".tests/issues/test_2527_fastmcp_logger_pollution.py.Before / After
Before (broken):
After (fixed):
Test plan
uv run pytest tests/issues/test_2527_fastmcp_logger_pollution.py -v— 5 new regression tests, all passuv run pytest tests/server/mcpserver/test_server.py -v— 89 existing tests, all pass🤖 Generated with Claude Code