Skip to content

fix: handle cancelled request id zero#2479

Open
chenlichao wants to merge 1 commit into
modelcontextprotocol:mainfrom
chenlichao:fix/cancel-request-id-zero-20260711100440
Open

fix: handle cancelled request id zero#2479
chenlichao wants to merge 1 commit into
modelcontextprotocol:mainfrom
chenlichao:fix/cancel-request-id-zero-20260711100440

Conversation

@chenlichao

Copy link
Copy Markdown

Summary

  • Treat requestId: 0 as a present cancellation target instead of returning early.
  • Add a regression test covering notifications/cancelled for in-flight request id 0.

Fixes #2283.

Why this helps

0 is a valid JSON-RPC request id, and the SDK's own per-instance request counter starts at zero. The previous truthiness guard ignored cancellations for that first request, leaving its handler running.

Test Plan

  • pnpm --filter @modelcontextprotocol/core-internal test -- test/shared/protocol.test.ts -t "request id 0"
  • pnpm --filter @modelcontextprotocol/core-internal lint -- test/shared/protocol.test.ts src/shared/protocol.ts
  • pnpm exec prettier --check packages/core-internal/src/shared/protocol.ts packages/core-internal/test/shared/protocol.test.ts
  • git diff --check
  • pre-push hook also ran pnpm -r typecheck, pnpm -r build, and pnpm -r lint

@chenlichao chenlichao requested a review from a team as a code owner July 11, 2026 17:05
@changeset-bot

changeset-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 19c8c44

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 19c8c44

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.

notifications/cancelled is ignored for request id 0

1 participant