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
44 changes: 44 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,50 @@ describe('protocol tests', () => {
// Verify the request was aborted
expect(wasAborted).toBe(true);
});

test('should handle notifications/cancelled for request ID 0', async () => {
await protocol.connect(transport);

// Set up a request handler that checks if it was aborted
let wasAborted = false;
protocol.setRequestHandler('ping', async (_request, ctx) => {
await new Promise(resolve => setTimeout(resolve, 100));
wasAborted = ctx.mcpReq.signal.aborted;
return {};
});

// Simulate an incoming request with ID 0 (a valid JSON-RPC id)
const requestId = 0;
if (transport.onmessage) {
transport.onmessage({
jsonrpc: '2.0',
id: requestId,
method: 'ping',
params: {}
});
}

// Wait a bit for the handler to start
await new Promise(resolve => setTimeout(resolve, 10));

// Send cancellation notification with requestId 0
if (transport.onmessage) {
transport.onmessage({
jsonrpc: '2.0',
method: 'notifications/cancelled',
params: {
requestId: requestId,
reason: 'User cancelled'
}
});
}

// Wait for the handler to complete
await new Promise(resolve => setTimeout(resolve, 150));

// Verify the request was aborted even with ID 0
expect(wasAborted).toBe(true);
});
});

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