Skip to content

bug: StreamableHTTP SSE parser fails when SSE event lacks "event:" field #369

@dracarys13

Description

@dracarys13

Description

The StreamableHTTP transport's SSE (Server-Sent Events) parser incorrectly requires both event: and data: fields to process an SSE event. According to the W3C SSE specification, the event: field is optional, and SSE events with only data: fields should be processed normally.

What happened:

  • Server responds with a valid SSE stream containing only data: field but no event: field
  • The SSE parser recognizes the data: field but doesn't trigger the event handler because no event: field was present
  • This results in unexpected nil response error and transport failure

What was expected:

  • SSE events with only data: fields should be processed normally
  • The event: field should be treated as optional

Code Sample

// Current problematic logic in readSSE function
if line == "" {
    // Empty line means end of event
    if event != "" && data != "" {  // ❌ This incorrectly requires both event AND data
        handler(event, data)
        event = ""
        data = ""
    }
    continue
}

Logs or Error Messages

========= SSE STREAM READING =========
Starting to read SSE stream...
SSE line received: data: {"jsonrpc":"2.0","id":1,"result":{...}}
  -> Parsed data: '{"jsonrpc":"2.0","id":1,"result":{...}}'
Empty line received (event boundary)
SSE stream reached EOF
========= SSE RESPONSE COMPLETED =========
Received nil response from SSE stream           # ❌ Event handler never called
transport error: unexpected nil response

Environment

  • Go version: 1.23
  • mcp-go version: latest
  • OS: macOS
  • Architecture: arm64

Metadata

Metadata

Assignees

No one assigned

    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