-
Notifications
You must be signed in to change notification settings - Fork 577
Fix Error: calling "initialize": invalid trailing data at the end of stream. #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughOn Windows, stdout is switched to binary mode and replaced with a CRStripper-wrapped TextIOWrapper (line-buffered, newline='\n'); FastMCP started over stdio runs inside a redirected stdout context so all stdout writes have CR (\r) characters removed and use LF newlines. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)Server/src/main.py (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@dsarno is there any issue in this PR ? |
|
Thanks for your help with this @gajzzs, from discussions on the issue and this PR. Can you help me fully understand your changes and answer these questions? msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)Why does Wouldn't this only need to be applied for stdio mode, and not HTTP mode? Is it possible to apply this fix w/o globally rewriting Can you do the byte replacement on For this fix to work, we need to patch stdout before running |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
Server/src/utils/cr_stripper.py (1)
3-5: Consider adding type hints and a docstring.While the implementation is functionally correct, adding type hints and a proper docstring would improve maintainability.
🔎 View suggested improvements:
+from typing import Any, BinaryIO, TextIO, Union + # This utility strips carriage return characters (\r) from bytes or strings class CRStripper: + """ + Stream wrapper that removes carriage return (CR) characters from output. + + Wraps any stream and strips \\r characters from both bytes and string data + before writing to the underlying stream. + """ - def __init__(self, stream): + def __init__(self, stream: Union[BinaryIO, TextIO]) -> None: self._stream = stream
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
Server/src/main.py(2 hunks)Server/src/utils/__init__.py(1 hunks)Server/src/utils/cr_stripper.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- Server/src/main.py
🧰 Additional context used
🧬 Code graph analysis (1)
Server/src/utils/__init__.py (1)
Server/src/utils/cr_stripper.py (1)
CRStripper(3-18)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Sourcery review
🔇 Additional comments (3)
Server/src/utils/__init__.py (1)
1-6: LGTM! Clean package initialization.The package structure follows Python conventions with appropriate exports via
__all__.Server/src/utils/cr_stripper.py (2)
14-15: LGTM!The
flushmethod correctly delegates to the underlying stream.
17-18: The__getattr__delegation is well-suited for this use case. The implementation wrapssys.stdout.buffer(a standardBufferedWriter) rather thansys.stdout, and only explicitly implementswrite()andflush()—the critical methods for MCP's stdio protocol. Other buffer methods delegate cleanly via__getattr__to the underlyingBufferedWriter, which has standard io module interfaces. Type checking is not a concern sinceCRStripperis wrapped insideTextIOWrapper, which is the actual stream interface. This approach already addresses the maintainer's compatibility question by operating on the buffer layer rather than replacing the entire stream object.
|
Looking good @gajzzs. I left one more comment style wise. The only thing pending after those changes would be other people testing, just to ensure it doesn't break other clients. I'll ask some in the community |
- Fix Return value to reflect input length after character removal.
#430
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.