Skip to main content
Glama
Mming-Lab
by Mming-Lab

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
NameRequiredDescriptionDefault
commandYesThe 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,
            },
          ],
        };
      }
    );
  • 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}`,
        };
      }
    }
  • 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)}` 
            };
        }
    }
  • Input schema definition for execute_command tool using Zod: command as required string.
    inputSchema: {
      command: z.string().describe("The Minecraft command to execute"),
    },
Install Server

Other Tools

Related Tools

  • @Mming-Lab/minecraft-bedrock-mcp-server
  • @yuniko-software/minecraft-mcp-server
  • @Mming-Lab/minecraft-bedrock-mcp-server
  • @Mming-Lab/minecraft-bedrock-mcp-server
  • @zeeweebee/mcp-server
  • @leo4life2/minecraft-mcp-http

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Mming-Lab/minecraft-bedrock-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server