find-block
Locate the nearest block of a specified type within a defined distance in Minecraft. Ideal for real-time exploration and structure building using the mcp-minecraft server.
Instructions
Find the nearest block of a specific type
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockType | Yes | Type of block to find | |
| maxDistance | No | Maximum search distance (default: 16) |
Implementation Reference
- src/tools/block-tools.ts:126-155 (registration)Registers the "find-block" MCP tool with its description, input schema using Zod, and inline asynchronous handler function that uses the bot to find the nearest block of the specified type within maxDistance.factory.registerTool( "find-block", "Find the nearest block of a specific type", { blockType: z.string().describe("Type of block to find"), maxDistance: z.number().optional().describe("Maximum search distance (default: 16)") }, async ({ blockType, maxDistance = 16 }) => { const bot = getBot(); const mcData = minecraftData(bot.version); const blocksByName = mcData.blocksByName; if (!blocksByName[blockType]) { return factory.createResponse(`Unknown block type: ${blockType}`); } const blockId = blocksByName[blockType].id; const block = bot.findBlock({ matching: blockId, maxDistance: maxDistance }); if (!block) { return factory.createResponse(`No ${blockType} found within ${maxDistance} blocks`); } return factory.createResponse(`Found ${blockType} at position (${block.position.x}, ${block.position.y}, ${block.position.z})`); } );
- src/tools/block-tools.ts:133-154 (handler)The handler function for the "find-block" tool. It retrieves the bot, looks up the block ID using minecraft-data, finds the nearest block using bot.findBlock, and returns the position or an error message.async ({ blockType, maxDistance = 16 }) => { const bot = getBot(); const mcData = minecraftData(bot.version); const blocksByName = mcData.blocksByName; if (!blocksByName[blockType]) { return factory.createResponse(`Unknown block type: ${blockType}`); } const blockId = blocksByName[blockType].id; const block = bot.findBlock({ matching: blockId, maxDistance: maxDistance }); if (!block) { return factory.createResponse(`No ${blockType} found within ${maxDistance} blocks`); } return factory.createResponse(`Found ${blockType} at position (${block.position.x}, ${block.position.y}, ${block.position.z})`); }
- src/tools/block-tools.ts:129-132 (schema)Zod schema defining the input parameters for the "find-block" tool: blockType (required string) and maxDistance (optional number, default 16).{ blockType: z.string().describe("Type of block to find"), maxDistance: z.number().optional().describe("Maximum search distance (default: 16)") },