When the MCP server was initialized before opening RooCode, the server list
would not appear in the settings. This was fixed by:
1. Adding proper server list initialization in ClineProvider.ts when the
webview launches, checking if mcpHub exists and sending its current
servers to the webview:
```typescript
if (this.mcpHub) {
this.postMessageToWebview({
type: "mcpServers",
mcpServers: this.mcpHub.getServers()
})
}
```
2. Using the public getServers() method from McpHub instead of relying on
internal state updates, ensuring consistent server list state across
the application.
The fix maintains clean separation of concerns and follows existing patterns
for state management between the extension and webview.
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.
The context token calculation has been updated to:
- Include cache tokens (cacheWrites + cacheReads) in the total context size
- Use a cleaner approach to find the last valid API request
- Fix issue where placeholder messages without token info were being counted
- Match upstream's implementation of getTotalTokensFromMessage
This fixes the issue where context size was incorrectly showing as 139 tokens
without any API requests being made.