Skip to content

fix: handle cancellation for request id zero#2138

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

fix: handle cancellation for request id zero#2138
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/cancel-request-id-zero

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • preserve requestId: 0 when handling notifications/cancelled
  • add a regression test that cancels an inbound request whose JSON-RPC id is 0

Fixes #2115.

Validation

  • pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "notifications/cancelled behavior"
  • pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts
  • pnpm --filter @modelcontextprotocol/core run typecheck
  • pnpm --filter @modelcontextprotocol/core run lint
  • pre-push hook: pnpm -r typecheck, pnpm -r build, pnpm sync:snippets --check, pnpm -r lint
  • git diff --check

@he-yufeng he-yufeng requested a review from a team as a code owner May 21, 2026 07:47
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: 553b6b6

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 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
Copy link
Copy Markdown

pkg-pr-new Bot commented May 21, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@2138

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/codemod@2138

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@2138

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@2138

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/fastify@2138

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@2138

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@2138

commit: 553b6b6

@he-yufeng he-yufeng force-pushed the fix/cancel-request-id-zero branch from 0d326bf to a3d7042 Compare May 24, 2026 10:34
@he-yufeng
Copy link
Copy Markdown
Author

Rebased this on the latest main and re-ran the focused/core checks locally:

  • pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "requestId 0"
  • pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts
  • pnpm --filter @modelcontextprotocol/core run typecheck
  • pnpm --filter @modelcontextprotocol/core run lint
  • git diff --check upstream/main..HEAD
  • pre-push hook: pnpm -r typecheck, pnpm -r build, pnpm sync:snippets --check, pnpm -r lint

@he-yufeng he-yufeng force-pushed the fix/cancel-request-id-zero branch from a3d7042 to 553b6b6 Compare May 27, 2026 10:45
@he-yufeng
Copy link
Copy Markdown
Author

Added the @modelcontextprotocol/core patch changeset and force-pushed 553b6b6. Local validation: changeset status shows @modelcontextprotocol/core patch; focused requestId 0 test passed; full core protocol.test.ts passed with 151 tests; core typecheck and lint passed; git diff --check passed. Pre-push typecheck, build, and lint also passed.

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.

requestId 0 is silently dropped by _oncancel, making the first request from every Protocol uncancellable

1 participant