Problem:
Closing auxiliary windows (e.g., from "open in editor") could prematurely dispose the shared singleton McpHub instance, shutting down MCP servers unexpectedly while other panels (like the sidebar) might still be active.
Solution:
Implemented reference counting directly within the McpHub class to manage its own lifecycle based on active clients (ClineProvider instances).
- Added `refCount`, `registerClient()`, and `unregisterClient()` methods to McpHub.
- McpHub now disposes itself only when the last registered client unregisters (`refCount` reaches 0).
- ClineProvider instances now call `mcpHub.registerClient()` upon initialization and `mcpHub.unregisterClient()` upon disposal.
- Removed the direct `mcpHub.dispose()` call from ClineProvider.dispose.
Benefit:
This ensures the shared McpHub instance remains active as long as at least one ClineProvider instance is using it. Cleanup now correctly occurs only when the last provider is closed or during full extension deactivation. This centralizes the resource's lifecycle logic within the resource class itself.
Files Changed:
- src/services/mcp/McpHub.ts
- src/core/webview/ClineProvider.ts
Problem:
Closing auxiliary windows (e.g., from "open in editor") could prematurely dispose the shared singleton McpHub instance, shutting down MCP servers unexpectedly while other panels (like the sidebar) might still be active.
Solution:
Implemented reference counting directly within the McpHub class to manage its own lifecycle based on active clients (ClineProvider instances).
refCount,registerClient(), andunregisterClient()methods to McpHub.refCountreaches 0).mcpHub.registerClient()upon initialization andmcpHub.unregisterClient()upon disposal.mcpHub.dispose()call from ClineProvider.dispose.Benefit:
This ensures the shared McpHub instance remains active as long as at least one ClineProvider instance is using it. Cleanup now correctly occurs only when the last provider is closed or during full extension deactivation. This centralizes the resource's lifecycle logic within the resource class itself.
Files Changed:
Important
Implements reference counting in
McpHubto manage its lifecycle based on activeClineProviderinstances, preventing premature disposal.McpHubto manage lifecycle based on activeClineProviderinstances.McpHubdisposes itself only whenrefCountreaches 0.ClineProvidercallsregisterClient()on initialization andunregisterClient()on disposal.dispose()call fromClineProvider.dispose().registerClient()andunregisterClient()toMcpHub.McpHub.tsandClineProvider.ts.This description was created by
for 0c51f38. It will automatically update as commits are pushed.