Skip to content

Increasing Buffer Size in MCP stdio Transport #1143

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

Closed

Conversation

abhishekgahlot2
Copy link

@abhishekgahlot2 abhishekgahlot2 commented Jul 15, 2025

Fixes: #1141

When using the low-level Server API (mcp.server.lowlevel.Server) with stdio transport, sending progress notifications during request handling causes the server to hang indefinitely and never send the final response.

This issue was discovered while implementing an MCP server that returns large SQL query results and detailed analysis. The server would hang indefinitely when the output exceeded the OS pipe buffer limit.

Motivation and Context

Provides a fix for #1141

The current stdio transport implementation uses unbuffered memory object streams (buffer size 0), which can cause deadlocks when:

  1. Multiple messages are sent in quick succession
  2. Progress notifications are combined with tool responses

How Has This Been Tested?

Tested with code shared in original #1141 and fix works in it.

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Comment on lines +57 to +59
# FIXED: Changed from 0 to 10 to create buffered streams
read_stream_writer, read_stream = anyio.create_memory_object_stream(10)
write_stream, write_stream_reader = anyio.create_memory_object_stream(10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is exactly to not have this buffer.

@ihrpr
Copy link
Contributor

ihrpr commented Jul 15, 2025

Thank you for debugging this. Lets continue the discussion in the #1141. Not having a buffer is on purpose.

@ihrpr ihrpr closed this Jul 15, 2025
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.

Progress notifications cause server to hang on stdio transport
3 participants