-
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
Open
gajzzs
wants to merge
8
commits into
CoplayDev:main
Choose a base branch
from
gajzzs:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−3
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d18bf91
Change fastmcp dependency version to 2.12.5
gajzzs b9c7365
Update fastmcp dependency version constraint
gajzzs aa81ee6
Fix issue https://github.com/CoplayDev/unity-mcp/issues/430
gajzzs 7fefa18
Merge branch 'CoplayDev:main' into main
gajzzs 3f88185
Merge branch 'CoplayDev:main' into main
gajzzs 0f89329
Changes https://github.com/CoplayDev/unity-mcp/pull/457\#issuecomment…
gajzzs 816c089
Merge branch 'CoplayDev:main' into main
gajzzs 2c09a78
docs(utils): enhance CRStripper docstrings and type hinting
gajzzs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| """ | ||
| SUMMARY: Utils package initialization. | ||
| """ | ||
| from .cr_stripper import CRStripper | ||
|
|
||
| __all__ = ["CRStripper"] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """ | ||
| Provides a utility to strip carriage return characters from output streams. | ||
|
|
||
| This module implements the `CRStripper` class, which wraps a file-like object | ||
| to filter out carriage return (\r) characters during write operations. | ||
|
|
||
| Usage of this wrapper is essential for Model Context Protocol (MCP) communication | ||
| over stdio, as it ensures consistent line endings and safeguards against | ||
| protocol errors, particularly in Windows environments. | ||
| """ | ||
|
|
||
| from typing import Any, BinaryIO | ||
|
|
||
| class CRStripper: | ||
| """ | ||
| A file-like wrapper that strips carriage return (\r) characters from data before writing. | ||
|
|
||
| This class intercepts write calls to the underlying stream and removes all | ||
| instances of '\r', ensuring that output is clean and consistent across | ||
| different platforms. | ||
| """ | ||
| def __init__(self, stream: BinaryIO) -> None: | ||
| """ | ||
| Initialize the stripper with an underlying stream. | ||
|
|
||
| Args: | ||
| stream (BinaryIO): The underlying file-like object or buffer to wrap (e.g., sys.stdout.buffer). | ||
| """ | ||
| self._stream = stream | ||
|
|
||
| def write(self, data: bytes | bytearray | str) -> int: | ||
| """ | ||
| Write data to the underlying stream after stripping all carriage return characters. | ||
|
|
||
| Args: | ||
| data (bytes | bytearray | str): The data to be written. | ||
|
|
||
| Returns: | ||
| int: The number of bytes or characters processed (matches input length if successful). | ||
| """ | ||
| if isinstance(data, (bytes, bytearray)): | ||
| stripped = data.replace(b'\r', b'') | ||
| written = self._stream.write(stripped) | ||
| elif isinstance(data, str): | ||
| stripped = data.replace('\r', '') | ||
| written = self._stream.write(stripped) | ||
| else: | ||
| return self._stream.write(data) | ||
|
|
||
| # If the underlying stream wrote all the stripped data, we report | ||
| # that we wrote all the ORIGINAL data. | ||
| # This prevents callers (like TextIOWrapper) from seeing a "partial write" | ||
| # mismatch when we intentionally removed characters. | ||
| if written == len(stripped): | ||
| return len(data) | ||
|
|
||
| return written | ||
|
|
||
| def flush(self) -> None: | ||
| """ | ||
| Flush the underlying stream. | ||
| """ | ||
| return self._stream.flush() | ||
|
|
||
| def __getattr__(self, name: str) -> Any: | ||
| """ | ||
| Delegate any attribute or method access to the underlying stream. | ||
|
|
||
| Args: | ||
| name (str): The name of the attribute to access. | ||
|
|
||
| Returns: | ||
| Any: The attribute or method from the wrapped stream. | ||
| """ | ||
| return getattr(self._stream, name) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.