Skip to content

mcp: do not broadcast list changes to sessions without a version - #1553

Merged
guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
luiacuaniello:fix-listen-unrequested-notifications
Dec 1, 2026
Merged

guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
luiacuaniello:fix-listen-unrequested-notifications

Conversation

@luiacuaniello

Copy link
Copy Markdown
Contributor

Fixes #1551.

notifySessions treated a session with no recorded protocol version as legacy and sent it list-changed broadcasts. Stateless 2026-07-28 requests have such a session until handle reads the version from _meta, so a tool change in that window could land on a subscriptions/listen stream before the ack.

Now only sessions whose recorded version is older than 2026-07-28 get the broadcast. I left ephemeralConnectOpts alone, since TestEphemeralConnectOpts expects no synthetic state for new-protocol requests. Legacy sessions that haven't initialized are skipped too, which is fine: they haven't listed anything yet.

TestListChangedSkipsSessionsWithoutVersion fails without the change. The repro from the issue goes from 80 bad streams out of 28368 on main to 0 out of 26723.

go test ./..., -race on mcp and auth, vet, staticcheck v0.8.2 and the conformance suites pass, with the same conformance numbers as main.

Found and written with help from Claude Code.

Server.notifySessions sent list-changed notifications to every session
that negotiatedLegacyProtocol reports as legacy, which includes a
session with no recorded protocol version. A stateless 2026-07-28
request gets such a session: its version is recorded only when the
request is handled. A tool, prompt or resource change in between sent
the session a legacy notification, and the stateless connection wrote
it on its only stream. When the request was subscriptions/listen, the
client received a notification it did not ask for, without a
subscription ID and before notifications/subscriptions/acknowledged.

Broadcast only to sessions whose recorded version predates 2026-07-28.
A legacy session before initialize is skipped as well; it has listed
nothing yet.

Fixes modelcontextprotocol#1551
@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Nov 27, 2026
@github-actions github-actions Bot closed this Nov 27, 2026
@github-actions github-actions Bot reopened this Dec 1, 2026
@github-actions github-actions Bot removed the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Dec 1, 2026
@guglielmo-san
guglielmo-san merged commit d445662 into modelcontextprotocol:main Dec 1, 2026
9 checks passed
Tangerg added a commit to Tangerg/go-sdk that referenced this pull request Dec 2, 2026
Brings the fork up to upstream main at 723d70e, which is v1.9.0 plus
fourteen later commits. Upstream changes: modelcontextprotocol#1238, modelcontextprotocol#1511, modelcontextprotocol#1515, modelcontextprotocol#1517,
modelcontextprotocol#1521, modelcontextprotocol#1523, modelcontextprotocol#1524, modelcontextprotocol#1527, modelcontextprotocol#1533, modelcontextprotocol#1537, modelcontextprotocol#1539, modelcontextprotocol#1540, modelcontextprotocol#1544, modelcontextprotocol#1547,
modelcontextprotocol#1549, modelcontextprotocol#1550, modelcontextprotocol#1553, modelcontextprotocol#1554, modelcontextprotocol#1558, modelcontextprotocol#1560, modelcontextprotocol#1561, modelcontextprotocol#1562.

Fork-side adaptations:

- internal/jsonrpc2: the -32600 reply to a duplicate in-flight ID
  (modelcontextprotocol#1550) is written off the read loop and holds its admission slot
  until written, like every other reply under MaxIncomingRequests.
- mcp: ClientSession.initialize takes the session state lock that
  upstream added, and still projects the negotiated version to the
  connection.
- mcp: the fork's copies of hintomitempty, nowrapinvalidparams and
  nomethodnotfoundcodeinerror go away with upstream's removal (modelcontextprotocol#1533).
- extensions/skills: reads the protocol version from the fork's
  json.RawMessage Meta.
- Tests: the duplicate-ID admission test drains the new reply, and the
  client cancellation test runs on 2025-11-25 only, because 2026-07-28
  clients reject every standalone server request (modelcontextprotocol#1537, modelcontextprotocol#1540, modelcontextprotocol#1554).
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.

mcp: stateless subscriptions/listen stream can start with an unrequested tools/list_changed

2 participants