Skip to content

node: serve MCP stateless - #540

Merged
aojea merged 4 commits into
google:mainfrom
kaisoz:kaisoz/node-mcp-stateless
Sep 29, 2026
Merged

aojea merged 4 commits into
google:mainfrom
kaisoz:kaisoz/node-mcp-stateless

Conversation

@kaisoz

@kaisoz kaisoz commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

MCP 2026-07-28 removed sessions, and the Go SDK serves that revision over HTTP only in stateless mode. Keeping the node's handler stateful had a second cost: the SDK refuses a legacy-version request that also carries the new per-request _meta protocol version tag, answering -32022 for a version it lists as supported. Newer agent CLIs send that tag on old-protocol sessions, so they could not use the node at all.

Nothing on the node used sessions: it sends no server-initiated notifications, makes no server-to-client requests, and the per-agent server is chosen per request, which stateless mode preserves. GET /mcp now answers 405, which the spec reserves for servers without a standalone stream.

  • internal/node/mcp.go: both handlers get StreamableHTTPOptions{Stateless: true}.
  • New test: an initialize with header 2025-11-25 plus the _meta tag is served and gets no Mcp-Session-Id; it fails with -32022 on the stateful handler.
  • mcp_test.go: GET /mcp expects 405.
  • node-api.md: the /mcp row says sessionless.

Verified with an agent CLI that sends the tag, against a node built from this branch.

MCP 2026-07-28 removed sessions, and the SDK serves it over HTTP only in stateless mode. A stateful handler also refused legacy-version clients that already send the per-request _meta protocol version tag, with -32022 for a version it lists as supported. Nothing on the node used sessions: no server-initiated notifications, no server-to-client requests, and the per-agent server is chosen per request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request configures the MCP server handlers to run in stateless mode, removing sessions and serving over HTTP only. It updates the associated tests and documentation to reflect this change, including asserting that GET requests on /mcp return a 405 Method Not Allowed status. A review comment recommends updating the newly added integration test to use http.NewRequestWithContext with a timeout context to prevent potential test hangs, in accordance with the repository style guide.

Comment thread internal/node/mcp_handlers_test.go Outdated
@aojea

aojea commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

I wonder if this can help us to simplify the code #387, I need to read more about MCP,.but seems this protocol does a lot of breaking changes

The stateless MCP handler has no standalone SSE stream, so GET /mcp is
405 Method Not Allowed instead of the 400 the stateful handler returned.
The unit test in internal/node was updated; this integration test still
expected 400 and failed in CI.
The bridge holds no per-caller state: one id space, no broadcast side.
A sessionless server does not mint or echo Mcp-Session-Id, and the
node's own /mcp handler no longer does. Nothing reads the constant
value it sent.
@aojea
aojea merged commit c916264 into google:main Sep 29, 2026
20 checks passed
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.

2 participants