attackEntity
Attack a specific entity in Minecraft by targeting its unique ID. Use this tool to interact with mobs or other players through the MCP Minecraft Remote server.
Instructions
Attack a specific entity
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entityId | Yes | ID of the entity to attack |
Implementation Reference
- src/tools/entityInteraction.ts:87-109 (handler)The handler function that implements the core logic of the attackEntity tool: validates connection, retrieves entity by ID, performs the attack using botState.bot.attack(entity), handles errors, and returns success or error responses.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.`) } // Attack the entity await botState.bot.attack(entity) return createSuccessResponse( `Attacked entity: ${ entity.name || entity.username || 'Unknown entity' } (ID: ${entityId})` ) } catch (error) { return createErrorResponse(error) } }
- src/tools/entityInteraction.ts:84-86 (schema)Input schema using Zod for validating the entityId parameter as a number.{ entityId: z.number().describe('ID of the entity to attack'), },
- src/tools/entityInteraction.ts:82-110 (registration)The server.tool call that registers the attackEntity tool, including its description, input schema, and handler function. This is invoked within the registerEntityInteractionTools function.'attackEntity', 'Attack a specific entity', { entityId: z.number().describe('ID of the entity to attack'), }, 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.`) } // Attack the entity await botState.bot.attack(entity) return createSuccessResponse( `Attacked entity: ${ entity.name || entity.username || 'Unknown entity' } (ID: ${entityId})` ) } catch (error) { return createErrorResponse(error) } } )