depositItem
Store items into an open Minecraft container by specifying the item name and quantity. Use this tool for efficient inventory management in remote Minecraft servers via MCP.
Instructions
Put items into an open container
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | No | Amount of items to deposit | |
| itemName | Yes | Name of the item to deposit |
Implementation Reference
- Handler function that executes the depositItem tool logic: checks connection and open container, finds matching items in inventory, deposits the specified amount into the container using deposit method.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 inventory const matchingItems = botState.bot.inventory .items() .filter( (item) => item !== null && item.name && item.name.toLowerCase() === itemName.toLowerCase() ) if (matchingItems.length === 0) { return createSuccessResponse( `Item "${itemName}" not found in your inventory.` ) } // Calculate how many items to deposit let remainingAmount = amount let depositedAmount = 0 // Deposit items from each matching slot until we've deposited enough for (const item of matchingItems) { if (remainingAmount <= 0) break const amountFromThisItem = Math.min(remainingAmount, item.count) // Ensure item.type exists if (typeof item.type !== 'number') { continue // Skip this item if type is not available } await botState.currentContainer.deposit( item.type, null, amountFromThisItem ) remainingAmount -= amountFromThisItem depositedAmount += amountFromThisItem } return createSuccessResponse( `Deposited ${depositedAmount} x ${itemName} into the container.` ) } catch (error) { return createErrorResponse(error) } }
- Input schema using Zod for the depositItem tool parameters: itemName (required string) and amount (optional number, defaults to 1).{ itemName: z.string().describe('Name of the item to deposit'), amount: z .number() .optional() .default(1) .describe('Amount of items to deposit'), },
- src/tools/containerInteraction.ts:161-233 (registration)Registration of the depositItem tool via server.tool(), specifying name, description, input schema, and inline handler function.server.tool( 'depositItem', 'Put items into an open container', { itemName: z.string().describe('Name of the item to deposit'), amount: z .number() .optional() .default(1) .describe('Amount of items to deposit'), }, 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 inventory const matchingItems = botState.bot.inventory .items() .filter( (item) => item !== null && item.name && item.name.toLowerCase() === itemName.toLowerCase() ) if (matchingItems.length === 0) { return createSuccessResponse( `Item "${itemName}" not found in your inventory.` ) } // Calculate how many items to deposit let remainingAmount = amount let depositedAmount = 0 // Deposit items from each matching slot until we've deposited enough for (const item of matchingItems) { if (remainingAmount <= 0) break const amountFromThisItem = Math.min(remainingAmount, item.count) // Ensure item.type exists if (typeof item.type !== 'number') { continue // Skip this item if type is not available } await botState.currentContainer.deposit( item.type, null, amountFromThisItem ) remainingAmount -= amountFromThisItem depositedAmount += amountFromThisItem } return createSuccessResponse( `Deposited ${depositedAmount} x ${itemName} into the container.` ) } catch (error) { return createErrorResponse(error) } } )
- src/tools/index.ts:38-38 (registration)Invocation of registerContainerInteractionTools() which registers the depositItem tool among others.registerContainerInteractionTools()