Fix [mcp client times out after 60 seconds (ignoring timeout option) #245] #849
+71
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the timeout issue where MCP clients would timeout after 60 seconds even when receiving progress notifications from servers performing long-running operations.
Problem
The TypeScript/JavaScript SDK was timing out after 60 seconds regardless of progress updates from the server, while the Python SDK correctly handled progress notifications by resetting the timeout. This inconsistency caused issues for users with long-running MCP tools that send periodic progress updates.
Error encountered:
McpError: MCP error -32001: Request timed out
at Timeout.timeoutHandler (file:///.../@modelcontextprotocol/sdk/dist/esm/shared/protocol.js:282:49)
...
code: -32001,
data: { timeout: 60000 }
Root Cause
The resetTimeoutOnProgress option in RequestOptions defaulted to false, meaning that progress notifications would not reset the request timeout. This required users to explicitly opt-in to the intuitive behavior of keeping connections alive when progress is being reported.
Solution
Changed the default value of resetTimeoutOnProgress from false to true, making the TypeScript/JavaScript SDK behave consistently with the Python SDK. This ensures that:
Progress notifications automatically reset the timeout by default
Long-running operations with progress updates won't timeout prematurely
Backward compatibility is maintained (users can still set resetTimeoutOnProgress: false explicitly)
Changes
Protocol behavior: resetTimeoutOnProgress now defaults to true instead of false
Documentation: Updated JSDoc comments to reflect the new default
Tests: Added comprehensive test coverage for the new default behavior and updated existing tests to prevent interference
Verification
The fix has been verified with:
All existing tests pass (670 total tests)
New test specifically validates default timeout reset behavior
Manual testing with demonstration script confirms progress notifications reset timeout
Build and linting pass successfully
Example of the fix in action:
// Before: Would timeout after 60s despite progress
const result = await client.request(longRunningRequest, schema, {
onprogress: (progress) => console.log(progress)
});
// After: Automatically resets timeout on each progress notification
const result = await client.request(longRunningRequest, schema, {
onprogress: (progress) => console.log(progress) // timeout resets on each call
});
Fixes mcp client times out after 60 seconds (ignoring timeout option) #245