mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-14 21:37:20 -07:00
fix(core): remove isolated MCP registries upon subagent completion
McpClient's registeredRegistries grows indefinitely during long sessions because isolated subagent registries were never removed. This commit introduces a cleanup mechanism invoked in LocalAgentExecutor's finally block to release these dead registries, preventing a memory leak.
This commit is contained in:
@@ -625,6 +625,15 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
|
||||
}
|
||||
} finally {
|
||||
this.config.userHintService.offUserHint(hintListener);
|
||||
|
||||
const globalMcpManager = this.context.config.getMcpClientManager();
|
||||
if (globalMcpManager) {
|
||||
globalMcpManager.removeRegistries({
|
||||
toolRegistry: this.toolRegistry,
|
||||
promptRegistry: this.promptRegistry,
|
||||
resourceRegistry: this.resourceRegistry,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// === UNIFIED RECOVERY BLOCK ===
|
||||
|
||||
@@ -164,6 +164,16 @@ export class McpClientManager {
|
||||
return this.clients.get(serverName);
|
||||
}
|
||||
|
||||
removeRegistries(registries: {
|
||||
toolRegistry: ToolRegistry;
|
||||
promptRegistry: PromptRegistry;
|
||||
resourceRegistry: ResourceRegistry;
|
||||
}): void {
|
||||
for (const client of this.clients.values()) {
|
||||
client.removeRegistries(registries);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For all the MCP servers associated with this extension:
|
||||
*
|
||||
|
||||
@@ -266,6 +266,14 @@ export class McpClient implements McpProgressReporter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters registries so this client will no longer update them when it receives
|
||||
* list_changed notifications from the server.
|
||||
*/
|
||||
removeRegistries(registries: RegistrySet): void {
|
||||
this.registeredRegistries.delete(registries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from the MCP server.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user