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:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user