Skip to content

Commit 409ad50

Browse files
authored
fix: add tool call timeout (#93)
add tool call timeout
1 parent 6abd1eb commit 409ad50

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/mcp/const.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const MAX_TOOL_NAME_LENGTH = 64;
22
export const SERVER_ID_LENGTH = 8;
3+
export const EXTERNAL_TOOL_CALL_TIMEOUT_MSEC = 120_000; // 2 minutes

src/mcp/server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
66
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
77
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
8-
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
8+
import { CallToolRequestSchema, CallToolResultSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
99
import type { ActorCallOptions } from 'apify-client';
1010

1111
import log from '@apify/log';
@@ -28,6 +28,7 @@ import {
2828
import { actorNameToToolName } from '../tools/utils.js';
2929
import type { ActorMCPTool, ActorTool, HelperTool, ToolWrap } from '../types.js';
3030
import { createMCPClient } from './client.js';
31+
import { EXTERNAL_TOOL_CALL_TIMEOUT_MSEC } from './const.js';
3132
import { processParamsGetTools } from './utils.js';
3233

3334
type ActorsMcpServerOptions = {
@@ -223,6 +224,8 @@ export class ActorsMcpServer {
223224
const res = await client.callTool({
224225
name: serverTool.originToolName,
225226
arguments: args,
227+
}, CallToolResultSchema, {
228+
timeout: EXTERNAL_TOOL_CALL_TIMEOUT_MSEC,
226229
});
227230

228231
return { ...res };

0 commit comments

Comments
 (0)