Skip to main content
Glama

withdrawItem

Take items from an open container in Minecraft by specifying the item name and quantity, enabling inventory management through natural language commands.

Instructions

Take items from an open container

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
itemNameYesName of the item to withdraw
amountNoAmount of items to withdraw

Implementation Reference

  • The asynchronous handler function that implements the core logic of the 'withdrawItem' tool. It checks for connection and open container, finds matching items by name, withdraws the specified amount from container slots using container.withdraw(), and returns success or error responses.
    if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Check if a container is open if (!botState.currentContainer) { return createSuccessResponse( 'No container is currently open. Use openContainer first.' ) } // Find the item in the container const container = botState.currentContainer const matchingItems = container.slots .filter((item): item is NonNullable<typeof item> => Boolean( item !== null && item.name && item.name.toLowerCase() === itemName.toLowerCase() ) ) .map((item, slotIndex) => ({ item, slotIndex })) if (matchingItems.length === 0) { return createSuccessResponse( `Item "${itemName}" not found in the container.` ) } // Calculate how many items to withdraw let remainingAmount = amount let withdrawnAmount = 0 // Withdraw items from each matching slot until we have enough for (const { item, slotIndex } of matchingItems) { if (remainingAmount <= 0) break const amountFromThisSlot = Math.min(remainingAmount, item.count) // In mineflayer, withdraw takes itemType, metadata, count await container.withdraw(item.type, null, amountFromThisSlot) remainingAmount -= amountFromThisSlot withdrawnAmount += amountFromThisSlot } return createSuccessResponse( `Withdrew ${withdrawnAmount} x ${itemName} from the container.` ) } catch (error) { return createErrorResponse(error) } } )
  • Zod schema defining the input parameters for the 'withdrawItem' tool: 'itemName' (string, name of item to withdraw) and 'amount' (optional number, defaults to 1).
    itemName: z.string().describe('Name of the item to withdraw'), amount: z .number() .optional() .default(1) .describe('Amount of items to withdraw'), }, async ({ itemName, amount }) => {
  • Registration of the 'withdrawItem' tool via server.tool(), specifying the tool name, description 'Take items from an open container', input schema, and handler function.
    'withdrawItem', 'Take items from an open container', { itemName: z.string().describe('Name of the item to withdraw'), amount: z .number() .optional() .default(1) .describe('Amount of items to withdraw'), }, async ({ itemName, amount }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Check if a container is open if (!botState.currentContainer) { return createSuccessResponse( 'No container is currently open. Use openContainer first.' ) } // Find the item in the container const container = botState.currentContainer const matchingItems = container.slots .filter((item): item is NonNullable<typeof item> => Boolean( item !== null && item.name && item.name.toLowerCase() === itemName.toLowerCase() ) ) .map((item, slotIndex) => ({ item, slotIndex })) if (matchingItems.length === 0) { return createSuccessResponse( `Item "${itemName}" not found in the container.` ) } // Calculate how many items to withdraw let remainingAmount = amount let withdrawnAmount = 0 // Withdraw items from each matching slot until we have enough for (const { item, slotIndex } of matchingItems) { if (remainingAmount <= 0) break const amountFromThisSlot = Math.min(remainingAmount, item.count) // In mineflayer, withdraw takes itemType, metadata, count await container.withdraw(item.type, null, amountFromThisSlot) remainingAmount -= amountFromThisSlot withdrawnAmount += amountFromThisSlot } return createSuccessResponse( `Withdrew ${withdrawnAmount} x ${itemName} from the container.` ) } catch (error) { return createErrorResponse(error) } } ) // Tool to deposit items to a container server.tool(

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