fix: Only register MCP tools when connected via torch

- Tools only register when connected to MCP (has torch)
- Store current page for tool activation when torch is obtained
- Add onTorchConnected to activate page tools after MCP connection
- Add onTorchDisconnected to clear tools when losing torch
- Page changes only update tools if connected, otherwise store for later
This commit is contained in:
2026-02-14 17:32:58 -06:00
parent 0f73bd60bf
commit 3817645919
2 changed files with 62 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import { useTorchStore } from '../stores/torch'
import { autoConnect, disconnectWebMCP } from './webmcp'
import { onTorchConnected, onTorchDisconnected } from './toolRegistry'
import { endpoints } from '../config/endpoints'
let torchWs: WebSocket | null = null
@@ -150,7 +151,8 @@ async function connectToMCP(): Promise<void> {
console.log('[Torch] Connecting to MCP...')
const success = await autoConnect()
if (success) {
console.log('[Torch] Connected to MCP')
console.log('[Torch] Connected to MCP, activating tools')
await onTorchConnected()
} else {
console.error('[Torch] Failed to connect to MCP')
}
@@ -161,6 +163,7 @@ async function connectToMCP(): Promise<void> {
*/
function disconnectFromMCP(): void {
console.log('[Torch] Disconnecting from MCP...')
onTorchDisconnected()
disconnectWebMCP()
}