-
Notifications
You must be signed in to change notification settings - Fork 18
fix: forward server timeout to MCP SDK Client requests #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,15 +162,22 @@ export class McpCommunicationProtocol implements CommunicationProtocol { | |
| return mcpClient; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the configured timeout for an MCP server in milliseconds. | ||
| * Defaults to 30 seconds when not specified. | ||
| */ | ||
| private _getTimeoutMs(serverConfig: McpServerConfig): number { | ||
| return (serverConfig.timeout ?? 30) * 1000; | ||
| } | ||
|
|
||
| private async _withSession<T>( | ||
| serverName: string, | ||
| serverConfig: McpServerConfig, | ||
| auth: OAuth2Auth | undefined, | ||
| operation: (client: McpClient) => Promise<T> | ||
| ): Promise<T> { | ||
| const sessionKey = `${serverName}:${serverConfig.transport}`; | ||
| // Use configured timeout (in seconds) or default to 30s | ||
| const timeoutMs = (serverConfig.timeout ?? 30) * 1000; | ||
| const timeoutMs = this._getTimeoutMs(serverConfig); | ||
| try { | ||
| const client = await this._getOrCreateSession(serverName, serverConfig, auth); | ||
| return await Promise.race([ | ||
|
|
@@ -211,8 +218,9 @@ export class McpCommunicationProtocol implements CommunicationProtocol { | |
| for (const [serverName, serverConfig] of Object.entries(mcpCallTemplate.config.mcpServers)) { | ||
| try { | ||
| this._logInfo(`Discovering tools from MCP server '${serverName}'...`); | ||
| const requestTimeout = this._getTimeoutMs(serverConfig); | ||
| const mcpToolsResult = await this._withSession(serverName, serverConfig, mcpCallTemplate.auth, | ||
| (client) => client.listTools() | ||
| (client) => client.listTools(undefined, { timeout: requestTimeout }) | ||
| ); | ||
|
|
||
| if (!isMcpToolsResponse(mcpToolsResult)) { | ||
|
|
@@ -292,8 +300,9 @@ export class McpCommunicationProtocol implements CommunicationProtocol { | |
| } | ||
|
|
||
| this._logInfo(`Calling tool '${actualToolName}' on MCP server '${serverName}'...`); | ||
| const requestTimeout = this._getTimeoutMs(serverConfig); | ||
| const result = await this._withSession(serverName, serverConfig, mcpCallTemplate.auth, | ||
| (client) => client.callTool({ name: actualToolName, arguments: toolArgs }) | ||
| (client) => client.callTool({ name: actualToolName, arguments: toolArgs }, undefined, { timeout: requestTimeout }) | ||
| ); | ||
|
Comment on lines
+303
to
306
|
||
|
|
||
| return this._processMcpToolResult(result); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New behavior forwards a per-request timeout into the MCP SDK (
listTools/callTooloptions). This is the core fix but isn’t covered by the existing MCP protocol tests. Please add a unit test that asserts the SDK client receives the expectedtimeoutoption (e.g., by monkeypatching_getOrCreateSessionto return a fake client and asserting the passed options), so regressions don’t silently reintroduce the 60s default timeout issue.