Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changeset/calm-taxis-cancel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modelcontextprotocol/core': patch
---

Prevent legacy cancellation notifications from inheriting request resumption options.
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 @@ -1461,7 +1461,7 @@ export abstract class Protocol<ContextT extends BaseContext> {
reason: String(reason)
}
}),
{ relatedRequestId, resumptionToken, onresumptiontoken }
{ relatedRequestId }
)
.catch(error => this._onerror(new Error(`Failed to send cancellation: ${error}`)));
} else {
Expand Down
25 changes: 25 additions & 0 deletions packages/core-internal/test/shared/protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,11 @@ describe('protocol tests', () => {
class PerRequestStreamTransport extends MockTransport {
readonly hasPerRequestStream = true;
sent: JSONRPCMessage[] = [];
sentCalls: { message: JSONRPCMessage; options?: TransportSendOptions }[] = [];
lastRequestSignal: AbortSignal | undefined;
override async send(message: JSONRPCMessage, options?: TransportSendOptions): Promise<void> {
this.sent.push(message);
this.sentCalls.push({ message, options });
this.lastRequestSignal = options?.requestSignal;
}
}
Expand Down Expand Up @@ -899,6 +901,29 @@ describe('protocol tests', () => {
expect(cancelledSent(tx.sent)).toHaveLength(1);
});

test('legacy era: cancellation does not inherit request resumption options', async () => {
const tx = new PerRequestStreamTransport();
const proto = createTestProtocol();
await proto.connect(tx);
setNegotiatedProtocolVersion(proto, '2025-11-25');

const ac = new AbortController();
const pending = testRequest(proto, { method: 'example', params: {} }, z.object({}), {
signal: ac.signal,
relatedRequestId: 'parent-request',
resumptionToken: 'resume-token',
onresumptiontoken: vi.fn()
});

ac.abort('user cancel');
await expect(pending).rejects.toThrow();

const cancellationCall = tx.sentCalls.find(
({ message }) => 'method' in message && message.method === 'notifications/cancelled'
);
expect(cancellationCall?.options).toEqual({ relatedRequestId: 'parent-request' });
});

test('modern era + per-request-stream transport: timeout aborts the stream, NO notifications/cancelled', async () => {
const tx = new PerRequestStreamTransport();
const proto = createTestProtocol();
Expand Down
Loading