Skip to content

mcp: reject resource subscriptions during close - #1172

Open
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/resource-subscribe-close
Open

mcp: reject resource subscriptions during close#1172
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/resource-subscribe-close

Conversation

@jstar0

@jstar0 jstar0 commented Aug 13, 2026

Copy link
Copy Markdown

Fixes #1171.

This change makes SEP-2575 resource subscription startup follow the same close semantics as other client sends:

  • ClientSession.Close marks the session as closing before cancelling existing listen streams.
  • ClientSession.Subscribe rejects calls after closing begins.
  • failed subscriptions/listen startup rolls back the resourceSubs entry it just registered.
  • subscriptions/listen now reports immediate jsonrpc2 close errors back to the caller instead of silently discarding them.

Tests:

  • go test ./mcp -run 'TestResourceSubscriptions_(SubscribeAfterCloseFails|SubscribeConcurrentCloseFails|Subscribe_Idempotent|InMemory|MultipleURIs)$'
  • go test ./internal/jsonrpc2 ./mcp -run 'TestSubscriptionsListen|TestResourceSubscriptions'
  • go test -race ./mcp -run 'TestResourceSubscriptions_SubscribeConcurrentCloseFails$'
  • go test ./... (fails only TestSSELocalhostProtection/0.0.0.0_via_localhost_rejects_evil.com and TestStreamableLocalhostProtection/0.0.0.0_via_localhost_rejects_evil.com; both got HTTP 200 instead of the expected 403, and the same failures reproduce when those tests are run directly)

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.

ClientSession.Subscribe can silently succeed while the session is closing

1 participant