Skip to content

fix: correct stdout buffering issues in spawned processes #739

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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nsheaps
Copy link

@nsheaps nsheaps commented Aug 21, 2025

Adds stdio inheritance to prevent Node.js from dropping console output after 8192 characters due to premature stdout pipe closure before output finishes flushing. Without this, calls like this would truncate after 8192 characters, leading to broken json output:

npx --node-options=--inspect -y @modelcontextprotocol/inspector --cli --config .mcp.json --server notion --method tools/list

It would normally print as much would fit in the default buffer of the child_process (controlled by maxBuffer, which defaults to 8192 characters), and would fail to print the rest because the node child_process buffer was at it's limit. When the process is spawn instead of execd, the data buffer passing is all that sends stuff back and forth, unless you set stdio to inherit in which case console.out in the child process would print directly to stdout instead of to a pipe. Since the output isn't needed, we don't need to keep it as a pipe.

You can see this in their openapi spec, which powers their MCP server.

Validated with:

npm run prettier-fix && npm run build && npm run test && npm run test-cli && npm run test:e2e 
npm -w cli exec -- node build/cli.js --cli --config ~/path/to/.mcp.json --server notion --method tools/list
npx --from 'github:nsheaps/inspector' --cli --config ~/path/to/.mcp.json --server notion --method tools/list

Prior to the change, running the second command would truncate the response

# notion mcp server
    "notion": {
      "//": "doppler needs to expose OPENAPI_MCP_HEADERS (and NOTION_TOKEN within it)",
      "command": "bash",
      "args": [
        "-c",
        "doppler run -p 'mcp' -c \"user_${MCP_USER:-$USER}\" -- npx -y @notionhq/notion-mcp-server"
      ]
    },

Adds stdio inheritance to prevent Node.js from dropping console output after 8192 characters due to premature stdout pipe closure before output finishes flushing. Without this, calls like this would truncate after 8192 characters, leading to broken json output:

```
npx --node-options=--inspect -y @modelcontextprotocol/inspector --cli --config .mcp.json --server notion --method tools/list
```

```
# notion mcp server
    "notion": {
      "//": "doppler needs to expose OPENAPI_MCP_HEADERS (and NOTION_TOKEN within it)",
      "command": "bash",
      "args": [
        "-c",
        "doppler run -p 'mcp' -c \"user_${MCP_USER:-$USER}\" -- npx -y @notionhq/notion-mcp-server"
      ]
    },
```

You can see this in their [openapi spec](https://github.com/makenotion/notion-mcp-server/blob/main/scripts/notion-openapi.json), which powers their MCP server.
@nsheaps nsheaps marked this pull request as ready for review August 21, 2025 01:23
@nsheaps
Copy link
Author

nsheaps commented Aug 21, 2025

You can see @ashwin-ant made a similar fix here: https://github.com/anthropics/claude-code-action/pull/473/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant