Skip to main content
Glama
zeeweebee

Minecraft MCP Server

by zeeweebee

find-entity

Locate the nearest entity of a specified type within Minecraft, with adjustable search distance parameters for precise targeting.

Instructions

Find the nearest entity of a specific type

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeNoType of entity to find (empty for any entity)
maxDistanceNoMaximum search distance (default: 16)

Implementation Reference

  • Handler function that implements the 'find-entity' tool logic: filters entities by type, finds the nearest one within maxDistance using bot.nearestEntity, and returns its position.
    async ({ type = '', maxDistance = 16 }): Promise<McpResponse> => {
      try {
        const entityFilter = (entity: any) => {
          if (!type) return true;
          if (type === 'player') return entity.type === 'player';
          if (type === 'mob') return entity.type === 'mob';
          return entity.name && entity.name.includes(type.toLowerCase());
        };
    
        const entity = bot.nearestEntity(entityFilter);
    
        if (!entity || bot.entity.position.distanceTo(entity.position) > maxDistance) {
          return createResponse(`No ${type || 'entity'} found within ${maxDistance} blocks`);
        }
    
        return createResponse(`Found ${entity.name || (entity as any).username || entity.type} at position (${Math.floor(entity.position.x)}, ${Math.floor(entity.position.y)}, ${Math.floor(entity.position.z)})`);
      } catch (error) {
        return createErrorResponse(error as Error);
      }
    }
  • Input schema for the 'find-entity' tool using Zod: optional type (string) and maxDistance (number).
    {
      type: z.string().optional().describe("Type of entity to find (empty for any entity)"),
      maxDistance: z.number().optional().describe("Maximum search distance (default: 16)")
    },
  • src/bot.ts:499-528 (registration)
    Registration of the 'find-entity' tool via server.tool() inside the registerEntityTools function.
    function registerEntityTools(server: McpServer, bot: any) {
      server.tool(
        "find-entity",
        "Find the nearest entity of a specific type",
        {
          type: z.string().optional().describe("Type of entity to find (empty for any entity)"),
          maxDistance: z.number().optional().describe("Maximum search distance (default: 16)")
        },
        async ({ type = '', maxDistance = 16 }): Promise<McpResponse> => {
          try {
            const entityFilter = (entity: any) => {
              if (!type) return true;
              if (type === 'player') return entity.type === 'player';
              if (type === 'mob') return entity.type === 'mob';
              return entity.name && entity.name.includes(type.toLowerCase());
            };
    
            const entity = bot.nearestEntity(entityFilter);
    
            if (!entity || bot.entity.position.distanceTo(entity.position) > maxDistance) {
              return createResponse(`No ${type || 'entity'} found within ${maxDistance} blocks`);
            }
    
            return createResponse(`Found ${entity.name || (entity as any).username || entity.type} at position (${Math.floor(entity.position.x)}, ${Math.floor(entity.position.y)}, ${Math.floor(entity.position.z)})`);
          } catch (error) {
            return createErrorResponse(error as Error);
          }
        }
      );
    }

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/zeeweebee/mcp-server'

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