Skip to content

mcp: fail connect when subscriptions listen is rejected - #1170

Open
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:audit/request-lifecycle-audit
Open

mcp: fail connect when subscriptions listen is rejected#1170
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:audit/request-lifecycle-audit

Conversation

@jstar0

@jstar0 jstar0 commented Aug 13, 2026

Copy link
Copy Markdown

Fixes #1169

When a v2026-07-28 streamable HTTP client installs notification handlers, Client.Connect opens subscriptions/listen after server/discover. If that listen call is rejected immediately, the client previously ignored the response and returned a session even though subscriptions were not active.

This change lets the listen helper observe an immediate terminal response before detaching the long-lived call. Rejections now propagate through Connect, and the partially opened session is closed on that connect error.

Verification:

  • Added TestStreamableClientConnect_SubscriptionsListenError; the test fails on origin/main because Connect succeeds after the rejected listen request
  • go test ./mcp -run 'TestStreamableClientConnect_SubscriptionsListenError|TestStreamableClientConnect_DiscoverSuccess|TestSubscriptionsListen_Streamable|TestResourceSubscriptions_Streamable|TestSubscriptionsListen_InMemory|TestResourceSubscriptions_InMemory' -count=1 -v passed
  • go test ./... currently fails in this local environment only on the existing localhost protection cases where evil.com resolves to 0.0.0.0; the same two subtests fail on clean origin/main: TestSSELocalhostProtection/0.0.0.0_via_localhost_rejects_evil.com and TestStreamableLocalhostProtection/0.0.0.0_via_localhost_rejects_evil.com

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: Client.Connect succeeds after subscriptions/listen is rejected

1 participant