Skip to main content
Defined in: server/middleware.ts:338 Intercepts notifications/cancelled from the client and aborts the matching in-flight handler via Promise.race + AbortController. KNOWN GAP (2026-07-28): this only covers legacy (2025-era) and stdio cancellation. On a modern Streamable HTTP connection, the SDK signals cancellation by closing the request’s response stream rather than sending notifications/cancelled — the client is correctly told the call was cancelled either way, but a handler registered here keeps running server-side to completion on the modern path, since this middleware never observes that stream closure. The SDK exposes it per-request as ctx.mcpReq.signal (a BaseContext field, present on every era) — unifying this middleware with that signal (so long-running handlers actually stop executing on both eras) is tracked as follow-up work, not yet implemented here.

Implements

Constructors

Constructor

Returns

CancellationMiddleware

Methods

onRequest()

Defined in: server/middleware.ts:348

Parameters

ctx
MiddlewareContext
next
Next

Returns

Promise<unknown>

Implementation of

Middleware.onRequest

setup()

Defined in: server/middleware.ts:341 Called once per Server instance. Use to register notification handlers or other server-level setup.

Parameters

server
Server

Returns

void

Implementation of

Middleware.setup