Skip to content

Commit ad9004a

Browse files
committed
fix(tarko): improve mcp client connection failure handling
- Throw errors instead of returning empty arrays in MCPClient.listTools() - Add tool count validation in MCPClientV2.initialize() to detect connection failures - Prevent silent failures when MCP server connections fail
1 parent 41bf5b9 commit ad9004a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

multimodal/tarko/mcp-agent/src/mcp-client-v2.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export class MCPClientV2 implements IMCPClient {
4747
this.logger.info(`Initializing MCP client v2 for ${this.serverName}`);
4848
await this.v2Client.init();
4949
this.tools = await this.v2Client.listTools(this.serverName as string);
50+
51+
// Validate that we got tools - if 0 tools, this likely indicates a connection failure
52+
if (this.tools.length === 0) {
53+
throw new Error(`MCP server ${this.serverName} connection failed: no tools available`);
54+
}
55+
5056
this.isInitialized = true;
5157
this.logger.success(
5258
`MCP client v2 initialized successfully for ${this.serverName}, found ${this.tools.length} tools`,

packages/agent-infra/mcp-client/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,19 @@ export class MCPClient<
557557
`[MCP] Error listing tools for ${clientName}:`,
558558
error,
559559
);
560+
// Re-throw error for specific server when serverName is provided
561+
if (serverName === clientName) {
562+
throw error;
563+
}
560564
}
561565
}
562566
this.log('info', `[MCP] Total tools listed: ${allTools.length}`);
563567
return allTools;
564568
}
565569
} catch (error) {
566570
this.log('error', '[MCP] Error listing tools:', error);
567-
return [];
571+
// Don't return empty array for critical failures, re-throw the error
572+
throw error;
568573
}
569574
}
570575

0 commit comments

Comments
 (0)