Skip to content

fix: treat relatedRequestId 0 as present in debounce guard - #2658

Closed
juneja-varun wants to merge 2 commits into
modelcontextprotocol:mainfrom
juneja-varun:fix/related-request-id-zero-debounce
Closed

fix: treat relatedRequestId 0 as present in debounce guard#2658
juneja-varun wants to merge 2 commits into
modelcontextprotocol:mainfrom
juneja-varun:fix/related-request-id-zero-debounce

Conversation

@juneja-varun

Copy link
Copy Markdown

Problem

The debounce guard in _notificationViaCodec used a truthiness check on options?.relatedRequestId:

const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !options?.relatedRequestId;

0 is a valid JSON-RPC request id — and the first id a Protocol instance issues — but the truthy check treats it the same as "absent", so a notification related to request 0 gets silently coalesced by the debounce path even though related notifications are supposed to bypass debouncing.

Fix

Switch to an explicit presence check (!== undefined), matching how the rest of the codebase treats optional request ids.

Testing

Added a regression test mirroring the existing "should NOT debounce a notification that has a relatedRequestId" case, but with relatedRequestId: 0. pnpm --filter @modelcontextprotocol/core-internal exec vitest run test/shared/protocol.test.ts passes (40/40).

Fixes #2117

@juneja-varun
juneja-varun requested a review from a team as a code owner August 13, 2026 20:41
@changeset-bot

changeset-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a81a911

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

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/client Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/codemod 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 Aug 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: a81a911

The debounce guard used a truthiness check on options.relatedRequestId,
so a related request id of 0 (a valid JSON-RPC id, and the first id a
Protocol instance issues) was treated as absent and the notification
was wrongly debounced. Switch to an explicit undefined check.

Fixes modelcontextprotocol#2117
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.

relatedRequestId 0 is treated as absent by notification debounce guard

2 participants