attackEntity
Target and attack a specific entity in Minecraft using its entity ID with the MCP Minecraft Remote server, enabling precise control for AI-assisted gameplay.
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)Executes the attackEntity tool: validates connection, locates entity by ID, performs bot.attack(entity), returns success with entity info 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.`) } // 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)Zod input schema defining entityId as a required number parameter.{ entityId: z.number().describe('ID of the entity to attack'), },
- src/tools/entityInteraction.ts:81-110 (registration)Registers the attackEntity tool on the MCP server with name, description, input schema, and handler function.server.tool( '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) } } )
- src/tools/index.ts:35-35 (registration)Invocation of registerEntityInteractionTools() within registerAllTools(), which includes the attackEntity tool registration.registerEntityInteractionTools()
- src/index.ts:7-7 (registration)Top-level call to registerAllTools() during server initialization, indirectly registering attackEntity.registerAllTools()