Skip to content

Commit b572522

Browse files
committed
fix: apply timeout configuration to all MCP client requests
- Added timeout parameter to readResource method - Added timeout parameter to fetchToolsList method - Added timeout parameter to fetchResourcesList method - Added timeout parameter to fetchResourceTemplatesList method Previously, only the callTool method was using the configured timeout, causing other MCP operations to use the default 30-second timeout instead of the user-configured value. Fixes #7836
1 parent 48d592f commit b572522

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

src/services/mcp/McpHub.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,19 @@ export class McpHub {
911911
return []
912912
}
913913

914-
const response = await connection.client.request({ method: "tools/list" }, ListToolsResultSchema)
914+
let timeout: number
915+
try {
916+
const parsedConfig = ServerConfigSchema.parse(JSON.parse(connection.server.config))
917+
timeout = (parsedConfig.timeout ?? 60) * 1000
918+
} catch (error) {
919+
console.error("Failed to parse server config for timeout:", error)
920+
// Default to 60 seconds if parsing fails
921+
timeout = 60 * 1000
922+
}
923+
924+
const response = await connection.client.request({ method: "tools/list" }, ListToolsResultSchema, {
925+
timeout,
926+
})
915927

916928
// Determine the actual source of the server
917929
const actualSource = connection.server.source || "global"
@@ -965,7 +977,20 @@ export class McpHub {
965977
if (!connection || connection.type !== "connected") {
966978
return []
967979
}
968-
const response = await connection.client.request({ method: "resources/list" }, ListResourcesResultSchema)
980+
981+
let timeout: number
982+
try {
983+
const parsedConfig = ServerConfigSchema.parse(JSON.parse(connection.server.config))
984+
timeout = (parsedConfig.timeout ?? 60) * 1000
985+
} catch (error) {
986+
console.error("Failed to parse server config for timeout:", error)
987+
// Default to 60 seconds if parsing fails
988+
timeout = 60 * 1000
989+
}
990+
991+
const response = await connection.client.request({ method: "resources/list" }, ListResourcesResultSchema, {
992+
timeout,
993+
})
969994
return response?.resources || []
970995
} catch (error) {
971996
// console.error(`Failed to fetch resources for ${serverName}:`, error)
@@ -982,9 +1007,23 @@ export class McpHub {
9821007
if (!connection || connection.type !== "connected") {
9831008
return []
9841009
}
1010+
1011+
let timeout: number
1012+
try {
1013+
const parsedConfig = ServerConfigSchema.parse(JSON.parse(connection.server.config))
1014+
timeout = (parsedConfig.timeout ?? 60) * 1000
1015+
} catch (error) {
1016+
console.error("Failed to parse server config for timeout:", error)
1017+
// Default to 60 seconds if parsing fails
1018+
timeout = 60 * 1000
1019+
}
1020+
9851021
const response = await connection.client.request(
9861022
{ method: "resources/templates/list" },
9871023
ListResourceTemplatesResultSchema,
1024+
{
1025+
timeout,
1026+
},
9881027
)
9891028
return response?.resourceTemplates || []
9901029
} catch (error) {
@@ -1564,6 +1603,17 @@ export class McpHub {
15641603
if (connection.server.disabled) {
15651604
throw new Error(`Server "${serverName}" is disabled`)
15661605
}
1606+
1607+
let timeout: number
1608+
try {
1609+
const parsedConfig = ServerConfigSchema.parse(JSON.parse(connection.server.config))
1610+
timeout = (parsedConfig.timeout ?? 60) * 1000
1611+
} catch (error) {
1612+
console.error("Failed to parse server config for timeout:", error)
1613+
// Default to 60 seconds if parsing fails
1614+
timeout = 60 * 1000
1615+
}
1616+
15671617
return await connection.client.request(
15681618
{
15691619
method: "resources/read",
@@ -1572,6 +1622,9 @@ export class McpHub {
15721622
},
15731623
},
15741624
ReadResourceResultSchema,
1625+
{
1626+
timeout,
1627+
},
15751628
)
15761629
}
15771630

0 commit comments

Comments
 (0)