fly-to
Move a Minecraft bot to a specific in-game position by specifying X, Y, and Z coordinates, enabling precise navigation within the MCP Server environment.
Instructions
Make the bot fly to a specific position
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x | Yes | X coordinate | |
| y | Yes | Y coordinate | |
| z | Yes | Z coordinate |
Implementation Reference
- src/bot.ts:561-599 (handler)The handler function for the 'fly-to' tool. It checks for creative mode, sets up a timeout and abort controller, flies to the target position using bot.creative.flyTo via a helper, handles errors and timeouts, and ensures flying is stopped.async ({ x, y, z }): Promise<McpResponse> => { if (!bot.creative) { return createResponse("Creative mode is not available. Cannot fly."); } const currentPos = bot.entity.position; console.error(`Flying from (${Math.floor(currentPos.x)}, ${Math.floor(currentPos.y)}, ${Math.floor(currentPos.z)}) to (${Math.floor(x)}, ${Math.floor(y)}, ${Math.floor(z)})`); const controller = new AbortController(); const FLIGHT_TIMEOUT_MS = 20000; const timeoutId = setTimeout(() => { if (!controller.signal.aborted) { controller.abort(); } }, FLIGHT_TIMEOUT_MS); try { const destination = new Vec3(x, y, z); await createCancellableFlightOperation(bot, destination, controller); return createResponse(`Successfully flew to position (${x}, ${y}, ${z}).`); } catch (error) { if (controller.signal.aborted) { const currentPosAfterTimeout = bot.entity.position; return createErrorResponse( `Flight timed out after ${FLIGHT_TIMEOUT_MS/1000} seconds. The destination may be unreachable. ` + `Current position: (${Math.floor(currentPosAfterTimeout.x)}, ${Math.floor(currentPosAfterTimeout.y)}, ${Math.floor(currentPosAfterTimeout.z)})` ); } console.error('Flight error:', error); return createErrorResponse(error as Error); } finally { clearTimeout(timeoutId); bot.creative.stopFlying(); } }
- src/bot.ts:556-560 (schema)Input schema for the 'fly-to' tool using Zod, requiring numeric x, y, z coordinates.{ x: z.number().describe("X coordinate"), y: z.number().describe("Y coordinate"), z: z.number().describe("Z coordinate") },
- src/bot.ts:553-600 (registration)The MCP server.tool registration for the 'fly-to' tool, including name, description, schema, and handler reference.server.tool( "fly-to", "Make the bot fly to a specific position", { x: z.number().describe("X coordinate"), y: z.number().describe("Y coordinate"), z: z.number().describe("Z coordinate") }, async ({ x, y, z }): Promise<McpResponse> => { if (!bot.creative) { return createResponse("Creative mode is not available. Cannot fly."); } const currentPos = bot.entity.position; console.error(`Flying from (${Math.floor(currentPos.x)}, ${Math.floor(currentPos.y)}, ${Math.floor(currentPos.z)}) to (${Math.floor(x)}, ${Math.floor(y)}, ${Math.floor(z)})`); const controller = new AbortController(); const FLIGHT_TIMEOUT_MS = 20000; const timeoutId = setTimeout(() => { if (!controller.signal.aborted) { controller.abort(); } }, FLIGHT_TIMEOUT_MS); try { const destination = new Vec3(x, y, z); await createCancellableFlightOperation(bot, destination, controller); return createResponse(`Successfully flew to position (${x}, ${y}, ${z}).`); } catch (error) { if (controller.signal.aborted) { const currentPosAfterTimeout = bot.entity.position; return createErrorResponse( `Flight timed out after ${FLIGHT_TIMEOUT_MS/1000} seconds. The destination may be unreachable. ` + `Current position: (${Math.floor(currentPosAfterTimeout.x)}, ${Math.floor(currentPosAfterTimeout.y)}, ${Math.floor(currentPosAfterTimeout.z)})` ); } console.error('Flight error:', error); return createErrorResponse(error as Error); } finally { clearTimeout(timeoutId); bot.creative.stopFlying(); } } );
- src/bot.ts:603-629 (helper)Helper function that wraps bot.creative.flyTo in a Promise with AbortController support for cancellable flight operations.function createCancellableFlightOperation( bot: any, destination: Vec3, controller: AbortController ): Promise<boolean> { return new Promise((resolve, reject) => { let aborted = false; controller.signal.addEventListener('abort', () => { aborted = true; bot.creative.stopFlying(); reject(new Error("Flight operation cancelled")); }); bot.creative.flyTo(destination) .then(() => { if (!aborted) { resolve(true); } }) .catch((err: any) => { if (!aborted) { reject(err); } }); }); }
- src/bot.ts:145-145 (registration)High-level registration call to registerFlightTools function, which contains the 'fly-to' tool registration.registerFlightTools(server, bot);