craftItem
Craft items in Minecraft using available materials. Specify the item name and quantity to create items through the MCP Minecraft Remote server.
Instructions
Craft an item using available materials
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| itemName | Yes | Name of the item to craft | |
| count | No | Number of items to craft |
Implementation Reference
- src/tools/crafting.ts:106-135 (handler)Executes the craftItem tool: finds recipes using wildcard itemType=0, selects first recipe, crafts using bot.craft if possible, handles errors.if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // For crafting, we need to get the itemType from a name lookup or approximate it // This is a simple workaround - ideally, we'd have a proper mapping of names to IDs const itemType = 0 // Using 0 as a wildcard to get all recipes const recipes = botState.bot.recipesFor(itemType, null, count, null) if (recipes.length === 0) { return createSuccessResponse( `No recipes found for "${itemName}" or insufficient materials.` ) } // Choose the first available recipe const recipe = recipes[0] // Craft the item await botState.bot.craft(recipe, count) return createSuccessResponse( `Successfully crafted ${count} x ${itemName}` ) } catch (error) { return createErrorResponse(error) } } )
- src/tools/crafting.ts:98-105 (schema)Input schema using Zod for craftItem tool parameters.itemName: z.string().describe('Name of the item to craft'), count: z .number() .optional() .default(1) .describe('Number of items to craft'), }, async ({ itemName, count }) => {
- src/tools/crafting.ts:95-135 (registration)Direct registration of the craftItem tool using server.tool including schema and handler.'craftItem', 'Craft an item using available materials', { itemName: z.string().describe('Name of the item to craft'), count: z .number() .optional() .default(1) .describe('Number of items to craft'), }, async ({ itemName, count }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // For crafting, we need to get the itemType from a name lookup or approximate it // This is a simple workaround - ideally, we'd have a proper mapping of names to IDs const itemType = 0 // Using 0 as a wildcard to get all recipes const recipes = botState.bot.recipesFor(itemType, null, count, null) if (recipes.length === 0) { return createSuccessResponse( `No recipes found for "${itemName}" or insufficient materials.` ) } // Choose the first available recipe const recipe = recipes[0] // Craft the item await botState.bot.craft(recipe, count) return createSuccessResponse( `Successfully crafted ${count} x ${itemName}` ) } catch (error) { return createErrorResponse(error) } } )
- src/tools/index.ts:39-39 (registration)Higher-level registration call to registerCraftingTools() which registers craftItem among other crafting tools.registerCraftingTools()