Skip to content

fix(server): complete stdio listen subscriptions that honor nothing - #3200

Open
adityajai119 wants to merge 1 commit into
modelcontextprotocol:mainfrom
adityajai119:fix/stdio-listen-empty-honored
Open

adityajai119 wants to merge 1 commit into
modelcontextprotocol:mainfrom
adityajai119:fix/stdio-listen-empty-honored

Conversation

@adityajai119

Copy link
Copy Markdown

Motivation and Context

Fixes #3199.

On HTTP, createMcpHandler (createListenRouter) ends a subscriptions/listen stream right after sending notifications/subscriptions/acknowledged when honoredSubset(filter, capabilities) is empty, emitting the graceful-close SubscriptionsListenResult (resultType: 'complete') and releasing the subscription slot (#2651).

On stdio, serveStdio (StdioListenRouter.serve()) sent the empty acknowledgement and still stored this._subs.set(message.id, {}) without emitting SubscriptionsListenResult. Because listenFilterAccepts({}, event) is always false, an empty-honored subscription on stdio could never deliver any notification, left McpSubscription.closed pending indefinitely, and permanently occupied one of the connection's maxSubscriptions slots.

When honored is empty, StdioListenRouter.serve() now returns [ack, closeFrame] without registering the id in _subs, and serveStdio writes both frames in order so stdio matches HTTP. Subscriptions that honor at least one notification type are unchanged.

How Has This Been Tested?

  • Added two regression cases in packages/server/test/server/serveStdioListen.test.ts covering both serveStdio (immediate acknowledged + complete result, maxSubscriptions: 1 slot remains free for a subsequent honored subscription, no duplicate close frame on handle.close()) and StdioListenRouter.serve() directly; confirmed both fail on unmodified main and pass with this change.
  • Updated s2 in the handle.close() active-subscriptions test in serveStdioListen.test.ts to request an advertised capability (toolsListChanged) so both s1 and s2 remain active until teardown.
  • pnpm --filter @modelcontextprotocol/server test (55 files, 674 passed)
  • pnpm --filter @modelcontextprotocol/test-e2e exec vitest run scenarios/subscriptions.test.ts (16 passed)
  • pnpm --filter @modelcontextprotocol/test-integration test -- dualEraStdio (3 passed)
  • pnpm run lint:all, pnpm --filter @modelcontextprotocol/server check, and pnpm --filter @modelcontextprotocol/server build

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository style guidelines
  • New and existing tests pass locally
  • I have added tests that prove my fix is effective

AI-assisted: drafted with an AI coding agent; I reviewed the diff and ran the tests above locally.

@adityajai119
adityajai119 requested a review from a team as a code owner November 18, 2026 09:46
@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 30d17b6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/client Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/core-internal Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@3200

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@3200

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@3200

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@3200

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@3200

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@3200

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@3200

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@3200

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@3200

commit: 30d17b6

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Nov 19, 2026

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

v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v2] serveStdio holds subscriptions/listen open when capabilities honor nothing

1 participant