Skip to content

Conversation

@gopinaath
Copy link

Summary

Increases the default JSON buffer size from 1MB to 10MB to accommodate modern MCP tools that may return large responses, and improves error messages to help users debug buffer overflow issues.

Problem

The current 1MB default buffer size is too small for real-world MCP tool responses. For example:

  • Puppeteer evaluate() can return 5-7MB when extracting computed CSS styles
  • Large file contents from Read tool
  • Complex DOM data from browser automation

This causes frequent crashes with buffer overflow errors, forcing users to modify installed packages directly.

Solution

  1. Increase default from 1MB to 10MB
  2. Add warning at 80% capacity to help users debug before hitting limit
  3. Improve error messages with actionable guidance
  4. Enhance documentation with examples

Testing

✅ Tested with real Puppeteer MCP scenarios (6.8 MB responses)
✅ Backward compatible
✅ No breaking changes

Impact

  • Better out-of-the-box experience with MCP tools
  • Clearer debugging with improved messages
  • Eliminates need for hackish workarounds

- Increase _DEFAULT_MAX_BUFFER_SIZE from 1MB to 10MB to accommodate modern
  MCP tools (e.g., Puppeteer evaluate() with DOM data, large file contents)
- Add warning when buffer reaches 80% capacity to help users debug before
  hitting the limit
- Improve error message with clearer guidance on increasing max_buffer_size
- Enhance documentation for ClaudeAgentOptions.max_buffer_size with examples

Background:
The 1MB default was too small for real-world MCP tool responses. Puppeteer's
evaluate() can return 5-7MB when extracting computed CSS styles from DOM
elements. This caused frequent crashes with 'JSON message exceeded maximum
buffer size' errors.

The max_buffer_size parameter was already configurable but:
1. The 1MB default was too conservative
2. Documentation didn't mention it clearly
3. Users resorted to hackish fixes (modifying site-packages directly)

This change makes the SDK work better out-of-the-box while maintaining
full backwards compatibility. Users can still override via ClaudeAgentOptions.
@gopinaath
Copy link
Author

Withdrawing this PR. After further consideration, the existing max_buffer_size parameter already provides the needed functionality. Users can configure it as needed for their use cases.

@gopinaath gopinaath closed this Dec 14, 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.

1 participant