Skip to main content
Glama

export_level

Export the current working draft as PuzzleData JSON for building, validating, and publishing Ice Puzzle levels with integrated solver feedback and quality checks.

Instructions

Export the current working draft as PuzzleData JSON

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The complete export_level tool registration including name, description, input schema, and async handler function. The handler calls draftStore.exportPuzzleData() and returns the PuzzleData as formatted JSON.
    {
      name: 'export_level',
      description: 'Export the current working draft as PuzzleData JSON.',
      inputSchema: { type: 'object', properties: {} },
      handler: async () => {
        const puzzleData = draftStore.exportPuzzleData();
        if (!puzzleData) return { content: [{ type: 'text', text: 'No active draft. Use create_level first.' }] };
        return { content: [{ type: 'text', text: JSON.stringify(puzzleData, null, 2) }] };
      },
    },
  • The exportPuzzleData() helper method that converts the current DraftState into a PuzzleData object. Handles warp pairs conversion, barrier normalization, obstacle filtering, and optional fields (warps, thinIceTiles, pushableRocks, pressurePlate, barrier).
    exportPuzzleData(): PuzzleData | null {
      if (!this.currentDraft) {
        return null;
      }
    
      const draft = this.currentDraft;
    
      // Convert warp pairs to WarpZones
      const warps = draft.warpPairs.flatMap(pair =>
        pair.positions.map(pos => ({
          x: pos.x,
          y: pos.y,
          id: pair.id,
        }))
      );
    
      // Barrier: prefer draft.barrier (Position), fall back to first barrier obstacle
      const barrierObstacles = draft.obstacles.filter(obs => obs.type === 'barrier');
      const exportedBarrier = draft.barrier || (barrierObstacles.length > 0
        ? { x: barrierObstacles[0].x, y: barrierObstacles[0].y }
        : null);
    
      // Regular obstacles: exclude barrier (separate field)
      const regularObstacles = draft.obstacles.filter(
        obs =>
          obs.type !== 'barrier' &&
          obs.type !== 'thin_ice' &&
          obs.type !== 'pushable_rock'
      );
    
      // Normalize legacy encodings where thin ice / pushable rocks were stored as obstacles.
      const normalizedThinIce = [...draft.thinIceTiles];
      for (const obs of draft.obstacles) {
        if (obs.type === 'thin_ice' && !normalizedThinIce.some((tile) => tile.x === obs.x && tile.y === obs.y)) {
          normalizedThinIce.push({ x: obs.x, y: obs.y });
        }
      }
    
      const normalizedPushableRocks = [...draft.pushableRocks];
      for (const obs of draft.obstacles) {
        if (obs.type === 'pushable_rock' && !normalizedPushableRocks.some((rock) => rock.x === obs.x && rock.y === obs.y)) {
          normalizedPushableRocks.push({ x: obs.x, y: obs.y });
        }
      }
    
      const puzzleData: PuzzleData = {
        id: draft.id || this.generateId(),
        name: draft.name,
        theme: 'ice',
        width: draft.gridWidth,
        height: draft.gridHeight,
        par: draft.par,
        start: draft.startPosition,
        goal: draft.goalPosition,
        obstacles: regularObstacles,
      };
    
      if (warps.length > 0) {
        puzzleData.warps = warps;
      }
      if (normalizedThinIce.length > 0) {
        puzzleData.thinIceTiles = normalizedThinIce;
      }
      if (normalizedPushableRocks.length > 0) {
        puzzleData.pushableRocks = normalizedPushableRocks;
      }
      if (draft.pressurePlate) {
        puzzleData.pressurePlate = draft.pressurePlate;
      }
      if (exportedBarrier) {
        puzzleData.barrier = exportedBarrier;
      }
    
      return puzzleData;
    }
  • The PuzzleData interface definition that defines the output schema structure for exported levels, including required fields (id, name, theme, width, height, par, start, goal, obstacles) and optional fields (warps, thinIceTiles, pushableRocks, pressurePlate, barrier).
    export interface PuzzleData {
      id: string;
      name: string;
      theme: string;
      width: number;
      height: number;
      par: number;
      start: Position;
      goal: Position;
      obstacles: Obstacle[];
      warps?: WarpZone[];
      thinIceTiles?: Position[];
      pushableRocks?: Position[];
      pressurePlate?: Position;
      barrier?: Position;
    }
  • The getLevelManagementTools() function that returns an array of tool definitions including export_level. This is the registration point where export_level is exported and made available to the MCP system.
    export function getLevelManagementTools(): ToolDefinition[] {
      return [
        {
          name: 'create_level',
          description: 'Create a new empty ice puzzle level. This becomes the current working draft.',
          inputSchema: {
            type: 'object',
            properties: {
              name: { type: 'string', description: 'Level name' },
              width: { type: 'number', description: 'Grid width (5-25, default 10)', minimum: 5, maximum: 25 },
              height: { type: 'number', description: 'Grid height (5-25, default 10)', minimum: 5, maximum: 25 },
            },
            required: ['name'],
          },
          handler: async (args) => {
            const draft = draftStore.createDraft(args.name, args.width, args.height);
            const viz = renderLevel(draft, { showCoords: true });
            return { content: [{ type: 'text', text: `Level "${args.name}" created!\n\n${formatDraftSummary(draft)}\n\n${viz}` }] };
          },
        },
        {
          name: 'get_level',
          description: 'Get the current working draft level state with full details and visualization.',
          inputSchema: { type: 'object', properties: {} },
          handler: async () => {
            const draft = draftStore.getCurrentDraft();
            if (!draft) return { content: [{ type: 'text', text: 'No active draft. Use create_level first.' }] };
            // Auto-solve if dirty
            if (draft.isDirty || !draft.lastSolverResult) {
              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, showSolution: true, solution: current.lastSolverResult?.solution });
            return { content: [{ type: 'text', text: `${formatDraftSummary(current)}\n\n${viz}` }] };
          },
        },
        {
          name: 'list_drafts',
          description: 'List all saved draft levels.',
          inputSchema: { type: 'object', properties: {} },
          handler: async () => {
            const drafts = draftStore.listDrafts();
            if (drafts.length === 0) return { content: [{ type: 'text', text: 'No saved drafts.' }] };
            const list = drafts.map((d, i) => `${i + 1}. ${d.name} (${d.id}) - ${d.description || 'No description'}`).join('\n');
            return { content: [{ type: 'text', text: `Saved drafts:\n${list}` }] };
          },
        },
        {
          name: 'delete_draft',
          description: 'Delete a saved draft level.',
          inputSchema: {
            type: 'object',
            properties: { draftId: { type: 'string', description: 'Draft ID to delete' } },
            required: ['draftId'],
          },
          handler: async (args) => {
            const success = draftStore.deleteDraft(args.draftId);
            return { content: [{ type: 'text', text: success ? `Draft ${args.draftId} deleted.` : `Draft ${args.draftId} not found.` }] };
          },
        },
        {
          name: 'import_level',
          description: 'Import a level from PuzzleData JSON. Sets it as the current working draft.',
          inputSchema: {
            type: 'object',
            properties: { puzzleData: { type: 'object', description: 'PuzzleData JSON object' } },
            required: ['puzzleData'],
          },
          handler: async (args) => {
            const validation = validatePuzzleData(args.puzzleData);
            if (!validation.valid) return { content: [{ type: 'text', text: `Invalid puzzle data: ${validation.error}` }] };
            const draft = draftStore.importPuzzleData(validation.data!);
            const viz = renderLevel(draft, { showCoords: true });
            return { content: [{ type: 'text', text: `Level imported!\n\n${formatDraftSummary(draft)}\n\n${viz}` }] };
          },
        },
        {
          name: 'export_level',
          description: 'Export the current working draft as PuzzleData JSON.',
          inputSchema: { type: 'object', properties: {} },
          handler: async () => {
            const puzzleData = draftStore.exportPuzzleData();
            if (!puzzleData) return { content: [{ type: 'text', text: 'No active draft. Use create_level first.' }] };
            return { content: [{ type: 'text', text: JSON.stringify(puzzleData, null, 2) }] };
          },
        },
      ];
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool exports data but doesn't clarify if this is a read-only operation, if it modifies state, what happens to the draft after export, or any rate limits or permissions required. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded with the core action and resource, making it easy to parse and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has no parameters, no annotations, and no output schema, the description adequately covers the basic purpose. However, it lacks details on behavioral aspects (e.g., side effects, return format) and usage context, making it minimally viable but incomplete for optimal agent understanding in a complex environment with many sibling tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters with 100% schema description coverage, so the schema fully documents the lack of inputs. The description adds no parameter information, which is appropriate here, earning a baseline score of 4 as it doesn't need to compensate for any schema gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Export') and the target resource ('current working draft as PuzzleData JSON'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'save_draft' or 'save_local_draft', which might have overlapping functionality but different output formats or purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a loaded draft), exclusions, or comparisons to similar tools like 'save_draft' or 'export' variants that might exist in context, leaving usage context implied rather than explicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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