Skip to main content
Glama

openContainer

Access containers like chests or furnaces at specific coordinates in Minecraft to manage inventory and retrieve items.

Instructions

Open a container (chest, furnace, etc.) at specific coordinates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xYesX coordinate of the container
yYesY coordinate of the container
zYesZ coordinate of the container

Implementation Reference

  • Executes the openContainer tool: checks bot connection, retrieves block at (x,y,z), validates it as a container type (chest, furnace, etc.), opens the container using bot.openContainer, stores it in botState.currentContainer, inventories non-null slots mapping to name/count/slot, formats response with contents list.
    async ({ x, y, z }) => {
      if (!botState.isConnected || !botState.bot) {
        return createNotConnectedResponse()
      }
    
      try {
        // Get the block at the coordinates
        const block = botState.bot.blockAt(new Vec3(x, y, z))
    
        if (!block) {
          return createSuccessResponse(
            `No block found at coordinates X=${x}, Y=${y}, Z=${z}`
          )
        }
    
        // Check if the block is a container
        if (
          !block.name.includes('chest') &&
          !block.name.includes('furnace') &&
          !block.name.includes('barrel') &&
          !block.name.includes('shulker') &&
          !block.name.includes('dispenser') &&
          !block.name.includes('dropper') &&
          !block.name.includes('hopper')
        ) {
          return createSuccessResponse(
            `Block at X=${x}, Y=${y}, Z=${z} is not a container (found: ${block.name})`
          )
        }
    
        // Open the container
        const container = await botState.bot.openContainer(block)
    
        // Store container reference as our Container type with withdraw/deposit methods
        botState.currentContainer = container as unknown as Container
    
        // Get container contents
        const items = container.slots
          .filter((item): item is NonNullable<typeof item> => item !== null)
          .map((item) => {
            if (!item) return null
            return {
              name: item.name,
              displayName: item.displayName || item.name,
              count: item.count || 1,
              slot: container.slots.indexOf(item),
            }
          })
          .filter((item) => item !== null)
    
        // Format the response
        let response = `Opened ${block.name} at X=${x}, Y=${y}, Z=${z}\n\n`
    
        if (items.length === 0) {
          response += 'Container is empty.'
        } else {
          response += `Container contains ${items.length} items:\n`
          items.forEach((item) => {
            response += `- ${item.displayName} (x${item.count}) in slot ${item.slot}\n`
          })
        }
    
        return createSuccessResponse(response)
      } catch (error) {
        return createErrorResponse(error)
      }
    }
  • Zod input schema for openContainer tool defining required numeric parameters x, y, z coordinates with descriptions.
    {
      x: z.number().describe('X coordinate of the container'),
      y: z.number().describe('Y coordinate of the container'),
      z: z.number().describe('Z coordinate of the container'),
    },
  • Registers the openContainer tool via server.tool call, specifying name, description, input schema, and handler function.
    server.tool(
      'openContainer',
      'Open a container (chest, furnace, etc.) at specific coordinates',
      {
        x: z.number().describe('X coordinate of the container'),
        y: z.number().describe('Y coordinate of the container'),
        z: z.number().describe('Z coordinate of the container'),
      },
      async ({ x, y, z }) => {
        if (!botState.isConnected || !botState.bot) {
          return createNotConnectedResponse()
        }
    
        try {
          // Get the block at the coordinates
          const block = botState.bot.blockAt(new Vec3(x, y, z))
    
          if (!block) {
            return createSuccessResponse(
              `No block found at coordinates X=${x}, Y=${y}, Z=${z}`
            )
          }
    
          // Check if the block is a container
          if (
            !block.name.includes('chest') &&
            !block.name.includes('furnace') &&
            !block.name.includes('barrel') &&
            !block.name.includes('shulker') &&
            !block.name.includes('dispenser') &&
            !block.name.includes('dropper') &&
            !block.name.includes('hopper')
          ) {
            return createSuccessResponse(
              `Block at X=${x}, Y=${y}, Z=${z} is not a container (found: ${block.name})`
            )
          }
    
          // Open the container
          const container = await botState.bot.openContainer(block)
    
          // Store container reference as our Container type with withdraw/deposit methods
          botState.currentContainer = container as unknown as Container
    
          // Get container contents
          const items = container.slots
            .filter((item): item is NonNullable<typeof item> => item !== null)
            .map((item) => {
              if (!item) return null
              return {
                name: item.name,
                displayName: item.displayName || item.name,
                count: item.count || 1,
                slot: container.slots.indexOf(item),
              }
            })
            .filter((item) => item !== null)
    
          // Format the response
          let response = `Opened ${block.name} at X=${x}, Y=${y}, Z=${z}\n\n`
    
          if (items.length === 0) {
            response += 'Container is empty.'
          } else {
            response += `Container contains ${items.length} items:\n`
            items.forEach((item) => {
              response += `- ${item.displayName} (x${item.count}) in slot ${item.slot}\n`
            })
          }
    
          return createSuccessResponse(response)
        } catch (error) {
          return createErrorResponse(error)
        }
      }
    )
  • Invokes registerContainerInteractionTools() within registerAllTools(), thereby registering the openContainer tool.
    registerContainerInteractionTools()

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