Skip to content

fix(mcp): consume self-cancelling JSON-RPC batches - #3076

Open
fahreddinozcan wants to merge 1 commit into
masterfrom
codex/ctx7-2472-reject-self-cancelling-batches
Open

fix(mcp): consume self-cancelling JSON-RPC batches#3076
fahreddinozcan wants to merge 1 commit into
masterfrom
codex/ctx7-2472-reject-self-cancelling-batches

Conversation

@fahreddinozcan

@fahreddinozcan fahreddinozcan commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • detect request/cancellation pairs contained in the same JSON-RPC batch before SDK dispatch
  • consume both elements so cancelled tools never start and the SDK transport has no orphaned request ID
  • return HTTP 202 with an empty body when the entire batch is cancelled
  • preserve responses for uncancelled requests in mixed batches and preserve cancellation notifications targeting IDs outside the batch

Root cause

@modelcontextprotocol/server@2.0.0 correctly suppresses a response after notifications/cancelled, but its legacy stateless HTTP transport closes a batch stream only after its response map contains every request ID registered for that stream. Cancellation does not remove or settle the mapped ID, so a self-cancelling batch stays open indefinitely.

The application-side filter preserves MCP cancellation semantics: cancelled requests produce no response, do no tool/backend work, and do not enter the SDK transport response accounting.

This closes Cobalt finding PT38659_18 (CWE-400).

Linear: CTX7-2472

Verification

  • SDK-only reproducer: ordinary request closed with 100 bytes; self-cancelling batch remained open with zero bytes after 500 ms
  • patched Context7 localhost retest: time=0.008391s http=202 bytes=0 exit=0
  • pnpm --dir packages/mcp typecheck
  • pnpm --dir packages/mcp lint:check
  • pnpm --dir packages/mcp exec vitest run --exclude "dist/**" (82 tests)
  • Prettier and git diff --check

@linear-code

linear-code Bot commented Aug 25, 2026

Copy link
Copy Markdown

CTX7-2472

@context7

context7 Bot commented Aug 25, 2026

Copy link
Copy Markdown

Docs7 preview for context7.com

Status Commit Updated (UTC)
✅ Ready (visit preview) 2b8f727 2026-08-25 09:18

@fahreddinozcan
fahreddinozcan force-pushed the codex/ctx7-2472-reject-self-cancelling-batches branch from 1c5a1fb to 2b8f727 Compare August 25, 2026 09:17
@fahreddinozcan fahreddinozcan changed the title fix(mcp): reject self-cancelling JSON-RPC batches fix(mcp): consume self-cancelling JSON-RPC batches Aug 25, 2026
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.

1 participant