Skip to content

Proposal: make maxTokenSize of client transport SSE event handling configurable #726

Closed

Description

@dingliang88526-dev

mcp/event.go

func scanEvents(r io.Reader) iter.Seq2[Event, error] {
scanner := bufio.NewScanner(r)
const maxTokenSize = 1 * 1024 * 1024 // 1 MiB max line size
scanner.Buffer(nil, maxTokenSize)
...
if err := scanner.Err(); err != nil {
if errors.Is(err, bufio.ErrTooLong) {
err = fmt.Errorf("event exceeded max line length of %d", maxTokenSize)
}
if !yield(Event{}, err) {
return
}
}

}

why set a small and no-configurable limit?

Activity

  1. findleyr commented on Dec 15, 2025

    @findleyr
    Contributor

    Is this actually causing you problems? Our assumption is that the in-memory event store is not really practical for production applications.

    Of course, we could make this configurable, but need to understand the use-case first.

  2. zxxf18 commented on Dec 17, 2025

    @zxxf18
    Contributor

    I have also been affected by this 1MB limit. Here is my business scenario:

    I registered a tool used to list a resource containing a list of server endpoint information descriptions on the server side. Each resource entry includes descriptive information of varying lengths (some long, some short).

    When I enter a relatively large amount of server information (currently around 0.87MB), constructing the JSON-RPC response body—according to the protocol specification, where structured data is placed in StructuredContent and the JSON-serialized data is placed in Content—exceeds the 1MB limit.

    It is expected that my list will continue to grow, so this 1MB restriction does have a practical impact on me.

    Of course, I could implement alternative strategies at the business level, but I similarly believe that this limit should be exposed as a configurable option.

  3. zxxf18 commented on Dec 17, 2025

    @zxxf18
    Contributor

    My work involves life science research, particularly in the area of complex molecular analysis. These analyses often include sequences and corresponding analytical content that can easily exceed the 1 MB limit.

    As a result, I am currently forced to fork a copy of the code and modify the restriction myself in order to continue using it.

  4. findleyr commented on Dec 17, 2025

    @findleyr
    Contributor

    @jba @markus-kusano any objection to making this configurable?

    We did design the memory event store to be somewhat production grade (that's why we set a maximum cache size in the first place), so making this configurable seems OK to me.

  5. changed the title [-]sse event limit 1M and cann't changed[/-] [+]Proposal: make cache size of the MemoryEventStore configurable[/+] on Dec 17, 2025
  6. changed the title [-]Proposal: make cache size of the MemoryEventStore configurable[/-] [+]Proposal: make maxTokenSize of client transport SSE event handling configurable[/+] on Dec 23, 2025
  7. findleyr commented on Dec 23, 2025

    @findleyr
    Contributor

    In my haste, I misunderstood the report, FWIW: the issue is not about MemoryEventStore, but rather our event scanner.

    Agree that we should fix this. Probably 1MB is too small a default, as well.

  8. findleyr commented on Dec 23, 2025

    @findleyr
    Contributor

    Ok, now that I understand this, I'm not sure configuration is the right fix: servers can still return >1MB by using more than one line of SSE data. The line buffering is arbitrary, and I'd prefer not to expose this arbitrary buffering in our API.

    Can we just eliminate the buffering entirely?

  9. alexbumbacea commented on Dec 24, 2025

    @alexbumbacea
    Contributor

    Having some configurable limits it's a good practice, but the error should be properly surfaced to the caller (compared to the error returned now when buffer is exceeded). Having that in place would help avoid some scenarios where a faulty/abusive server sends very large responses and crash the client process (which might be a server interacting with multiple mcp servers).

    On the other side CommandTransport doesn't have that limitation (it reads the stream without a limit on the buffer) - but this could be argued that you're reading from executing another local command (which you maybe trust more than a remote server).

    Short version: having that limit is good, but it should be configurable and have better errors.

  10. findleyr commented on Dec 31, 2025

    @findleyr
    Contributor

    @alexbumbacea my major counterpoint to that argument is that there isn't really a limit that guards the in-memory buffer: if the message is split across multiple "data:" fields then the message can still be arbitrarily large.

    I think this needs more research. If none of the other SDKs have a buffer limit, I don't think we should either.

  11. alexbumbacea commented on Jan 3, 2026

    @alexbumbacea
    Contributor

    That's a fair point. I had a look over implementation of python, javascript and also mark3labs implementation and there is no such limitation.
    I will proceed with modifying the PR to remove the buffer size.

  12. added this to the v1.3.0 milestone on Jan 14, 2026
  13. maciej-kisiel commented on Jan 20, 2026

    @maciej-kisiel
    Contributor

    Hi @alexbumbacea, it's more than a week that the latest implementation proposal has been provided on the issue, I think we're good to go with accepting it and proceeding. Would you still like to contribute? I can assign you to the issue in that case.

  14. alexbumbacea commented on Jan 20, 2026

    @alexbumbacea
    Contributor

    @maciej-kisiel fell free to assign it to me. There is already a proposal in #734

  15. maciej-kisiel commented on Jan 21, 2026

    @maciej-kisiel
    Contributor

    Great, thanks!

  16. removed this from the v1.3.0 milestone on Jan 26, 2026
  17. maciej-kisiel commented on Feb 5, 2026

    @maciej-kisiel
    Contributor

    #734 was merged, closing this as done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions