Roo-Code/src
Hannes Rudolph 3f6e07adf1
refactor(mcp): Implement reference counting for McpHub lifecycle (#2310)
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
2025-04-04 23:14:05 -04:00
..
__mocks__ Re-enable ClineProvider tests (#2047) 2025-03-27 21:06:54 -07:00
__tests__ Removed hardcoded filenames to GlobalFileNames constants. (#1904) 2025-03-24 13:32:44 -04:00
activate Revert "Better logic for choosing the view column when opening Roo in a tab" (#2285) 2025-04-04 02:14:33 -04:00
api Jbbrown/bedrock caching (#2071) 2025-04-03 13:05:29 -04:00
core refactor(mcp): Implement reference counting for McpHub lifecycle (#2310) 2025-04-04 23:14:05 -04:00
exports Ironing out some kinks when running evals with high parallelism (#2280) 2025-04-04 09:08:12 -07:00
i18n Improve zh-TW Traditional Chinese locale (#2305) 2025-04-04 22:22:48 -04:00
integrations Allow processes to access the Roo Code API via a unix socket (#2232) 2025-04-02 12:42:00 -07:00
schemas Jbbrown/bedrock caching (#2071) 2025-04-03 13:05:29 -04:00
services refactor(mcp): Implement reference counting for McpHub lifecycle (#2310) 2025-04-04 23:14:05 -04:00
shared Add the gemini 2.5 pro preview model with upper bound pricing (#2300) 2025-04-04 15:12:18 -04:00
utils Revert "feat @-mention window path style & file with space (#1924)" (#2162) 2025-03-31 15:56:47 -05:00
extension.ts Allow processes to access the Roo Code API via a unix socket (#2232) 2025-04-02 12:42:00 -07:00