getRecipes
Retrieve Minecraft crafting recipes from a remote server to find item recipes and crafting instructions for in-game use.
Instructions
Get a list of available crafting recipes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | Filter recipes by item name |
Implementation Reference
- src/tools/crafting.ts:18-90 (handler)Handler function that fetches crafting recipes using the mineflayer bot's recipesFor method, groups them by output item, formats a detailed response, and handles errors or no-connection states.async ({ filter }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // In mineflayer API, first parameter should be itemType (number), not filter string // Using a regex match or 0 as a wildcard for all items const itemType = filter ? 0 : 0 // 0 is used as a wildcard const recipes = botState.bot.recipesFor(itemType, null, null, null) if (recipes.length === 0) { return createSuccessResponse( filter ? `No recipes found for "${filter}".` : 'No recipes available.' ) } // Group recipes by output item type RecipeGroups = Record<string, Array<any>> const groupedRecipes: RecipeGroups = {} recipes.forEach((recipe) => { const outputName = recipe.result && typeof recipe.result === 'object' && 'name' in recipe.result ? recipe.result.name : 'Unknown' // Use type assertion to help TypeScript understand the key is valid const key = outputName as string if (!groupedRecipes[key]) { groupedRecipes[key] = [] } groupedRecipes[key].push(recipe) }) // Format the response let response = filter ? `Available recipes for "${filter}":\n\n` : `Available recipes (${recipes.length}):\n\n` for (const [output, recipes] of Object.entries(groupedRecipes)) { response += `${output} (${recipes.length} recipe${ recipes.length > 1 ? 's' : '' }):\n` recipes.forEach((recipe, index) => { response += ` Recipe ${index + 1}:\n` // Add ingredients if ( recipe.ingredients && Array.isArray(recipe.ingredients) && recipe.ingredients.length > 0 ) { response += ' Ingredients:\n' recipe.ingredients.forEach((item: any) => { const count = item.count || 1 response += ` - ${item.name} x${count}\n` }) } response += '\n' }) } return createSuccessResponse(response) } catch (error) { return createErrorResponse(error) } }
- src/tools/crafting.ts:15-17 (schema)Input schema for the getRecipes tool using Zod, defining an optional 'filter' string parameter.{ filter: z.string().optional().describe('Filter recipes by item name'), },
- src/tools/crafting.ts:13-91 (registration)Direct registration of the 'getRecipes' tool on the server using server.tool, specifying name, description, input schema, and inline handler.'getRecipes', 'Get a list of available crafting recipes', { filter: z.string().optional().describe('Filter recipes by item name'), }, async ({ filter }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // In mineflayer API, first parameter should be itemType (number), not filter string // Using a regex match or 0 as a wildcard for all items const itemType = filter ? 0 : 0 // 0 is used as a wildcard const recipes = botState.bot.recipesFor(itemType, null, null, null) if (recipes.length === 0) { return createSuccessResponse( filter ? `No recipes found for "${filter}".` : 'No recipes available.' ) } // Group recipes by output item type RecipeGroups = Record<string, Array<any>> const groupedRecipes: RecipeGroups = {} recipes.forEach((recipe) => { const outputName = recipe.result && typeof recipe.result === 'object' && 'name' in recipe.result ? recipe.result.name : 'Unknown' // Use type assertion to help TypeScript understand the key is valid const key = outputName as string if (!groupedRecipes[key]) { groupedRecipes[key] = [] } groupedRecipes[key].push(recipe) }) // Format the response let response = filter ? `Available recipes for "${filter}":\n\n` : `Available recipes (${recipes.length}):\n\n` for (const [output, recipes] of Object.entries(groupedRecipes)) { response += `${output} (${recipes.length} recipe${ recipes.length > 1 ? 's' : '' }):\n` recipes.forEach((recipe, index) => { response += ` Recipe ${index + 1}:\n` // Add ingredients if ( recipe.ingredients && Array.isArray(recipe.ingredients) && recipe.ingredients.length > 0 ) { response += ' Ingredients:\n' recipe.ingredients.forEach((item: any) => { const count = item.count || 1 response += ` - ${item.name} x${count}\n` }) } response += '\n' }) } return createSuccessResponse(response) } catch (error) { return createErrorResponse(error) } } )
- src/tools/index.ts:39-39 (registration)Invocation of registerCraftingTools() within registerAllTools(), which registers the getRecipes tool among others.registerCraftingTools()