Roo-Code/src/services/mcp
MuriloFP b2b5e1ffa6 fix: Implement singleton pattern for MCP server management to prevent multiple instances
Problem:
- Multiple instances of the Roo Code application were launching separate MCP server instances
- This led to unnecessary resource consumption and potential conflicts between instances

Solution:
1. Created new McpServerManager singleton class to manage MCP server instances:
   - Static getInstance() method ensures only one McpHub instance exists
   - Tracks registered ClineProvider instances
   - Handles cleanup on extension deactivation

2. Modified ClineProvider class:
   - Changed mcpHub from private to protected
   - Added getMcpHub() public getter method
   - Updated initialization to use McpServerManager
   - Added unregister logic in dispose()

3. Updated extension.ts to handle cleanup:
   - Added McpServerManager cleanup in deactivate()

Technical Implementation:
- Uses WeakRef for provider tracking to allow proper garbage collection
- Maintains global state to track instance IDs
- Implements proper cleanup of resources on disposal
- Ensures backward compatibility with existing code

This change significantly improves resource usage and prevents potential conflicts
between multiple instances of the application while maintaining all existing
functionality.
2025-02-07 15:51:30 -03:00
..
__tests__ Add per-server MCP network timeout configuration 2025-01-26 22:49:21 -05:00
McpHub.ts Add per-server MCP network timeout configuration 2025-01-26 22:49:21 -05:00
McpServerManager.ts fix: Implement singleton pattern for MCP server management to prevent multiple instances 2025-02-07 15:51:30 -03:00