From a7292abff75613b1bad476fe857a469403ec98b3 Mon Sep 17 00:00:00 2001 From: Rob <46608303+classicrob@users.noreply.github.com> Date: Fri, 6 Feb 2026 10:33:38 -0800 Subject: [PATCH] Add get_state MCP tool for read-only state checks Co-Authored-By: Claude Opus 4.6 --- mcp/server.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mcp/server.ts b/mcp/server.ts index 670a14551..6d2d2b892 100644 --- a/mcp/server.ts +++ b/mcp/server.ts @@ -128,6 +128,20 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { type: 'object', properties: {} } + }, + { + name: 'get_state', + description: 'Read-only: Get current game state for a bot without executing any code. Safe to call while scripts are running. Returns position, inventory, skills, nearby NPCs/objects, recent messages, dialog state, and equipment.', + inputSchema: { + type: 'object', + properties: { + bot_name: { + type: 'string', + description: 'Bot name (matches folder in bots/). Auto-connects on first use.' + } + }, + required: ['bot_name'] + } } ] }; @@ -158,6 +172,31 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { }); } + case 'get_state': { + const botName = args?.bot_name as string; + + if (!botName) { + return errorResponse('bot_name is required'); + } + + // Auto-connect if not already connected + let connection = botManager.get(botName); + if (!connection) { + console.error(`[MCP] Bot "${botName}" not connected, auto-connecting...`); + connection = await botManager.connect(botName); + } + + const state = connection.sdk.getState(); + if (!state) { + return errorResponse('No game state available (bot may not be in-game)'); + } + + const output = formatWorldState(state, connection.sdk.getStateAge()); + return { + content: [{ type: 'text', text: output }] + }; + } + case 'execute_code': { const botName = args?.bot_name as string; const code = args?.code as string;