Skip to content

fix: handle cancelled request id zero#2479

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

fix: handle cancelled request id zero#2479
chenlichao wants to merge 2 commits 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

🦋 Changeset detected

Latest commit: d5e7657

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

This PR includes changesets to release 1 package
Name Type
@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 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: d5e7657

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