fix: route AsyncLogger output to stderr by default (fixes #1968)#1969
Open
cgseyhan wants to merge 1 commit into
Open
fix: route AsyncLogger output to stderr by default (fixes #1968)#1969cgseyhan wants to merge 1 commit into
cgseyhan wants to merge 1 commit into
Conversation
MCP stdio transport uses stdout for JSON-RPC messages. AsyncLogger was writing Rich progress output to stdout (the default Console() target), which caused clients to receive garbled JSON and log lines interleaved in the same stream. Changes: - Pass stderr=True to Console() so all log output goes to stderr, which is the correct channel for library diagnostics and aligns with the behaviour of Python's own logging.StreamHandler. - Add an injectable console parameter so downstream wrappers (e.g. mcp-crawl4ai, FastMCP integrations) can override the target stream without monkey-patching. - Add import sys (used in docstring example). - Add tests/test_async_logger_stderr.py with 7 tests covering the default-to-stderr behaviour, custom console injection, verbose=False suppression, file logging, and an end-to-end MCP scenario. Fixes unclecode#1968
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.
Problem
AsyncLogger writes its Rich progress output to stdout via the default Console() constructor. When crawl4ai is used as an MCP server over stdio (e.g. with mcp-crawl4ai, Claude Desktop, or mcp-inspector), the log lines are injected into the JSON-RPC stream. Clients fail to parse the messages and report:
Failed to parse JSONRPC message from server
This was reported in #1968.
async_logger.py – before
self.console = Console() # writes to stdout by default
ich.Console() without arguments writes to stdout. Library log output should go to stderr — this is the POSIX convention and what Python's own logging.StreamHandler does.
async_logger.py – after
self.console = console if console is not None else Console(stderr=True)
Two changes:
Testing
Added ests/test_async_logger_stderr.py with 7 tests:
All 7 pass ✅
Backwards Compatibility