Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core-internal/src/shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ export abstract class Protocol<ContextT extends BaseContext> {
}

private async _oncancel(notification: CancelledNotification): Promise<void> {
if (!notification.params.requestId) {
if (notification.params.requestId === undefined) {
return;
}
// Handle request cancellation
Expand Down
46 changes: 46 additions & 0 deletions packages/core-internal/test/shared/protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,52 @@ describe('protocol tests', () => {
// Verify the request was aborted
expect(wasAborted).toBe(true);
});

test('should abort request handler for request id 0', async () => {
await protocol.connect(transport);

let handlerStarted!: () => void;
const started = new Promise<void>(resolve => {
handlerStarted = resolve;
});
let handlerAborted!: () => void;
const aborted = new Promise<void>(resolve => {
handlerAborted = resolve;
});
let abortReason: unknown;

protocol.setRequestHandler('ping', async (_request, ctx) => {
handlerStarted();
ctx.mcpReq.signal.addEventListener('abort', () => {
abortReason = ctx.mcpReq.signal.reason;
handlerAborted();
});
await aborted;
return {};
});

transport.onmessage?.({
jsonrpc: '2.0',
id: 0,
method: 'ping',
params: {}
});

await started;

transport.onmessage?.({
jsonrpc: '2.0',
method: 'notifications/cancelled',
params: {
requestId: 0,
reason: 'User cancelled'
}
});

await aborted;

expect(abortReason).toBe('User cancelled');
});
});

// Spec basic/patterns/cancellation §Transport-Specific (2026-07-28): on a
Expand Down
Loading