mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-10 11:12:35 -07:00
fix(core): remove stale MCP client from map on initialization failure
This commit is contained in:
@@ -751,6 +751,19 @@ describe('McpClientManager', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should remove the client from the clients map if initialization fails', async () => {
|
||||
const manager = new McpClientManager('0.0.1', toolRegistry, mockConfig);
|
||||
const name = 'test-server';
|
||||
const config = { command: 'node', args: ['fail.js'] };
|
||||
|
||||
mockedMcpClient.connect.mockRejectedValue(new Error('Connection failed'));
|
||||
|
||||
// maybeDiscoverMcpServer returns a promise that resolves when discovery is finished.
|
||||
await manager.maybeDiscoverMcpServer(name, config);
|
||||
|
||||
expect(manager.getClient(name)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should show previously deduplicated errors after interaction clears state', () => {
|
||||
const manager = new McpClientManager('0.0.1', toolRegistry, mockConfig);
|
||||
|
||||
|
||||
@@ -404,6 +404,7 @@ export class McpClientManager {
|
||||
await client.discover(this.cliConfig);
|
||||
this.eventEmitter?.emit('mcp-client-update', this.clients);
|
||||
} catch (error) {
|
||||
this.clients.delete(name);
|
||||
this.eventEmitter?.emit('mcp-client-update', this.clients);
|
||||
// Check if this is a 401/auth error - if so, don't show as red error
|
||||
// (the info message was already shown in mcp-client.ts)
|
||||
@@ -418,6 +419,7 @@ export class McpClientManager {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.clients.delete(name);
|
||||
const errorMessage = getErrorMessage(error);
|
||||
this.emitDiagnostic(
|
||||
'error',
|
||||
|
||||
Reference in New Issue
Block a user