Skip to main content
Glama

generate_code_screenshot

Create syntax-highlighted code screenshots with customizable themes for documentation, sharing, or presentations.

Instructions

Generate a beautiful screenshot of code with syntax highlighting and themes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe code to screenshot
languageYesProgramming language (e.g., javascript, python, rust)
themeNoColor theme (dracula, nord, monokai, github-light, github-dark)

Implementation Reference

  • src/index.ts:34-56 (registration)
    Registration of the 'generate_code_screenshot' tool in the ListTools response, including name, description, and input schema definition.
    {
      name: "generate_code_screenshot",
      description: "Generate a beautiful screenshot of code with syntax highlighting and themes",
      inputSchema: {
        type: "object",
        properties: {
          code: {
            type: "string",
            description: "The code to screenshot",
          },
          language: {
            type: "string",
            description: "Programming language (e.g., javascript, python, rust)",
          },
          theme: {
            type: "string",
            description: "Color theme (dracula, nord, monokai, github-light, github-dark)",
            enum: ["dracula", "nord", "monokai", "github-light", "github-dark"],
          },
        },
        required: ["code", "language"],
      },
    },
  • MCP CallToolRequest handler for 'generate_code_screenshot': validates arguments, invokes generateScreenshot, constructs response with success/error text and base64 image.
    if (name === "generate_code_screenshot") {
      if (!args) {
        throw new Error("Arguments are required");
      }
    
      try {
        const { code, language, theme = "dracula" } = args as {
          code: string;
          language: string;
          theme?: string;
        };
    
        if (!code || !language) {
          throw new Error("Both 'code' and 'language' are required");
        }
    
        // Generate the screenshot
        const result = await generateScreenshot({
          code,
          language,
          theme,
        });
    
        return {
          content: [
            {
              type: "text",
              text: `✅ Screenshot generated successfully!\n\nFile saved to: ${result.path}\n\nTheme: ${theme}\nLanguage: ${language}\n\nYou can view the image in your file browser.`,
            },
            {
              type: "image",
              data: result.base64,
              mimeType: "image/png",
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `❌ Error generating screenshot: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Core tool implementation: renders syntax-highlighted code HTML in headless browser using Playwright, screenshots the code container, saves PNG to temp file, returns file path and base64 data.
    export async function generateScreenshot(
      options: ScreenshotOptions
    ): Promise<GenerateScreenshotResult> {
      const html = generateHTML(options);
      const browser = await getBrowser();
      const page = await browser.newPage();
    
      try {
        // Set viewport for better rendering
        await page.setViewportSize({
          width: 1920,
          height: 1080,
        });
    
        // Load the HTML content
        await page.setContent(html, {
          waitUntil: "networkidle",
        });
    
        // Wait for syntax highlighting to apply
        await page.waitForTimeout(500);
    
        // Find the container element
        const container = await page.locator(".container");
    
        // Take screenshot of just the container
        const screenshot = await container.screenshot({
          type: "png",
        });
    
        // Save to temp file
        const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "code-screenshot-"));
        const tempFile = path.join(tempDir, "screenshot.png");
        await fs.writeFile(tempFile, screenshot);
    
        // Convert to base64
        const base64 = screenshot.toString("base64");
    
        return {
          path: tempFile,
          base64: base64,
        };
      } finally {
        await page.close();
      }
    }
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 mentions generating a 'beautiful screenshot' but doesn't specify output format (e.g., image type, size), performance aspects (e.g., rate limits, processing time), or error handling. For a tool with no annotations, this leaves significant gaps in understanding how it behaves beyond the basic action.

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

Conciseness4/5

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

The description is concise and front-loaded in a single sentence that states the core purpose efficiently. There's no wasted text, and it directly communicates the tool's function. However, it could be slightly improved by structuring to include usage hints, but as is, it's appropriately sized for its content.

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?

Given the tool's complexity (generating visual output) and lack of annotations and output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., image format, dimensions), potential limitations, or how errors are handled. For a tool with no structured output information, the description should provide more context to be fully helpful.

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?

The description adds minimal meaning beyond the input schema, which has 100% coverage with clear descriptions for all parameters. It implies parameters through 'code with syntax highlighting and themes' but doesn't detail semantics like how 'language' affects highlighting or what 'theme' visually entails. With high schema coverage, the baseline is 3, as the schema does most of the work without extra value from the description.

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 tool's purpose: 'Generate a beautiful screenshot of code with syntax highlighting and themes.' It specifies the verb ('generate'), resource ('screenshot of code'), and key features ('syntax highlighting and themes'), making the action distinct. However, it doesn't explicitly differentiate from sibling tools like 'batch_screenshot' or 'screenshot_from_file', which likely handle multiple codes or file inputs, so it misses full sibling distinction.

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 sibling tools such as 'batch_screenshot' for multiple codes, 'screenshot_from_file' for code from files, or 'screenshot_git_diff' for diff outputs, leaving the agent without context for selection. Usage is implied only by the tool's name and description, with no explicit when/when-not instructions.

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/MoussaabBadla/code-screenshot-mcp'

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