Skip to content

feat(server-initialize): add server-version-echo and server-version-negotiate checks - #608

Open
seedfunded wants to merge 1 commit into
modelcontextprotocol:mainfrom
seedfunded:feat/version-negotiation-conformance
Open

seedfunded wants to merge 1 commit into
modelcontextprotocol:mainfrom
seedfunded:feat/version-negotiation-conformance

Conversation

@seedfunded

Copy link
Copy Markdown

Summary

Updates #102 (server-side lifecycle version negotiation for stateful revisions 2025-06-18–2025-11-25, keeping the client-side MCP-Protocol-Version header check for a focused follow-up PR).

Following AGENTS.md ("fewer scenarios, more checks"), this extends the existing server-initialize scenario rather than adding a separate scenario:

  • server-version-echo (MUST / FAILURE): sends a raw initialize with ctx.specVersion and verifies the server responds with the exact same protocolVersion.
  • server-version-negotiate (MUST / FAILURE, WARNING for unrecognized future YYYY-MM-DD dates): sends a raw initialize with unsupported version 1999-01-01 (omitting MCP-Protocol-Version header so dual stateful/stateless servers route to initialize) and verifies the server responds with another supported protocolVersion instead of an HTTP/JSON-RPC error or echoing 1999-01-01.
  • Handles both application/json and text/event-stream responses via EventSourceParserStream, cancelling open SSE streams immediately after the first JSON-RPC response and sending DELETE to terminate any issued session.

Testing

  • Expanded src/scenarios/server/lifecycle.test.ts (12 unit tests covering JSON + SSE cancellation, mismatched version echo, echoed unsupported version, JSON-RPC error, unrecognized future date warning, invalid non-date version, and DELETE cleanup).
  • Added negative fixture examples/servers/typescript/version-negotiation-broken.ts and end-to-end negative test in src/scenarios/server/negative.test.ts proving server-version-negotiate emits FAILURE.
  • Verified npm run check, npm run build, and npm test (48 test files, 647 tests passing, including live everything-server).

…egotiate checks

Add lifecycle version negotiation checks to the existing `server-initialize`
scenario (following AGENTS.md "fewer scenarios, more checks") for stateful
initialize revisions (2025-06-18 through 2025-11-25):

- `server-version-echo`: sends a raw `initialize` request with `ctx.specVersion`
  and verifies the server responds with the exact same `protocolVersion` (MUST).
- `server-version-negotiate`: sends a raw `initialize` request with unsupported
  version `1999-01-01` (omitting `MCP-Protocol-Version` header) and verifies
  the server responds with a different supported `protocolVersion` rather than
  an HTTP/JSON-RPC error or echoing `1999-01-01` (MUST; WARNING for unrecognized
  future `YYYY-MM-DD` revisions to avoid false failures on newer spec releases).
- Handles both `application/json` and `text/event-stream` responses, cancelling
  open SSE streams immediately after the first JSON-RPC response and sending
  `DELETE` to clean up any issued session.
- Adds unit tests in `lifecycle.test.ts` and an end-to-end negative fixture
  (`examples/servers/typescript/version-negotiation-broken.ts`) verified in
  `negative.test.ts`.

Updates modelcontextprotocol#102

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.

1 participant