Skip to main content
Glama
Tai-DT
by Tai-DT

generate_preview

Create visual previews of Tailwind CSS components with customizable dimensions, dark mode, and responsive breakpoint options to verify design implementation.

Instructions

Generate visual preview of Tailwind components

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
htmlYesHTML code to preview
widthNoPreview width in pixels
heightNoPreview height in pixels
darkModeNoGenerate dark mode preview
responsiveNoGenerate responsive breakpoint previews

Implementation Reference

  • Primary handler implementation for the 'generate_preview' tool. Uses Puppeteer to render HTML with Tailwind CSS CDN, capture screenshot as base64 PNG, embed in Markdown response, includes HTML code block and responsive notes.
    export async function generatePreview(args: PreviewRequest) {
      try {
        const {
          html,
          width = 800,
          height = 600,
          darkMode = false,
          responsive = false
        } = args;
    
        // Create full HTML document
        const fullHtml = `
    <!DOCTYPE html>
    <html lang="en" ${darkMode ? 'class="dark"' : ''}>
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Tailwind Preview</title>
      <script src="https://cdn.tailwindcss.com"></script>
      ${darkMode ? '<script>tailwind.config = { darkMode: "class" }</script>' : ''}
    </head>
    <body class="${darkMode ? 'dark:bg-gray-900 dark:text-white' : 'bg-white'}">
      ${html}
    </body>
    </html>`;
    
        let result = '# Component Preview\n\n';
        
        try {
          // Launch headless browser for screenshot
          const browser = await puppeteer.launch({ headless: true });
          const page = await browser.newPage();
          
          await page.setViewport({ width, height });
          await page.setContent(fullHtml);
          
          // Take screenshot
          const screenshot = await page.screenshot({ 
            encoding: 'base64',
            fullPage: false 
          });
          
          await browser.close();
          
          result += `**Preview Generated**: ${width}x${height}px ${darkMode ? '(Dark Mode)' : '(Light Mode)'}\n\n`;
          result += `![Component Preview](data:image/png;base64,${screenshot})\n\n`;
          
        } catch (screenshotError) {
          console.error('Screenshot error:', screenshotError);
          result += '**Note**: Preview screenshot could not be generated. Here\'s the rendered HTML:\n\n';
        }
    
        result += '## HTML Code\n```html\n' + html + '\n```\n\n';
        
        if (responsive) {
          result += '## Responsive Breakpoints\n\n';
          result += '- **Mobile**: 375px width\n';
          result += '- **Tablet**: 768px width\n';
          result += '- **Desktop**: 1024px width\n';
          result += '- **Large**: 1280px width\n\n';
          result += '*Note: Test your component at different screen sizes to ensure responsive behavior.*\n';
        }
    
        return {
          content: [
            {
              type: 'text',
              text: result
            }
          ]
        };
      } catch (error) {
        console.error('Preview generation error:', error);
        throw new Error(`Failed to generate preview: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • src/index.ts:268-301 (registration)
    Tool registration entry in the server's TOOLS array, defining name, description, and input schema precisely matching the preview-generator parameters.
    {
      name: 'generate_preview',
      description: 'Generate visual preview of Tailwind components',
      inputSchema: {
        type: 'object',
        properties: {
          html: {
            type: 'string',
            description: 'HTML code to preview'
          },
          width: {
            type: 'number',
            default: 800,
            description: 'Preview width in pixels'
          },
          height: {
            type: 'number',
            default: 600,
            description: 'Preview height in pixels'
          },
          darkMode: {
            type: 'boolean',
            default: false,
            description: 'Generate dark mode preview'
          },
          responsive: {
            type: 'boolean',
            default: false,
            description: 'Generate responsive breakpoint previews'
          }
        },
        required: ['html']
      }
    },
  • Dispatcher in the CallToolRequestHandler switch statement that invokes the generatePreview handler for 'generate_preview' tool calls.
    case 'generate_preview':
      return await generatePreview(args as unknown as PreviewOptions);
  • TypeScript interface for PreviewOptions used in type annotations, though parameters slightly differ from runtime schema.
    export interface PreviewOptions {
      html: string;
      css?: string;
      devices?: ('mobile' | 'tablet' | 'desktop' | 'wide')[];
      theme?: 'light' | 'dark' | 'auto';
      interactive?: boolean;
      showCode?: boolean;
      format?: 'html' | 'image' | 'pdf';
      quality?: 'low' | 'medium' | 'high';
    }
  • Placeholder/stub handler imported and called by index.ts, returns dummy text response (note: parameter mismatch with schema).
    export async function generatePreview(args: PreviewOptions) {
      return {
        content: [
          {
            type: 'text',
            text: `Generated preview for ${args.devices?.join(', ') || 'all devices'}\nTheme: ${args.theme || 'light'}`
          }
        ]
      };
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'Generate visual preview' implies a read-only operation that creates output, it doesn't disclose important behavioral aspects like whether this is a computationally intensive operation, whether there are rate limits, what format the preview output takes (image, HTML, etc.), or whether authentication is required.

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 extremely concise at just 6 words, front-loading the essential information with zero wasted words. Every word earns its place by specifying what's being generated (visual preview) and what it applies to (Tailwind components).

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 and no output schema, the description is inadequate. It doesn't explain what the output looks like (image URL, base64 data, HTML snippet), doesn't mention performance characteristics, and provides no examples of typical use cases. With no annotations to supplement the description, this leaves significant gaps for an agent trying to use the tool effectively.

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?

With 100% schema description coverage, the input schema already documents all 5 parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain how the HTML should be structured, what 'responsive breakpoint previews' actually means, or provide examples of typical usage patterns.

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 verb ('Generate') and resource ('visual preview of Tailwind components'), making the purpose immediately understandable. However, it doesn't differentiate this tool from potential sibling tools like 'analyze_design' or 'generate_component' that might also involve visual aspects of Tailwind components.

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. With sibling tools like 'analyze_design', 'generate_component', and 'suggest_improvements' that might overlap in visual component contexts, there's no indication of when this specific preview generation tool is appropriate versus those other tools.

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/Tai-DT/mcp-tailwind-gemini'

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