Skip to main content
Glama

getNearbyEntities

Retrieve a list of all entities within a specified range in Minecraft. Ideal for tracking mobs, players, or objects nearby, enabling precise entity interaction and navigation on MCP Minecraft Remote servers.

Instructions

Get a list of all entities nearby

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rangeNoRange in blocks to search for entities

Implementation Reference

  • The main handler function for the 'getNearbyEntities' tool. It filters nearby entities based on distance from the bot, groups them by type, calculates distances, and returns a formatted string listing the entities.
    async ({ range }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Get all entities within range const nearbyEntities = Object.values(botState.bot.entities).filter( (entity) => { if (!entity || !entity.position || !botState.bot) return false const distance = entity.position.distanceTo( botState.bot.entity.position ) return distance <= range && entity.id !== botState.bot.entity.id } ) if (nearbyEntities.length === 0) { return createSuccessResponse('No entities found nearby.') } // Group entities by type const groupedEntities: Record<string, any[]> = {} nearbyEntities.forEach((entity) => { const type = String(entity.type || 'unknown') if (!groupedEntities[type]) { groupedEntities[type] = [] } groupedEntities[type].push(entity) }) // Format the response let response = `Entities within ${range} blocks:\n\n` for (const [type, entities] of Object.entries(groupedEntities)) { response += `${type.toUpperCase()} (${entities.length}):\n` entities.forEach((entity: any) => { const distance = entity.position .distanceTo(botState.bot!.entity.position) .toFixed(1) const name = entity.name || entity.username || entity.displayName || `Entity #${entity.id}` response += `- ${name} (${distance} blocks away, ID: ${entity.id})\n` }) response += '\n' } return createSuccessResponse(response) } catch (error) { return createErrorResponse(error) } }
  • Zod schema defining the input parameter 'range' (optional number, default 10) for searching nearby entities.
    { range: z .number() .optional() .default(10) .describe('Range in blocks to search for entities'), },
  • Registration of the 'getNearbyEntities' tool using server.tool(), including name, description, schema, and handler.
    'getNearbyEntities', 'Get a list of all entities nearby', { range: z .number() .optional() .default(10) .describe('Range in blocks to search for entities'), }, async ({ range }) => { if (!botState.isConnected || !botState.bot) { return createNotConnectedResponse() } try { // Get all entities within range const nearbyEntities = Object.values(botState.bot.entities).filter( (entity) => { if (!entity || !entity.position || !botState.bot) return false const distance = entity.position.distanceTo( botState.bot.entity.position ) return distance <= range && entity.id !== botState.bot.entity.id } ) if (nearbyEntities.length === 0) { return createSuccessResponse('No entities found nearby.') } // Group entities by type const groupedEntities: Record<string, any[]> = {} nearbyEntities.forEach((entity) => { const type = String(entity.type || 'unknown') if (!groupedEntities[type]) { groupedEntities[type] = [] } groupedEntities[type].push(entity) }) // Format the response let response = `Entities within ${range} blocks:\n\n` for (const [type, entities] of Object.entries(groupedEntities)) { response += `${type.toUpperCase()} (${entities.length}):\n` entities.forEach((entity: any) => { const distance = entity.position .distanceTo(botState.bot!.entity.position) .toFixed(1) const name = entity.name || entity.username || entity.displayName || `Entity #${entity.id}` response += `- ${name} (${distance} blocks away, ID: ${entity.id})\n` }) response += '\n' } return createSuccessResponse(response) } catch (error) { return createErrorResponse(error) } } )
  • Top-level registration call to registerEntityInteractionTools(), which includes the 'getNearbyEntities' tool, as part of registerAllTools().
    registerEntityInteractionTools()

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