agent
Control and automate in-game tasks such as movement, mining, building, and inventory management for Minecraft Bedrock Edition. Perform actions like teleportation, item collection, and block placement to streamline gameplay and resource management.
Instructions
Agent control: movement, building, mining, inventory, exploration, construction, resource gathering
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Agent action to perform | |
| amount | No | Item amount (1-64) | |
| data | No | Item data/aux value | |
| direction | No | Direction for movement/rotation/block operations | |
| distance | No | Number of blocks to move (1-10) | |
| item_id | No | Item ID (e.g., minecraft:stone, minecraft:dirt) | |
| slot | No | Inventory slot (1-16) | |
| steps | No | Array of agent actions for sequence. Each step should have "type" field and relevant parameters. | |
| x | No | X coordinate for teleportation | |
| y | No | Y coordinate for teleportation | |
| z | No | Z coordinate for teleportation |
Implementation Reference
- src/tools/core/agent.ts:84-230 (handler)Core handler function implementing all 'agent' tool actions (move, turn, teleport, attack, mine/place blocks, inventory ops, sequences) via switch on 'action' param.async execute(args: { action: string; direction?: string; distance?: number; x?: number; y?: number; z?: number; slot?: number; item_id?: string; amount?: number; data?: number; steps?: SequenceStep[]; }): Promise<ToolCallResult> { if (!this.agent) { return { success: false, message: 'Agent not available. Ensure Minecraft is connected and agent is spawned.' }; } try { const { action } = args; let result: any; let message: string; switch (action) { case 'move': if (!args.direction) return { success: false, message: 'Direction required for move' }; const distance = args.distance || 1; for (let i = 0; i < distance; i++) { await this.agent.move(args.direction as AgentDirection); } message = distance === 1 ? `Agent moved ${args.direction}` : `Agent moved ${distance} blocks ${args.direction}`; break; case 'turn': if (!args.direction || !['left', 'right'].includes(args.direction)) { return { success: false, message: 'Direction must be "left" or "right" for turn' }; } await this.agent.turn(args.direction as AgentDirection.Left | AgentDirection.Right); message = `Agent turned ${args.direction}`; break; case 'teleport': if (args.x !== undefined && args.y !== undefined && args.z !== undefined) { await this.agent.teleport({ x: args.x, y: args.y, z: args.z }); message = `Agent teleported to (${args.x}, ${args.y}, ${args.z})`; result = { x: args.x, y: args.y, z: args.z }; } else { await this.agent.teleport(); message = 'Agent teleported to player location'; } break; case 'attack': if (!args.direction) return { success: false, message: 'Direction required for attack' }; await this.agent.attack(args.direction as AgentDirection); message = `Agent attacked ${args.direction}`; break; case 'mine_block': if (!args.direction) return { success: false, message: 'Direction required for mine_block' }; await this.agent.destroyBlock(args.direction as AgentDirection); message = `Agent mined block ${args.direction}`; break; case 'place_block': if (!args.direction || !args.slot) return { success: false, message: 'Direction and slot required for place_block' }; await this.agent.placeBlock(args.direction as AgentDirection, args.slot); message = `Agent placed block from slot ${args.slot} ${args.direction}`; break; case 'inspect_block': if (!args.direction) return { success: false, message: 'Direction required for inspect_block' }; result = await this.agent.inspect(args.direction as AgentDirection); message = `Agent inspected block ${args.direction}`; break; case 'detect_block': if (!args.direction) return { success: false, message: 'Direction required for detect_block' }; result = await this.agent.detect(args.direction as AgentDirection); message = `Agent detected block ${args.direction}`; break; case 'get_position': result = await this.agent.getLocation(); message = 'Agent position retrieved'; break; case 'collect_item': if (!args.item_id) return { success: false, message: 'item_id required for collect_item' }; await this.agent.collect(args.item_id); message = `Agent collected ${args.item_id}`; break; case 'drop_item': if (!args.direction || !args.slot) return { success: false, message: 'Direction and slot required for drop_item' }; const dropAmount = args.amount || 1; await this.agent.dropItem(args.direction as AgentDirection, args.slot, dropAmount); message = `Agent dropped ${dropAmount} items from slot ${args.slot} ${args.direction}`; break; case 'drop_all': if (!args.direction) return { success: false, message: 'Direction required for drop_all' }; await this.agent.dropAllItems(args.direction as AgentDirection); message = `Agent dropped all items ${args.direction}`; break; case 'get_inventory': if (!args.slot) return { success: false, message: 'Slot required for get_inventory' }; const itemDetail = await this.agent.getItemDetail(args.slot); const itemCount = await this.agent.getItemCount(args.slot); const itemSpace = await this.agent.getItemSpace(args.slot); result = { detail: itemDetail, count: itemCount, space: itemSpace }; message = `Inventory info for slot ${args.slot} retrieved`; break; case 'set_item_in_slot': if (!args.slot || !args.item_id) return { success: false, message: 'Slot and item_id required for set_item_in_slot' }; const setAmount = args.amount || 1; const setData = args.data || 0; await this.agent.setItem(args.slot, args.item_id, setAmount, setData); message = `Set ${setAmount} ${args.item_id} in slot ${args.slot}`; break; case 'sequence': if (!args.steps) { return this.createErrorResponse('steps array is required for sequence action'); } return await this.executeSequence(args.steps as SequenceStep[]); default: return { success: false, message: `Unknown action: ${action}` }; } return { success: true, message: message, data: { action, result, timestamp: Date.now() } }; } catch (error) { return { success: false, message: `Agent operation error: ${error instanceof Error ? error.message : String(error)}` }; } }
- src/tools/core/agent.ts:13-68 (schema)Input schema defining parameters for agent tool: action (enum), direction, distance, coords, slots, items, etc.readonly inputSchema: InputSchema = { type: 'object', properties: { action: { type: 'string', description: 'Agent action to perform', enum: [ 'move', 'turn', 'teleport', 'attack', 'mine_block', 'place_block', 'inspect_block', 'detect_block', 'get_position', 'collect_item', 'drop_item', 'drop_all', 'get_inventory', 'set_item_in_slot', 'sequence' ] }, direction: { type: 'string', description: 'Direction for movement/rotation/block operations', enum: ['forward', 'back', 'left', 'right', 'up', 'down'] }, distance: { type: 'number', description: 'Number of blocks to move (1-10)', minimum: 1, maximum: 10, default: 1 }, x: { type: 'number', description: 'X coordinate for teleportation' }, y: { type: 'number', description: 'Y coordinate for teleportation' }, z: { type: 'number', description: 'Z coordinate for teleportation' }, slot: { type: 'number', description: 'Inventory slot (1-16)', minimum: 1, maximum: 16 }, item_id: { type: 'string', description: 'Item ID (e.g., minecraft:stone, minecraft:dirt)' }, amount: { type: 'number', description: 'Item amount (1-64)', minimum: 1, maximum: 64, default: 1 }, data: { type: 'number', description: 'Item data/aux value', default: 0 }, steps: { type: 'array', description: 'Array of agent actions for sequence. Each step should have "type" field and relevant parameters.' } }, required: ['action'] };
- src/server.ts:348-372 (registration)Instantiation of AgentTool() and inclusion in the tools array.this.tools = [ // Socket-BE Core API ツール(推奨 - シンプルでAI使いやすい) new AgentTool(), new WorldTool(), new PlayerTool(), new BlocksTool(), new SystemTool(), new CameraTool(), new SequenceTool(), new MinecraftWikiTool(), // Advanced Building ツール(高レベル建築機能) new BuildCubeTool(), // ✅ 完全動作 new BuildLineTool(), // ✅ 完全動作 new BuildSphereTool(), // ✅ 完全動作 new BuildCylinderTool(), // ✅ 修正済み new BuildParaboloidTool(), // ✅ 基本動作 new BuildHyperboloidTool(), // ✅ 基本動作 new BuildRotateTool(), // ✅ 基本動作 new BuildTransformTool(), // ✅ 基本動作 new BuildTorusTool(), // ✅ 修正完了 new BuildHelixTool(), // ✅ 修正完了 new BuildEllipsoidTool(), // ✅ 修正完了 new BuildBezierTool(), // ✅ 新規追加(可変制御点ベジェ曲線) ];
- src/server.ts:494-573 (registration)Registration loop using mcpServer.registerTool for each tool (including 'agent') with name, desc, converted schema, and execute wrapper.this.tools.forEach((tool) => { // inputSchemaをZod形式に変換(SchemaToZodConverterを使用) const zodSchema = schemaConverter.convert(tool.inputSchema); // ツールを登録 this.mcpServer.registerTool( tool.name, { title: tool.name, description: tool.description, inputSchema: zodSchema, }, async (args: any) => { try { const result = await tool.execute(args); let responseText: string; if (result.success) { // 建築ツールの場合は最適化 if (tool.name.startsWith('build_')) { const optimized = optimizeBuildResult(result); responseText = `✅ ${optimized.message}`; if (optimized.summary) { responseText += `\n\n📊 Summary:\n${JSON.stringify(optimized.summary, null, 2)}`; } } else { // 通常ツールの場合 responseText = result.message || `Tool ${tool.name} executed successfully`; if (result.data) { // データサイズチェック const dataStr = JSON.stringify(result.data, null, 2); const sizeWarning = checkResponseSize(dataStr); if (sizeWarning) { // 大きすぎる場合はデータタイプのみ表示 responseText += `\n\n${sizeWarning}`; responseText += `\nData type: ${Array.isArray(result.data) ? `Array[${result.data.length}]` : typeof result.data}`; } else { responseText += `\n\nData: ${dataStr}`; } } } } else { // エラーメッセージにヒントを追加 const errorMsg = result.message || "Tool execution failed"; const enrichedError = enrichErrorWithHints(errorMsg); responseText = `❌ ${enrichedError}`; if (result.data) { responseText += `\n\nDetails:\n${JSON.stringify(result.data, null, 2)}`; } } return { content: [ { type: "text", text: responseText, }, ], }; } catch (error) { const errorMsg = error instanceof Error ? error.message : String(error); const errorStack = error instanceof Error ? error.stack : undefined; const exceptionMessage = `Tool execution failed with exception: ${errorMsg}${errorStack ? `\n\nStack trace:\n${errorStack}` : ""}`; return { content: [ { type: "text", text: `❌ ${exceptionMessage}`, }, ], }; } } ); });