Skip to content

fix: handle notifications/cancelled for valid request ID 0#2502

Open
nankingjing wants to merge 1 commit into
modelcontextprotocol:mainfrom
nankingjing:fix/cancelled-notification-id-zero
Open

fix: handle notifications/cancelled for valid request ID 0#2502
nankingjing wants to merge 1 commit into
modelcontextprotocol:mainfrom
nankingjing:fix/cancelled-notification-id-zero

Conversation

@nankingjing

Copy link
Copy Markdown

Fixes #2283

JSON-RPC allows request ID 0 as a valid identifier, but the SDK's cancelled notification handler treats it as falsy and silently drops the cancellation. This means agent orchestrators cannot cancel tool calls numbered with ID 0.

Fix: Replace truthiness check with explicit undefined check so that 0 is treated as a valid request ID for cancellation.

Changes:

  • packages/core-internal/src/shared/protocol.ts: Change !notification.params.requestId to notification.params.requestId === undefined in _oncancel
  • packages/core-internal/test/shared/protocol.test.ts: Add test verifying cancellation works for request ID 0

JSON-RPC allows 0 as a valid request id, but Protocol._oncancel used a
truthiness check on params.requestId, so a cancellation targeting
request id 0 was silently dropped and the in-flight handler kept
running. Replace the truthiness check with an explicit undefined check.

Fixes modelcontextprotocol#2283
@nankingjing nankingjing requested a review from a team as a code owner July 15, 2026 15:41
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e2c7b1b

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 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: e2c7b1b

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