Skip to main content
Glama

mcp-minecraft

inventory-tools.ts2.41 kB
import { z } from "zod"; import mineflayer from 'mineflayer'; import { ToolFactory } from '../tool-factory.js'; interface InventoryItem { name: string; count: number; slot: number; } export function registerInventoryTools(factory: ToolFactory, getBot: () => mineflayer.Bot): void { factory.registerTool( "list-inventory", "List all items in the bot's inventory", {}, async () => { const bot = getBot(); const items = bot.inventory.items(); const itemList: InventoryItem[] = items.map((item) => ({ name: item.name, count: item.count, slot: item.slot })); if (items.length === 0) { return factory.createResponse("Inventory is empty"); } let inventoryText = `Found ${items.length} items in inventory:\n\n`; itemList.forEach(item => { inventoryText += `- ${item.name} (x${item.count}) in slot ${item.slot}\n`; }); return factory.createResponse(inventoryText); } ); factory.registerTool( "find-item", "Find a specific item in the bot's inventory", { nameOrType: z.string().describe("Name or type of item to find") }, async ({ nameOrType }) => { const bot = getBot(); const items = bot.inventory.items(); const item = items.find((item) => item.name.includes(nameOrType.toLowerCase()) ); if (item) { return factory.createResponse(`Found ${item.count} ${item.name} in inventory (slot ${item.slot})`); } else { return factory.createResponse(`Couldn't find any item matching '${nameOrType}' in inventory`); } } ); factory.registerTool( "equip-item", "Equip a specific item", { itemName: z.string().describe("Name of the item to equip"), destination: z.string().optional().describe("Where to equip the item (default: 'hand')") }, async ({ itemName, destination = 'hand' }) => { const bot = getBot(); const items = bot.inventory.items(); const item = items.find((item) => item.name.includes(itemName.toLowerCase()) ); if (!item) { return factory.createResponse(`Couldn't find any item matching '${itemName}' in inventory`); } await bot.equip(item, destination as mineflayer.EquipmentDestination); return factory.createResponse(`Equipped ${item.name} to ${destination}`); } ); }

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/yuniko-software/minecraft-mcp-server'

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