tossItem
Remove specific items from your Minecraft inventory by remotely commanding players to throw them, managing storage and item counts efficiently.
Instructions
Throw items from inventory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | No | Amount of items to throw | |
| itemName | Yes | Name of the item to throw |
Implementation Reference
- src/tools/inventoryManagement.ts:145-169 (handler)Handler function that locates the specified item in the bot's inventory and tosses the requested amount using bot.toss, with error handling for connection and missing items.async ({ itemName, amount }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Find the item in inventory const item = botState.bot.inventory .items() .find((item) => item.name.toLowerCase() === itemName.toLowerCase()) if (!item) { return createSuccessResponse( `Item "${itemName}" not found in inventory.` ) } // Since tossItem doesn't exist in the API, we have a few alternatives: // 1. Drop the item at the bot's current position await botState.bot.toss(item.type, null, amount) return createSuccessResponse(`Successfully threw ${amount} ${itemName}`) } catch (error) { return createErrorResponse(error) } }
- Zod input schema defining parameters for the tossItem tool: itemName (required string) and amount (optional number, defaults to 1).{ itemName: z.string().describe('Name of the item to throw'), amount: z .number() .optional() .default(1) .describe('Amount of items to throw'), },
- src/tools/inventoryManagement.ts:134-170 (registration)Registration of the tossItem MCP tool using server.tool, including name, description, schema, and handler within the registerInventoryManagementTools function.server.tool( 'tossItem', 'Throw items from inventory', { itemName: z.string().describe('Name of the item to throw'), amount: z .number() .optional() .default(1) .describe('Amount of items to throw'), }, async ({ itemName, amount }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Find the item in inventory const item = botState.bot.inventory .items() .find((item) => item.name.toLowerCase() === itemName.toLowerCase()) if (!item) { return createSuccessResponse( `Item "${itemName}" not found in inventory.` ) } // Since tossItem doesn't exist in the API, we have a few alternatives: // 1. Drop the item at the bot's current position await botState.bot.toss(item.type, null, amount) return createSuccessResponse(`Successfully threw ${amount} ${itemName}`) } catch (error) { return createErrorResponse(error) } } )