Skip to content

Commit 1fa749d

Browse files
committed
Added default mcp tool call timeout from env
Signed-off-by: hayden.rear <hayden.rear@gmail.com>
1 parent 7ba58da commit 1fa749d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.changeset/perky-sloths-say.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/core': minor
3+
---
4+
5+
Added ability to set mcp tool call timeout for the client from an env - keeping the fallback of 60_000

docs/client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ client.onclose = () => {
539539

540540
### Timeouts
541541

542-
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}:
542+
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}:
543543

544544
```ts source="../examples/client/src/clientGuide.examples.ts#errorHandling_timeout"
545545
try {

packages/core/src/shared/protocol.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,17 @@ export type ProtocolOptions = {
9696

9797
/**
9898
* The default request timeout, in milliseconds.
99+
*
100+
* Can be overridden via the `MCP_TOOL_CALL_MCP_REQUEST_TIMEOUT_MSEC` environment variable.
99101
*/
100-
export const DEFAULT_REQUEST_TIMEOUT_MSEC = 60_000;
102+
export const DEFAULT_REQUEST_TIMEOUT_MSEC = (() => {
103+
try {
104+
const envValue = Number.parseInt(process.env.MCP_TOOL_CALL_MCP_REQUEST_TIMEOUT_MSEC ?? '', 10);
105+
return envValue > 0 ? envValue : 60_000;
106+
} catch {
107+
return 60_000;
108+
}
109+
})();
101110

102111
/**
103112
* Options that can be given per request.

0 commit comments

Comments
 (0)