Skip to main content
Glama

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
NameRequiredDescriptionDefault
filterNoFilter recipes by item name

Implementation Reference

  • 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)
      }
    }
  • Input schema for the getRecipes tool using Zod, defining an optional 'filter' string parameter.
    {
      filter: z.string().optional().describe('Filter recipes by item name'),
    },
  • 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)
        }
      }
    )
  • Invocation of registerCraftingTools() within registerAllTools(), which registers the getRecipes tool among others.
    registerCraftingTools()

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/nacal/mcp-minecraft-remote'

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