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
5 changes: 5 additions & 0 deletions .changeset/fix-automatic-task-polling-abort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modelcontextprotocol/server': patch
---

Check AbortSignal in handleAutomaticTaskPolling to stop cancelled requests from polling indefinitely. Previously, if a client cancelled a tools/call request during automatic task polling, the poll loop continued consuming server resources until the task completed or the process died.
3 changes: 3 additions & 0 deletions packages/server/src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ export class McpServer {
const pollInterval = task.pollInterval ?? 5000;

while (task.status !== 'completed' && task.status !== 'failed' && task.status !== 'cancelled') {
if (ctx.mcpReq.signal.aborted) {
throw new ProtocolError(ProtocolErrorCode.InternalError, 'Request cancelled during task polling');
}
await new Promise(resolve => setTimeout(resolve, pollInterval));
const updatedTask = await ctx.task.store.getTask(taskId);
if (!updatedTask) {
Expand Down
Loading