Skip to main content
Glama

preview_ui_ascii

Generate ASCII art previews of UI layouts and components to visualize designs before coding implementation.

Instructions

create page|build UI|design component|make page|develop page - Preview UI before coding

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
page_nameYesName of the page or component (e.g., "Login Page", "Dashboard")
layout_typeNoLayout structure type (default: header-footer)
componentsYesList of UI components to include
widthNoPreview width in characters (default: 60)
responsiveNoShow mobile view preview (default: false)

Implementation Reference

  • The core handler function that takes UI description parameters and generates an ASCII art preview of the layout, supporting various layout types like header-footer, sidebar, grid, centered, split. Includes mobile responsive preview option.
    export async function previewUiAscii(args: {
      page_name: string;
      layout_type?: string;
      components: Array<{ type: string; label?: string; position?: string }>;
      width?: number;
      responsive?: boolean;
    }): Promise<ToolResult> {
      const {
        page_name,
        layout_type = 'header-footer',
        components,
        width = 60,
        responsive = false
      } = args;
    
      // ASCII art generation
      const topBorder = '┌' + '─'.repeat(width - 2) + '┐';
      const bottomBorder = '└' + '─'.repeat(width - 2) + '┘';
      const separator = '├' + '─'.repeat(width - 2) + '┤';
      const emptyLine = '│' + ' '.repeat(width - 2) + '│';
    
      const createLine = (text: string, align: 'left' | 'center' | 'right' = 'left') => {
        const contentWidth = width - 4;
        let content = text.slice(0, contentWidth);
    
        if (align === 'center') {
          const padding = Math.floor((contentWidth - content.length) / 2);
          content = ' '.repeat(padding) + content + ' '.repeat(contentWidth - padding - content.length);
        } else if (align === 'right') {
          content = ' '.repeat(contentWidth - content.length) + content;
        } else {
          content = content + ' '.repeat(contentWidth - content.length);
        }
    
        return '│ ' + content + ' │';
      };
    
      const createBox = (label: string, w: number, h: number) => {
        const lines = [];
        lines.push('┌' + '─'.repeat(w - 2) + '┐');
    
        for (let i = 0; i < h - 2; i++) {
          if (i === Math.floor((h - 2) / 2)) {
            const padding = Math.floor((w - 4 - label.length) / 2);
            const text = ' '.repeat(padding) + label + ' '.repeat(w - 4 - padding - label.length);
            lines.push('│ ' + text + ' │');
          } else {
            lines.push('│ ' + ' '.repeat(w - 4) + ' │');
          }
        }
    
        lines.push('└' + '─'.repeat(w - 2) + '┘');
        return lines;
      };
    
      let preview: string[] = [];
    
      // Generate preview based on layout type
      preview.push(topBorder);
    
      switch (layout_type) {
        case 'header-footer': {
          // Header
          const header = components.find(c => c.type === 'header' || c.position === 'top');
          if (header) {
            preview.push(createLine(header.label || 'Header', 'left'));
            preview.push(separator);
          }
    
          // Main content
          const mainComponents = components.filter(c =>
            c.type !== 'header' && c.type !== 'footer' && c.position !== 'top' && c.position !== 'bottom'
          );
    
          preview.push(emptyLine);
          mainComponents.forEach(comp => {
            const label = comp.label || comp.type.toUpperCase();
            if (comp.type === 'button') {
              preview.push(createLine(`  [${label}]`, 'center'));
            } else if (comp.type === 'input') {
              preview.push(createLine(`  ${label}: [____________]`, 'left'));
            } else if (comp.type === 'card') {
              preview.push(createLine(`  ┌─ ${label} ─────────────┐`, 'left'));
              preview.push(createLine(`  │ Content here...      │`, 'left'));
              preview.push(createLine(`  └──────────────────────┘`, 'left'));
            } else {
              preview.push(createLine(`  ${label}`, 'left'));
            }
          });
          preview.push(emptyLine);
    
          // Footer
          const footer = components.find(c => c.type === 'footer' || c.position === 'bottom');
          if (footer) {
            preview.push(separator);
            preview.push(createLine(footer.label || 'Footer', 'center'));
          }
          break;
        }
    
        case 'sidebar': {
          // Header
          const header = components.find(c => c.type === 'header' || c.position === 'top');
          if (header) {
            preview.push(createLine(header.label || 'Header', 'left'));
            preview.push(separator);
          }
    
          // Sidebar + Content
          const sidebarWidth = Math.floor(width * 0.25);
          const contentWidth = width - sidebarWidth - 5;
    
          const sidebar = components.find(c => c.type === 'sidebar' || c.position === 'left');
          const mainComponents = components.filter(c =>
            c.type !== 'header' && c.type !== 'footer' && c.type !== 'sidebar' &&
            c.position !== 'top' && c.position !== 'bottom' && c.position !== 'left'
          );
    
          preview.push('│ ┌' + '─'.repeat(sidebarWidth - 2) + '┐' + ' '.repeat(contentWidth - sidebarWidth + 3) + '│');
          preview.push('│ │' + (sidebar?.label || 'Nav').padEnd(sidebarWidth - 2) + '│  Content Area' + ' '.repeat(contentWidth - 15) + '│');
    
          const navItems = mainComponents.slice(0, 3);
          navItems.forEach((item, idx) => {
            const navLabel = `${item.label || item.type}`.slice(0, sidebarWidth - 4);
            const contentLabel = idx === 0 ? `┌─ ${mainComponents[0]?.label || 'Main'} ─┐` : '';
            preview.push('│ │ ' + navLabel.padEnd(sidebarWidth - 3) + '│  ' + contentLabel.padEnd(contentWidth - 3) + '│');
          });
    
          preview.push('│ └' + '─'.repeat(sidebarWidth - 2) + '┘' + ' '.repeat(contentWidth - sidebarWidth + 3) + '│');
    
          // Footer
          const footer = components.find(c => c.type === 'footer' || c.position === 'bottom');
          if (footer) {
            preview.push(separator);
            preview.push(createLine(footer.label || 'Footer', 'center'));
          }
          break;
        }
    
        case 'grid': {
          preview.push(createLine('Grid Layout', 'center'));
          preview.push(separator);
    
          const gridComponents = components.filter(c => c.type !== 'header' && c.type !== 'footer');
          const cols = Math.ceil(Math.sqrt(gridComponents.length));
          const cellWidth = Math.floor((width - 4) / cols) - 2;
    
          for (let i = 0; i < gridComponents.length; i += cols) {
            const row = gridComponents.slice(i, i + cols);
            preview.push('│ ' + row.map(c => {
              const label = (c.label || c.type).slice(0, cellWidth - 2);
              return '┌' + label.padEnd(cellWidth - 2, '─') + '┐';
            }).join(' ') + ' '.repeat(width - 4 - row.length * (cellWidth + 1)) + ' │');
    
            preview.push('│ ' + row.map(c => '│' + ' '.repeat(cellWidth - 2) + '│').join(' ') + ' '.repeat(width - 4 - row.length * (cellWidth + 1)) + ' │');
    
            preview.push('│ ' + row.map(c => '└' + '─'.repeat(cellWidth - 2) + '┘').join(' ') + ' '.repeat(width - 4 - row.length * (cellWidth + 1)) + ' │');
          }
          break;
        }
    
        case 'centered': {
          const main = components[0];
          preview.push(emptyLine);
          preview.push(emptyLine);
          preview.push(createLine(main?.label || 'Main Content', 'center'));
    
          components.slice(1).forEach(comp => {
            if (comp.type === 'button') {
              preview.push(createLine(`[${comp.label || 'Button'}]`, 'center'));
            } else if (comp.type === 'input') {
              preview.push(createLine(`${comp.label || 'Input'}: [____________]`, 'center'));
            }
          });
    
          preview.push(emptyLine);
          preview.push(emptyLine);
          break;
        }
    
        case 'split': {
          const leftWidth = Math.floor((width - 5) / 2);
          const rightWidth = width - leftWidth - 5;
    
          preview.push('│ ┌' + '─'.repeat(leftWidth) + '┐ ┌' + '─'.repeat(rightWidth) + '┐ │');
    
          const left = components.find(c => c.position === 'left') || components[0];
          const right = components.find(c => c.position === 'right') || components[1];
    
          preview.push('│ │' + (left?.label || 'Left').padEnd(leftWidth) + '│ │' + (right?.label || 'Right').padEnd(rightWidth) + '│ │');
    
          for (let i = 0; i < 5; i++) {
            preview.push('│ │' + ' '.repeat(leftWidth) + '│ │' + ' '.repeat(rightWidth) + '│ │');
          }
    
          preview.push('│ └' + '─'.repeat(leftWidth) + '┘ └' + '─'.repeat(rightWidth) + '┘ │');
          break;
        }
      }
    
      preview.push(bottomBorder);
    
      // Mobile view if responsive
      let mobilePreview = '';
      if (responsive) {
        const mobileWidth = 30;
        const mobileTop = '┌' + '─'.repeat(mobileWidth - 2) + '┐';
        const mobileBottom = '└' + '─'.repeat(mobileWidth - 2) + '┘';
    
        mobilePreview = '\n\n📱 Mobile View:\n';
        mobilePreview += mobileTop + '\n';
        components.forEach(comp => {
          const label = (comp.label || comp.type).slice(0, mobileWidth - 4);
          mobilePreview += '│ ' + label.padEnd(mobileWidth - 4) + ' │\n';
        });
        mobilePreview += mobileBottom;
      }
    
      const result = {
        page_name,
        layout_type,
        ascii_preview: preview.join('\n'),
        mobile_preview: responsive ? mobilePreview : null,
        components_count: components.length,
        message: '✅ Do you want to proceed with this layout? If you approve, I will start generating the code.',
        action: 'preview_ui_ascii',
        status: 'awaiting_confirmation'
      };
    
      return {
        content: [{
          type: 'text',
          text: `🎨 UI Preview: ${page_name}\n\n${preview.join('\n')}${mobilePreview}\n\n${result.message}`
        }]
      };
    }
  • The tool definition and input schema specifying parameters like page_name (required), components (required), layout_type, width, responsive with descriptions and types.
    export const previewUiAsciiDefinition: ToolDefinition = {
      name: 'preview_ui_ascii',
      description: 'create page|build UI|design component|make page|develop page - Preview UI before coding',
      inputSchema: {
        type: 'object',
        properties: {
          page_name: {
            type: 'string',
            description: 'Name of the page or component (e.g., "Login Page", "Dashboard")'
          },
          layout_type: {
            type: 'string',
            enum: ['sidebar', 'header-footer', 'grid', 'centered', 'split', 'custom'],
            description: 'Layout structure type (default: header-footer)'
          },
          components: {
            type: 'array',
            description: 'List of UI components to include',
            items: {
              type: 'object',
              properties: {
                type: { type: 'string', description: 'Component type (header, sidebar, button, input, card, etc.)' },
                label: { type: 'string', description: 'Component label or text' },
                position: { type: 'string', description: 'Position in layout (top, left, center, right, bottom)' }
              }
            }
          },
          width: {
            type: 'number',
            description: 'Preview width in characters (default: 60)'
          },
          responsive: {
            type: 'boolean',
            description: 'Show mobile view preview (default: false)'
          }
        },
        required: ['page_name', 'components']
      },
      annotations: {
        title: 'Preview UI (ASCII)',
        audience: ['user', 'assistant']
      }
    };
  • src/index.ts:694-695 (registration)
    Tool handler dispatch in the main executeToolCall switch statement in index.ts, calling the previewUiAscii function.
    case 'preview_ui_ascii':
      return await previewUiAscii(args as any) as CallToolResult;
  • src/index.ts:159-159 (registration)
    Inclusion of previewUiAsciiDefinition in the tools array for MCP tool listing.
    previewUiAsciiDefinition
  • src/index.ts:85-85 (registration)
    Import of the previewUiAscii handler and definition from its module.
    import { previewUiAscii, previewUiAsciiDefinition } from './tools/ui/previewUiAscii.js';
Behavior2/5

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

No annotations are provided beyond a title, so the description carries full burden. It mentions 'preview' which implies read-only/non-destructive behavior, but doesn't explicitly state this. No information about permissions, rate limits, output format, or what 'preview' actually generates (ASCII representation as hinted in title). The description adds minimal behavioral context.

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

Conciseness2/5

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

The description is poorly structured with a confusing pipe-separated list of verbs followed by the actual purpose. The front-loaded content ('create page|build UI|design component|make page|develop page') is misleading and doesn't earn its place. Only the last part 'Preview UI before coding' is useful.

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

Completeness2/5

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

For a tool with 5 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the preview output looks like (ASCII representation), how it's displayed, or what value it provides. The title hints at 'ASCII' but the description doesn't mention this crucial aspect.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents all 5 parameters. The description adds no parameter-specific information beyond what's in the schema. Baseline score of 3 is appropriate since the schema does all the parameter documentation work.

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

Purpose3/5

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

The description states the tool's purpose as 'Preview UI before coding' which is clear but vague. It lists alternative verbs like 'create page|build UI|design component|make page|develop page' which adds confusion rather than clarity. The purpose is understandable but not specific about what 'preview' entails or how it differs from actual creation tools.

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?

No explicit guidance on when to use this tool versus alternatives. The description mentions 'before coding' which implies a pre-implementation context, but there's no comparison with sibling tools (none of which appear to be UI-related). No exclusions or prerequisites are mentioned.

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/ssdeanx/ssd-ai'

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