Skip to content

test_streaming_elicitation: use proper SSE instead of NDJSON - #392

Open
howardjohn wants to merge 2 commits into
modelcontextprotocol:mainfrom
howardjohn:server/proper-sse
Open

howardjohn wants to merge 2 commits into
modelcontextprotocol:mainfrom
howardjohn:server/proper-sse

Conversation

@howardjohn

Copy link
Copy Markdown

Motivation and Context

NDJSON is not acceptable in the spec.

Before:

$ curl -iN --max-time 5 -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2026-07-28' -H 'Mcp-Method: tools/call' -H 'Mcp-Name: test_streaming_elicitation' --data '{
      "jsonrpc":"2.0",
      "id":1,
      "method":"tools/call",
      "params":{
        "name":"test_streaming_elicitation",
        "arguments":{},
        "_meta":{
          "io.modelcontextprotocol/protocolVersion":"2026-07-28",
          "io.modelcontextprotocol/clientInfo":{"name":"conformance-client","version":"1.0.0"},
          "io.modelcontextprotocol/clientCapabilities":{}
        }
      }
    }' http://localhost:3001/mcp
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Mcp-Session-Id
Content-Type: application/json
Transfer-Encoding: chunked
Date: Mon, 06 Jul 2026 16:30:12 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"token-abc","total":100,"value":50}}
{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Streaming complete"}]}}

After:

$ curl -iN --max-time 5 -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2026-07-28' -H 'Mcp-Method: tools/call' -H 'Mcp-Name: test_streaming_elicitation' --data '{
      "jsonrpc":"2.0",
      "id":1,
      "method":"tools/call",
      "params":{
        "name":"test_streaming_elicitation",
        "arguments":{},
        "_meta":{
          "io.modelcontextprotocol/protocolVersion":"2026-07-28",
          "io.modelcontextprotocol/clientInfo":{"name":"conformance-client","version":"1.0.0"},
          "io.modelcontextprotocol/clientCapabilities":{}
        }
      }
    }' http://localhost:3001/mcp
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Mcp-Session-Id
Content-Type: text/event-stream
Cache-Control: no-cache
Date: Mon, 06 Jul 2026 16:32:49 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Transfer-Encoding: chunked

event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"token-abc","total":100,"value":50}}

event: message
data: {"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Streaming complete"}]}}

How Has This Been Tested?

curl above + running the server through a real client that rejected the invalid NDJSON

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

NDJSON is not acceptable in the spec.

Before:

```
$ curl -iN --max-time 5 -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2026-07-28' -H 'Mcp-Method: tools/call' -H 'Mcp-Name: test_streaming_elicitation' --data '{
      "jsonrpc":"2.0",
      "id":1,
      "method":"tools/call",
      "params":{
        "name":"test_streaming_elicitation",
        "arguments":{},
        "_meta":{
          "io.modelcontextprotocol/protocolVersion":"2026-07-28",
          "io.modelcontextprotocol/clientInfo":{"name":"conformance-client","version":"1.0.0"},
          "io.modelcontextprotocol/clientCapabilities":{}
        }
      }
    }' http://localhost:3001/mcp
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Mcp-Session-Id
Content-Type: application/json
Transfer-Encoding: chunked
Date: Mon, 06 Jul 2026 16:30:12 GMT
Connection: keep-alive
Keep-Alive: timeout=5

{"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"token-abc","total":100,"value":50}}
{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Streaming complete"}]}}
```

After:

```
$ curl -iN --max-time 5 -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -H 'MCP-Protocol-Version: 2026-07-28' -H 'Mcp-Method: tools/call' -H 'Mcp-Name: test_streaming_elicitation' --data '{
      "jsonrpc":"2.0",
      "id":1,
      "method":"tools/call",
      "params":{
        "name":"test_streaming_elicitation",
        "arguments":{},
        "_meta":{
          "io.modelcontextprotocol/protocolVersion":"2026-07-28",
          "io.modelcontextprotocol/clientInfo":{"name":"conformance-client","version":"1.0.0"},
          "io.modelcontextprotocol/clientCapabilities":{}
        }
      }
    }' http://localhost:3001/mcp
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Mcp-Session-Id
Content-Type: text/event-stream
Cache-Control: no-cache
Date: Mon, 06 Jul 2026 16:32:49 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Transfer-Encoding: chunked

event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"token-abc","total":100,"value":50}}

event: message
data: {"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Streaming complete"}]}}
```
@pcarleton

Copy link
Copy Markdown
Member

Backlog sweep: this needs a rebase now that #462 has landed (same area of everything-server.ts) before it can merge. If that's not something you have time for, no problem, say so and a maintainer may pick it up; otherwise I'll close it in two weeks if there's no update. Thanks for the contribution either way.

@YS-OH-CORE

Copy link
Copy Markdown

This PR also covers #531: its subscription changes frame both the acknowledgment and subsequent list-change notifications as SSE.

Following up on the rebase request, I prepared review/pr-392-sse-rebased-20260928 on main at 7169291, with the two original commits retaining John Howard's authorship and one separate regression-test commit. Full diff. The rebase preserves #462's normalizeStatelessResponse call around the generic streamed tools/call result.

The new regression tests launch the real everything-server and parse the stream with the existing eventsource-parser. They check the SSE media type and framing, acknowledgment before notifications, string subscription IDs, both list-change events, and tools-only/prompts-only filtering. For each filter case, the excluded mutation runs before the included mutation, so the included event provides an ordering barrier rather than relying on a quiet-time timeout. Mutation responses also assert resultType: "complete".

Version tested with the new tests Result
Unmodified main at 7169291 3 failed: application/json response
Header-only control, retaining the NDJSON body 3 failed: strict SSE parser rejects the body
Rebased branch at 376aec8 3 passed

GitHub CI passed: npm run check, npm run build, and all 625 tests across 48 files. This uses the repository's existing workflow on a verification branch; its only additional change is one push-trigger line. Source and tests are identical to the handoff branch. Local runs of the existing CLI against the example server also passed tools-call-simple-text (2/2 checks) and tools-list (4/4), using --spec-version 2026-07-28.

For completeness, the local full suite hit existing tsx IPC startup restrictions, so the full-suite result above comes from GitHub Actions. The fork's separate pkg.pr.new preview job failed because that app is not installed on the fork.

The branch is available for updating this PR. The added coverage targets subscription framing/filtering and retained response normalization; it does not establish complete protocol or cross-SDK conformance.

Rebase conflict resolution, regression tests, and this comment were produced with OpenAI ChatGPT coding tools.

Zero × Youngseok Oh

This branch has not been deployed

No deployments
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.

3 participants