Skip to main content
Glama

clear_region

Remove all puzzle tiles within a specified rectangular area to automatically solve that section of the level.

Instructions

Clear all tiles in a rectangular region. Auto-solves.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
x1YesTop-left X
y1YesTop-left Y
x2YesBottom-right X
y2YesBottom-right Y

Implementation Reference

  • The main handler function for clear_region tool. It gets the current draft, calculates the bounded rectangular region from x1,y1 to x2,y2, iterates through each position and calls draftStore.removeElement(), counts cleared positions, and returns a response with the count and auto-solved visualization.
    handler: async (args) => {
      const draft = draftStore.getCurrentDraft();
      if (!draft) return { content: [{ type: 'text', text: 'No active draft. Use create_level first.' }] };
      let cleared = 0;
      const minX = Math.max(1, Math.min(args.x1, args.x2));
      const maxX = Math.min(draft.gridWidth - 2, Math.max(args.x1, args.x2));
      const minY = Math.max(1, Math.min(args.y1, args.y2));
      const maxY = Math.min(draft.gridHeight - 2, Math.max(args.y1, args.y2));
      for (let y = minY; y <= maxY; y++) {
        for (let x = minX; x <= maxX; x++) {
          draftStore.removeElement(x, y);
          cleared++;
        }
      }
      const current = draftStore.getCurrentDraft()!;
      return { content: [{ type: 'text', text: `Cleared ${cleared} positions\n\n${autoSolveAndVisualize(current)}` }] };
    },
  • Input schema definition for clear_region tool. Defines an object with properties x1, y1, x2, y2 (all required numbers) representing the top-left and bottom-right coordinates of the rectangular region to clear.
    inputSchema: {
      type: 'object',
      properties: {
        x1: { type: 'number', description: 'Top-left X' },
        y1: { type: 'number', description: 'Top-left Y' },
        x2: { type: 'number', description: 'Bottom-right X' },
        y2: { type: 'number', description: 'Bottom-right Y' },
      },
      required: ['x1', 'y1', 'x2', 'y2'],
    },
  • Tool definition object for clear_region, including name, description, inputSchema, and handler. This is part of the array returned by getTileOperationTools() function that registers all tile operation tools.
      name: 'clear_region',
      description: 'Clear all tiles in a rectangular region. Auto-solves after clear.',
      inputSchema: {
        type: 'object',
        properties: {
          x1: { type: 'number', description: 'Top-left X' },
          y1: { type: 'number', description: 'Top-left Y' },
          x2: { type: 'number', description: 'Bottom-right X' },
          y2: { type: 'number', description: 'Bottom-right Y' },
        },
        required: ['x1', 'y1', 'x2', 'y2'],
      },
      handler: async (args) => {
        const draft = draftStore.getCurrentDraft();
        if (!draft) return { content: [{ type: 'text', text: 'No active draft. Use create_level first.' }] };
        let cleared = 0;
        const minX = Math.max(1, Math.min(args.x1, args.x2));
        const maxX = Math.min(draft.gridWidth - 2, Math.max(args.x1, args.x2));
        const minY = Math.max(1, Math.min(args.y1, args.y2));
        const maxY = Math.min(draft.gridHeight - 2, Math.max(args.y1, args.y2));
        for (let y = minY; y <= maxY; y++) {
          for (let x = minX; x <= maxX; x++) {
            draftStore.removeElement(x, y);
            cleared++;
          }
        }
        const current = draftStore.getCurrentDraft()!;
        return { content: [{ type: 'text', text: `Cleared ${cleared} positions\n\n${autoSolveAndVisualize(current)}` }] };
      },
    },
  • Helper function autoSolveAndVisualize() used by the clear_region handler. It exports puzzle data, solves it, updates the draft with solver result, renders the level with coordinates, and returns a formatted string with the visualization and solver info.
    function autoSolveAndVisualize(draft: DraftState): string {
      const puzzleData = draftStore.exportPuzzleData();
      if (puzzleData) {
        const result = solve(puzzleData);
        draftStore.updateDraft({ lastSolverResult: result, isDirty: false });
      }
      const current = draftStore.getCurrentDraft()!;
      const viz = renderLevel(current, { showCoords: true });
      const solverInfo = current.lastSolverResult ? formatSolverResult(current.lastSolverResult) : '';
      return `${viz}\n${solverInfo}`;
    }

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/wmoten/ice-puzzle-mcp'

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