MCP C# SDK Guards Against Infinite Polling Loops in Async Task Handling
The MCP C# SDK's Tasks extension addresses a failure mode where asynchronous tool calls repeatedly return the same input_required status without making progress. The CallToolWithPollingAsync method deduplicates input-request keys and detects when consecutive polls return no new keys, triggering a cancellation attempt and throwing an McpException. Developers can configure the stuck-poll threshold via the maxConsecutiveStuckPolls parameter, with the default set at 60 consecutive stalled polls. The practical timeout depends on the server's poll interval multiplied by the threshold, meaning tasks with longer poll intervals need separate threshold tuning. This guard works alongside a CancellationToken, with each addressing a distinct failure question — whether the result is still needed versus whether the server is making useful progress.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in