Skip to main content
Glama

screenshot_from_file

Generate syntax-highlighted code screenshots from file paths with line selection and theme customization for documentation and sharing purposes.

Instructions

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

Input Schema

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

Implementation Reference

  • The core handler function that implements the screenshot_from_file tool logic: reads the file, detects language from extension, extracts optional line range, and calls generateScreenshot.
    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, }); }
  • src/index.ts:57-83 (registration)
    Registration of the 'screenshot_from_file' tool in the MCP ListTools response, including name, description, and 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"], }, },
  • TypeScript interface defining the input options for screenshotFromFile function.
    export interface ScreenshotFromFileOptions { filePath: string; startLine?: number; endLine?: number; theme?: string; }
  • MCP CallTool handler dispatch for 'screenshot_from_file': validates args, calls screenshotFromFile, formats response with text and image content.
    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, }; } }
  • MCP input schema definition for the screenshot_from_file tool.
    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"], },

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