execute_command
Run Minecraft commands directly through the MCP server to control gameplay, manipulate the world, and manage player actions in Minecraft Bedrock Edition.
Instructions
Execute a Minecraft command
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | The Minecraft command to execute |
Implementation Reference
- src/server.ts:442-485 (registration)Registration of the 'execute_command' MCP tool, including schema definition (command: string) and handler function that calls executeCommand, optimizes result, adds hints, and formats MCP response.this.mcpServer.registerTool( "execute_command", { title: "Execute Command", description: "Execute a Minecraft command", inputSchema: { command: z.string().describe("The Minecraft command to execute"), }, }, async ({ command }: { command: string }) => { const result = await this.executeCommand(command); // トークン最適化: コマンド結果を要約 const optimized = optimizeCommandResult(result.data); let responseText: string; if (result.success) { responseText = `✅ ${optimized.summary}`; if (optimized.details) { responseText += `\n\n${JSON.stringify(optimized.details, null, 2)}`; } } else { // エラーメッセージにヒントを追加 const errorMsg = result.message || "Command execution failed"; const enrichedError = enrichErrorWithHints(errorMsg); responseText = `❌ ${enrichedError}`; } // レスポンスサイズチェック const sizeWarning = checkResponseSize(responseText); if (sizeWarning) { responseText += `\n\n${sizeWarning}`; } return { content: [ { type: "text", text: responseText, }, ], }; } );
- src/server.ts:630-652 (handler)Core handler logic for executing Minecraft commands via SocketBE World.runCommandAsync, handling world connection check and storing last response.public async executeCommand(command: string): Promise<ToolCallResult> { if (!this.currentWorld) { return { success: false, message: "No player connected" }; } try { const result = await this.currentWorld.runCommand(command); // レスポンスをlastCommandResponseに保存(位置情報取得などで使用) this.lastCommandResponse = result; return { success: true, message: "Command executed successfully", data: result, }; } catch (error) { return { success: false, message: `Command execution failed: ${error}`, }; } }
- src/tools/base/tool.ts:133-146 (helper)BaseTool helper method for command execution, delegates to injected commandExecutor (server's executeCommand), used by modular tools.protected async executeCommand(command: string): Promise<ToolCallResult> { if (!this.commandExecutor) { return { success: false, message: 'Command executor not set' }; } try { return await this.commandExecutor(command); } catch (error) { return { success: false, message: `Command execution error: ${error instanceof Error ? error.message : String(error)}` }; } }
- src/server.ts:447-449 (schema)Input schema definition for execute_command tool using Zod: command as required string.inputSchema: { command: z.string().describe("The Minecraft command to execute"), },