feat: support logging to stderr in Jupyter Notebook environments (#156)#1706
Closed
dgenio wants to merge 9 commits intomodelcontextprotocol:mainfrom
Closed
feat: support logging to stderr in Jupyter Notebook environments (#156)#1706dgenio wants to merge 9 commits intomodelcontextprotocol:mainfrom
dgenio wants to merge 9 commits intomodelcontextprotocol:mainfrom
Conversation
- Add _is_jupyter_notebook() to detect Jupyter/IPython environments - Add _print_stderr() to handle stderr output with IPython display support
- Mock builtins.__import__ instead of patching IPython.display directly - Handle 'from IPython.display import HTML, display' import pattern - Tests now work without IPython installed in test environment
- Add test for _is_jupyter_notebook with valid IPython instances - Add test for stderr_reader exception handling - Improve test coverage to reach 100%
- Store original __import__ before patching to avoid recursion - Fix test_stderr_reader_no_stderr to not print to stdout - Apply ruff formatting fixes
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 #156 - Adds support for displaying stderr output in Jupyter Notebook environments.
Changes
IPython.get_ipython()FallbackProcessto wrap stderr in async-compatible streamsDesign Decisions
errlogparameter is kept but behavior adapts based on environmentTesting
Behavior
errlogstream (defaults tosys.stderr)This enables proper debugging of MCP servers in Jupyter notebook environments, addressing the issue where server crashes or command errors were invisible.