@@ -19,6 +19,7 @@ import {
19
19
} from "./client/index.js" ;
20
20
import { handleError } from "./error-handler.js" ;
21
21
import { createTransport , TransportOptions } from "./transport.js" ;
22
+ import { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js" ;
22
23
23
24
type Args = {
24
25
target : string [ ] ;
@@ -29,6 +30,9 @@ type Args = {
29
30
logLevel ?: LogLevel ;
30
31
toolName ?: string ;
31
32
toolArg ?: Record < string , string > ;
33
+ requestTimeout ?: number ;
34
+ resetTimeoutOnProgress ?: boolean ;
35
+ maxTotalTimeout ?: number ;
32
36
} ;
33
37
34
38
function createTransportOptions ( target : string [ ] ) : TransportOptions {
@@ -67,7 +71,13 @@ async function callMethod(args: Args): Promise<void> {
67
71
} ) ;
68
72
69
73
try {
70
- await connect ( client , transport ) ;
74
+ const mcpRequestOptions : RequestOptions = {
75
+ timeout : args ?. requestTimeout ,
76
+ resetTimeoutOnProgress : args ?. resetTimeoutOnProgress ,
77
+ maxTotalTimeout : args ?. maxTotalTimeout ,
78
+ } ;
79
+
80
+ await connect ( client , transport , mcpRequestOptions ) ;
71
81
72
82
let result : McpResponse ;
73
83
@@ -151,6 +161,24 @@ function parseKeyValuePair(
151
161
return { ...previous , [ key as string ] : val } ;
152
162
}
153
163
164
+ function parseStringToNumber ( value : string ) : number {
165
+ const parsedValue = parseInt ( value , 10 ) ;
166
+ if ( isNaN ( parsedValue ) ) {
167
+ throw new Error ( `Invalid parameter format : ${value } . Use a number format . `) ;
168
+ }
169
+ return parsedValue ;
170
+ }
171
+
172
+ function parseStringToBoolean ( value : string ) : boolean {
173
+ if ( value === "true ") {
174
+ return true ;
175
+ } else if ( value === "false ") {
176
+ return false ;
177
+ } else {
178
+ throw new Error ( `Invalid parameter format : ${value } . Use true or false . `) ;
179
+ }
180
+ }
181
+
154
182
function parseArgs ( ) : Args {
155
183
const program = new Command ( ) ;
156
184
@@ -214,6 +242,24 @@ function parseArgs(): Args {
214
242
215
243
return value as LogLevel ;
216
244
} ,
245
+ )
246
+ . option (
247
+ "--request-timeout <number>" ,
248
+ "Timeout for requests to the MCP server (ms)" ,
249
+ parseStringToNumber ,
250
+ 10000 ,
251
+ )
252
+ . option (
253
+ "--reset-timeout-on-progress <boolean>" ,
254
+ "Reset timeout on progress notifications" ,
255
+ parseStringToBoolean ,
256
+ true ,
257
+ )
258
+ . option (
259
+ "--max-total-timeout <number>" ,
260
+ "Maximum total timeout for requests sent to the MCP server (ms) (Use with progress notifications)" ,
261
+ parseStringToNumber ,
262
+ 60000 ,
217
263
) ;
218
264
219
265
// Parse only the arguments before --
0 commit comments