Skip to content

fix: bound stdio JSON-RPC message size#985

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/stdio-max-message-bytes
Open

fix: bound stdio JSON-RPC message size#985
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/stdio-max-message-bytes

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Fixes #984.

Summary

Adds an optional MaxMessageBytes limit for newline-delimited JSON-RPC transports:

  • CommandTransport.MaxMessageBytes bounds frames read from child process stdout.
  • StdioTransport.MaxMessageBytes and IOTransport.MaxMessageBytes expose the same behavior for server-side stdio and custom IO transports.
  • The IO reader now frames input by NDJSON line, preserves the existing trailing-data rejection, and rejects oversized frames before JSON-RPC decoding.

Validation

  • go test ./mcp -run "TestIOConnRead|TestIOConnReadMaxMessageBytes|TestBatchFraming"
  • go test ./mcp -run TestCommandTransportTerminateDuration
  • go test ./...
  • go vet ./...
  • gofmt -l .
  • go run honnef.co/go/tools/cmd/staticcheck@v0.6.1 ./...
  • git diff --check -- mcp\transport.go mcp\cmd.go mcp\transport_test.go

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.

Expose max JSON-RPC frame/message size for stdio transports

1 participant