Skip to main content
Glama

useOnEntity

Apply a held item to a specific entity in Minecraft by providing its entity ID, enabling targeted interactions like feeding animals or activating mechanisms.

Instructions

Use held item on a specific entity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entityIdYesID of the entity to use item on

Implementation Reference

  • Executes the 'useOnEntity' tool: validates connection, retrieves entity by ID, uses the bot's held item on the entity via bot.useOn(entity), and returns success or error response.
    async ({ entityId }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Find the entity by ID const entity = botState.bot.entities[entityId] if (!entity) { return createSuccessResponse(`Entity with ID ${entityId} not found.`) } // Use current item on the entity await botState.bot.useOn(entity) const heldItem = botState.bot.heldItem ? botState.bot.heldItem.name : 'hand' return createSuccessResponse( `Used ${heldItem} on entity: ${ entity.name || entity.username || 'Unknown entity' } (ID: ${entityId})` ) } catch (error) { return createErrorResponse(error) } } )
  • Zod input schema for 'useOnEntity' tool defining the required entityId parameter.
    { entityId: z.number().describe('ID of the entity to use item on'), },
  • Registers the 'useOnEntity' MCP tool with server.tool, providing name, description, input schema, and handler function.
    server.tool( 'useOnEntity', 'Use held item on a specific entity', { entityId: z.number().describe('ID of the entity to use item on'), }, async ({ entityId }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Find the entity by ID const entity = botState.bot.entities[entityId] if (!entity) { return createSuccessResponse(`Entity with ID ${entityId} not found.`) } // Use current item on the entity await botState.bot.useOn(entity) const heldItem = botState.bot.heldItem ? botState.bot.heldItem.name : 'hand' return createSuccessResponse( `Used ${heldItem} on entity: ${ entity.name || entity.username || 'Unknown entity' } (ID: ${entityId})` ) } catch (error) { return createErrorResponse(error) } } )
  • Top-level registration call within registerAllTools() that invokes the entity interaction tools registration, including 'useOnEntity'.
    registerEntityInteractionTools()
  • src/index.ts:7-7 (registration)
    Ultimate registration point calling registerAllTools(), which chains to 'useOnEntity' tool registration.
    registerAllTools()

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