Skip to content

Cover the MCP transport's oversized-line bound #116

Description

@kikashy

Goal

Test what the stdio MCP server does with a JSON-RPC line larger than maxMessageBytes.

Why

internal/mcp/server.go bounds one line at 16 MiB and sizes the scanner buffer accordingly:

const maxMessageBytes = 16 * 1024 * 1024
scanner.Buffer(make([]byte, 0, 64*1024), maxMessageBytes)

maxMessageBytes appears nowhere in internal/mcp/server_test.go. A client that sends an oversized line gets whatever bufio.Scanner does at its limit, and nothing pins whether that is a clean refusal or a silently truncated read that the server then tries to parse.

That distinction matters here more than usual: a truncated line that happens to parse would be a different request than the one sent.

Scope

  • Change internal/mcp/server_test.go only.
  • Make the bound overridable in the test the way maxMatrixResultBytes already is (a var rather than a const) if that is the smallest change; otherwise construct an oversized line directly.
  • Cover:
    • a line over the bound;
    • whether the server emits a response, and if so which;
    • whether the stream continues or ends after it.
  • Assert what the server does today rather than changing it. If the current behaviour is judged wrong, say so in the pull request and stop there.

Acceptance criteria

  • An oversized line has a test that states the observed behaviour explicitly.
  • The test says whether a response is emitted and whether processing continues.
  • No production change unless the pull request argues for one separately.
  • env GO111MODULE=on go test ./internal/mcp and go test ./... pass.
  • Every commit includes a DCO sign-off created with git commit -s.

Contributor learning

Line-oriented transports, bufio.Scanner limits, and the difference between refusing an input and processing a prefix of it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    goPull requests that update go codegood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions