mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-18 15:52:53 -07:00
fix(core): reuse connected MCP client in subagent invocations
Subsequent subagent invocations attempt to connect to an already connected MCP client, throwing an error. This commit adds a status check before calling client.connect(), enabling client.discoverInto() to successfully populate the new subagent registry.
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
type MockedObject,
|
||||
} from 'vitest';
|
||||
import { McpClientManager } from './mcp-client-manager.js';
|
||||
import { McpClient, MCPDiscoveryState } from './mcp-client.js';
|
||||
import { McpClient, MCPDiscoveryState, MCPServerStatus } from './mcp-client.js';
|
||||
import type { ToolRegistry } from './tool-registry.js';
|
||||
import type { Config, GeminiCLIExtension } from '../config/config.js';
|
||||
import type { PromptRegistry } from '../prompts/prompt-registry.js';
|
||||
@@ -38,7 +38,7 @@ describe('McpClientManager', () => {
|
||||
connect: vi.fn(),
|
||||
discoverInto: vi.fn(),
|
||||
disconnect: vi.fn(),
|
||||
getStatus: vi.fn(),
|
||||
getStatus: vi.fn().mockReturnValue(MCPServerStatus.DISCONNECTED),
|
||||
getServerConfig: vi.fn(),
|
||||
getServerName: vi.fn().mockReturnValue('test-server'),
|
||||
} as unknown as McpClient);
|
||||
|
||||
@@ -13,6 +13,7 @@ import type { ToolRegistry } from './tool-registry.js';
|
||||
import {
|
||||
McpClient,
|
||||
MCPDiscoveryState,
|
||||
MCPServerStatus,
|
||||
populateMcpServerCommand,
|
||||
} from './mcp-client.js';
|
||||
import { getErrorMessage, isAuthenticationError } from '../utils/errors.js';
|
||||
@@ -458,7 +459,9 @@ export class McpClientManager {
|
||||
: undefined);
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
if (client.getStatus() === MCPServerStatus.DISCONNECTED) {
|
||||
await client.connect();
|
||||
}
|
||||
if (targetRegistries) {
|
||||
await client.discoverInto(this.cliConfig, targetRegistries);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user