feat: Add torch MCP tools for multi-browser control

- Add torchHandlers.ts with 5 tools:
  - list_torch_clients: list connected browsers with metadata
  - get_torch_status: show current torch holder
  - transfer_torch: transfer control to another browser
  - request_torch: request MCP control
  - release_torch: release MCP control
- Add 'transfer' message type to server torch-handler
- Add torch category to all pages
- Export helper functions from torch.ts
This commit is contained in:
2026-02-14 17:52:16 -06:00
parent 210e15d8d1
commit 1a51b34228
6 changed files with 252 additions and 16 deletions

View File

@@ -102,6 +102,43 @@ export function handleTorchMessage(ws: any, data: any, broadcast: (message: stri
}
break
}
case 'transfer': {
// Transfer torch to a specific client (only if sender has torch or no one has it)
const targetId = data.targetId
if (!targetId) {
ws.send(JSON.stringify({ type: 'error', message: 'targetId required' }))
break
}
// Check if target exists
let targetExists = false
for (const [, c] of torchClients) {
if (c.id === targetId) {
targetExists = true
break
}
}
if (!targetExists) {
ws.send(JSON.stringify({ type: 'error', message: 'Target client not found' }))
break
}
// Only allow transfer if sender has torch or no one has it
if (torchHolderId !== null && torchHolderId !== client.id) {
ws.send(JSON.stringify({ type: 'error', message: 'Cannot transfer - you do not have the torch' }))
break
}
const previousHolder = torchHolderId
torchHolderId = targetId
ws.send(JSON.stringify({ type: 'transferred', targetId }))
console.log(`[Torch] Transferred by ${client.id}: ${previousHolder}${targetId}`)
broadcastTorchState(broadcast)
break
}
}
}