Fix MCP stdio servers that print logs or banners to stdout: wraps the server so only JSON-RPC reaches the client (no more handshake timeouts or 'Unexpected token' errors), plus a check for CI
A stdio MCP server talks JSON-RPC on stdout, so a single banner, log line or print() there breaks the stream: the client times out handshaking, shows Unexpected token errors, or drops the server. cleanpipe wraps any server so only JSON-RPC messages reach the client and everything else goes to stderr, without waiting for the server's maintainers to ship a fix.
pip install cleanpipe # or run it with no install: uvx cleanpipe -- No dependencies. Python 3.9+. Works with servers written in any language.
Put cleanpipe -- in front of the server command in your client's config.
[mcp_servers.gitnexus] command = "uvx" args = ["cleanpipe", "--", "npx", "-y", "gitnexus@latest", "mcp"] Claude Code:
claude mcp add gitnexus -- uvx cleanpipe -- npx -y gitnexus@latest mcp Claude Desktop, Cursor, VS Code and other JSON configs:
cleanpipe [--log FILE | --drop] [--quiet] -- [args...] Option What it does --log FILE Append the moved output to FILE instead of stderr. --drop Throw the moved output away. --quiet Don't print cleanpipe's own notes. The server's exit code is passed on, its stderr is left alone, and SIGTERM / Ctrl-C are passed to it. python -m cleanpipe works too.
cleanpipe reads the server's stdout one line at a time (MCP stdio is newline-delimited JSON):
A message is a JSON object with "jsonrpc": "2.0" and a method, or an id with a result or error, or a batch (array) of them. A JSON-RPC message nested inside a log object is not forwarded. What the client sends to the server is copied unchanged.
$ cleanpipe check -- python my_server.py handshake: ok, 4 tool(s) stdout noise: 2 line(s) that are not JSON-RPC (clients may fail the handshake; log to stderr instead): | Loading model weights... | [INFO] ready It starts the server, sends initialize, notifications/initialized and tools/list, keeps listening for half a second more, and exits 0 when stdout is clean, 1 when it found noise and 2 when the server didn't answer (--timeout S, default 10). --json prints the report as JSON for CI. From Python:
from cleanpipe import check, split report = check(["python", "my_server.py"]) assert report.clean, report.noise split(b'Loading...{"jsonrpc":"2.0","id":1,"result":{}}\n') # ([b'{"jsonrpc":"2.0","id":1,"result":{}}'], [b'Loading...']) Limits Only stdio servers. Streamable HTTP servers don't share a channel with their logs. A message pretty-printed over several lines is not put back together; each line is noise. No MCP SDK writes messages that way. Output the server buffers and only flushes at exit (Python's print() to a pipe without flush=True) can't be moved until it is flushed; it still never reaches the client. cleanpipe needs Python on the machine. With uvx it is fetched on first use. Some clients tolerate stray lines (the official Python SDK client logs them and carries on); others fail the handshake. cleanpipe is for the second kind and harmless with the first. The real fix is in the server: log to stderr. cleanpipe check in CI keeps it fixed. Why this exists The same bug is reported again and again, one server at a time, and users wait for each fix:
GitHub has over 70 such issues opened since September 2026 alone (titles with "stdout", "stdio" and "MCP"). The existing tools detect the problem; cleanpipe also works around it from the client side, so you can use the server today.
claude code claude desktop codex cursor handshake json-rpc logging mcp mcp proxy mcp server model context protocol parse error stdio stdout stdout pollution timed out handshaking unexpected token
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




