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/perky-sloths-say.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modelcontextprotocol/core': minor
---

Added ability to set mcp tool call timeout for the client from an env - keeping the fallback of 60_000
2 changes: 1 addition & 1 deletion docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ client.onclose = () => {

### Timeouts

All requests have a 60-second default timeout. Pass a custom `timeout` in the options to override it. On timeout, the SDK sends a cancellation notification to the server and rejects the promise with {@linkcode @modelcontextprotocol/client!index.SdkErrorCode.RequestTimeout | SdkErrorCode.RequestTimeout}:
All requests have a 60-second default timeout. You can override it globally by setting the `MCP_TOOL_CALL_MCP_REQUEST_TIMEOUT_MSEC` environment variable, or pass a custom `timeout` in the options per request. On timeout, the SDK sends a cancellation notification to the server and rejects the promise with {@linkcode @modelcontextprotocol/client!index.SdkErrorCode.RequestTimeout | SdkErrorCode.RequestTimeout}:

```ts source="../examples/client/src/clientGuide.examples.ts#errorHandling_timeout"
try {
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,17 @@ export type ProtocolOptions = {

/**
* The default request timeout, in milliseconds.
*
* Can be overridden via the `MCP_TOOL_CALL_MCP_REQUEST_TIMEOUT_MSEC` environment variable.
*/
export const DEFAULT_REQUEST_TIMEOUT_MSEC = 60_000;
export const DEFAULT_REQUEST_TIMEOUT_MSEC = (() => {
try {
const envValue = Number.parseInt(process.env.MCP_TOOL_CALL_MCP_REQUEST_TIMEOUT_MSEC ?? '', 10);
return envValue > 0 ? envValue : 60_000;
} catch {
return 60_000;
}
})();

/**
* Options that can be given per request.
Expand Down
Loading