Skip to content
Open
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
29 changes: 27 additions & 2 deletions test/e2e/scenarios/protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,18 @@ verifies('protocol:timeout:basic', async ({ transport }: TestArgs) => {
verifies('protocol:timeout:max-total', async ({ transport }: TestArgs) => {
vi.useFakeTimers();
try {
let onCall: () => void = () => {};
const callReceived = new Promise<void>(resolve => {
onCall = resolve;
});

const makeServer = () => {
const s = new McpServer({ name: 's', version: '0' });
s.registerTool(
'slow-progress',
{ inputSchema: z.object({ delayMs: z.number(), steps: z.number() }) },
async ({ delayMs, steps }, ctx) => {
onCall();
const token = ctx.mcpReq._meta?.progressToken;
if (token !== undefined) {
for (let i = 1; i <= steps; i++) {
Expand All @@ -691,20 +697,39 @@ verifies('protocol:timeout:max-total', async ({ transport }: TestArgs) => {
const delayMs = 200;

const ticks: number[] = [];
let onTick: (() => void) | undefined;
const nextTick = () =>
new Promise<void>(resolve => {
onTick = resolve;
});

const call = client.callTool(
{ name: 'slow-progress', arguments: { delayMs, steps: 100 } },
{
timeout: perChunk,
resetTimeoutOnProgress: true,
maxTotalTimeout: maxTotal,
onprogress: p => ticks.push(p.progress)
onprogress: p => {
ticks.push(p.progress);
onTick?.();
onTick = undefined;
}
}
);
call.catch(() => {});
const callSettled = call.then(
() => {},
() => {}
);

// An SSE round trip is real I/O: the POST must land before the fake clock moves, or the request timeout fires first.
await callReceived;

for (let elapsed = 0; elapsed < maxTotal + perChunk; elapsed += delayMs) {
const tick = nextTick();
await vi.advanceTimersByTimeAsync(delayMs);
// Wait for the notification to arrive before advancing again, so the clock cannot outrun the SSE stream.
const next = await Promise.race([tick.then(() => 'progress' as const), callSettled.then(() => 'settled' as const)]);
if (next === 'settled') break;
}

await expect(call).rejects.toBeInstanceOf(SdkError);
Expand Down
Loading