Skip to main content
Glama

screenshot_from_file

Generate syntax-highlighted code screenshots from file paths, with optional line range selection and theme customization.

Instructions

Screenshot code directly from a file path, with optional line range selection. Auto-detects language from file extension.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the code file
startLineNoStart line number (1-indexed, optional)
endLineNoEnd line number (optional)
themeNoColor theme (dracula, nord, monokai, github-light, github-dark)

Implementation Reference

  • Core implementation of the screenshot_from_file tool: reads the specified file, auto-detects language from extension, optionally extracts a line range, and generates a screenshot using the generateScreenshot helper.
    export async function screenshotFromFile(
      options: ScreenshotFromFileOptions
    ): Promise<GenerateScreenshotResult> {
      // Read the file
      const fileContent = await fs.readFile(options.filePath, 'utf-8');
    
      // Detect language from extension
      const ext = path.extname(options.filePath).toLowerCase();
      const language = extensionToLanguage[ext] || 'plaintext';
    
      // Extract lines if specified
      let code = fileContent;
      if (options.startLine !== undefined || options.endLine !== undefined) {
        const lines = fileContent.split('\n');
        const start = (options.startLine || 1) - 1;
        const end = options.endLine || lines.length;
        code = lines.slice(start, end).join('\n');
      }
    
      // Generate screenshot
      return generateScreenshot({
        code,
        language,
        theme: options.theme,
      });
    }
  • TypeScript type definition for the input options of the screenshotFromFile handler.
    export interface ScreenshotFromFileOptions {
      filePath: string;
      startLine?: number;
      endLine?: number;
      theme?: string;
    }
  • src/index.ts:57-82 (registration)
    MCP tool registration in the listTools response, including name, description, and JSON input schema.
    {
      name: "screenshot_from_file",
      description: "Screenshot code directly from a file path, with optional line range selection. Auto-detects language from file extension.",
      inputSchema: {
        type: "object",
        properties: {
          filePath: {
            type: "string",
            description: "Path to the code file",
          },
          startLine: {
            type: "number",
            description: "Start line number (1-indexed, optional)",
          },
          endLine: {
            type: "number",
            description: "End line number (optional)",
          },
          theme: {
            type: "string",
            description: "Color theme (dracula, nord, monokai, github-light, github-dark)",
            enum: ["dracula", "nord", "monokai", "github-light", "github-dark"],
          },
        },
        required: ["filePath"],
      },
  • MCP server dispatch handler for screenshot_from_file tool calls: validates arguments, invokes the screenshotFromFile function, and formats the response with image and text.
    if (name === "screenshot_from_file") {
      if (!args) {
        throw new Error("Arguments are required");
      }
    
      try {
        const { filePath, startLine, endLine, theme = "dracula" } = args as {
          filePath: string;
          startLine?: number;
          endLine?: number;
          theme?: string;
        };
    
        if (!filePath) {
          throw new Error("filePath is required");
        }
    
        // Generate the screenshot from file
        const result = await screenshotFromFile({
          filePath,
          startLine,
          endLine,
          theme,
        });
    
        const lineInfo = startLine || endLine
          ? `\nLines: ${startLine || 1}-${endLine || 'end'}`
          : '\nFull file';
    
        return {
          content: [
            {
              type: "text",
              text: `✅ Screenshot from file generated successfully!\n\nFile: ${filePath}${lineInfo}\nSaved to: ${result.path}\n\nTheme: ${theme}\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 from file: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
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 'auto-detects language from file extension', which adds useful context beyond the schema. However, it doesn't describe critical behaviors like output format (e.g., image type, size), error handling (e.g., for invalid file paths), or performance aspects (e.g., file size limits), leaving significant gaps for a tool that performs file I/O and image generation.

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 a single, efficient sentence that front-loads the core purpose ('Screenshot code directly from a file path') and adds key features ('optional line range selection', 'auto-detects language'). It avoids redundancy and wastes no words, though it could be slightly more structured by separating usage notes.

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 (file I/O, image generation, language detection) and lack of annotations and output schema, the description is incomplete. It misses details on output (e.g., image format, where it's saved), error conditions, permissions needed for file access, and how it differs from siblings. For a tool with no structured behavioral hints, this leaves the agent under-informed.

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 already documents all parameters thoroughly. The description adds minimal value beyond the schema by hinting at 'optional line range selection' (implied by startLine/endLine) and 'auto-detects language' (not directly parameter-related). With high schema coverage, the baseline is 3, as the description doesn't significantly enhance parameter understanding.

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: 'Screenshot code directly from a file path' with the specific action 'screenshot' and resource 'code from a file path'. It distinguishes from siblings by mentioning 'from a file path' (vs. batch operations, git diffs, or generic generation), but doesn't explicitly name alternatives or contrast with all siblings like 'batch_screenshot' or 'screenshot_git_diff'.

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

Usage Guidelines3/5

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

The description implies usage context through 'optional line range selection' and 'auto-detects language from file extension', suggesting it's for capturing specific code sections from files. However, it lacks explicit guidance on when to use this tool versus siblings like 'batch_screenshot' (for multiple files) or 'screenshot_git_diff' (for diff outputs), leaving the agent to infer based on parameter names and descriptions.

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