Skip to main content
Glama

godot_screenshot

Read-onlyIdempotent

Capture a viewport screenshot from the running Godot project and return it as a base64-encoded PNG image.

Instructions

Capture a viewport screenshot from the running Godot project. Returns base64-encoded PNG image. Requires a display server (not headless mode).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sceneNoScene to capture (e.g., res://scenes/main.tscn). If omitted, captures the project's main scene.

Implementation Reference

  • Main handler function for the godot_screenshot tool. Registers the MCP tool, accepts an optional 'scene' parameter, generates a GDScript to capture the viewport, spawns Godot to run it, reads back the PNG, and returns it as base64 image content.
    export function registerScreenshot(server: McpServer, ctx: ServerContext): void {
      server.tool(
        "godot_screenshot",
        "Capture a viewport screenshot from the running Godot project. Returns base64-encoded PNG image. Requires a display server (not headless mode).",
        {
          scene: z
            .string()
            .optional()
            .describe("Scene to capture (e.g., res://scenes/main.tscn). If omitted, captures the project's main scene."),
        },
        { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
        async (args) => {
          if (!ctx.projectDir) {
            return { isError: true, content: [{ type: "text", text: formatError(projectNotFound()) }] };
          }
          if (!ctx.godotBinary) {
            return { isError: true, content: [{ type: "text", text: formatError(godotNotFound()) }] };
          }
    
          // Check for display availability
          if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) {
            return {
              isError: true,
              content: [
                {
                  type: "text",
                  text: formatError({
                    message: "No display server available.",
                    suggestion:
                      "Screenshot requires a display server. Run Godot with a display (not --headless) " +
                      "or use a virtual framebuffer (Xvfb on Linux).",
                  }),
                },
              ],
            };
          }
    
          // Get project config for name (user:// path) and main scene
          const config = parseProjectGodot(ctx.projectDir);
          const projectName = config?.name ?? "unnamed project";
    
          // Determine which scene to capture
          let scenePath = args.scene ?? null;
          if (!scenePath) {
            // Read main scene from project.godot
            const projFile = resolve(ctx.projectDir, "project.godot");
            if (existsSync(projFile)) {
              const projContent = readFileSync(projFile, "utf-8");
              const mainSceneMatch = projContent.match(/run\/main_scene\s*=\s*"([^"]+)"/);
              if (mainSceneMatch) {
                scenePath = mainSceneMatch[1];
              }
            }
          }
    
          if (!scenePath) {
            return {
              isError: true,
              content: [
                {
                  type: "text",
                  text: formatError({
                    message: "No scene specified and no main scene found in project.godot.",
                    suggestion: "Specify a scene path, e.g., scene: \"res://scenes/main.tscn\"",
                  }),
                },
              ],
            };
          }
    
          try {
            // Generate and write temporary screenshot script
            const scriptPath = resolve(ctx.projectDir, ".mcp_screenshot.gd");
            writeFileSync(scriptPath, makeScreenshotScript(scenePath));
    
            try {
              const godotArgs = [
                "--path",
                ctx.projectDir,
                "-s",
                "res://.mcp_screenshot.gd",
              ];
    
              await spawnGodot(ctx.godotBinary, godotArgs, {
                cwd: ctx.projectDir,
                timeout: 15_000,
              });
    
              // Find the screenshot in user:// resolved paths
              const possiblePaths = getUserDataPaths(ctx.projectDir, projectName);
    
              let screenshotPath: string | null = null;
              for (const p of possiblePaths) {
                if (existsSync(p)) {
                  screenshotPath = p;
                  break;
                }
              }
    
              if (!screenshotPath) {
                return {
                  isError: true,
                  content: [
                    {
                      type: "text",
                      text: formatError({
                        message: "Screenshot captured but output file not found.",
                        suggestion:
                          `Checked user:// paths for project "${projectName}". ` +
                          "Verify the project name in project.godot matches the app_userdata directory. " +
                          `Paths checked: ${possiblePaths.join(", ")}`,
                      }),
                    },
                  ],
                };
              }
    
              const imageData = readFileSync(screenshotPath);
              const base64 = imageData.toString("base64");
    
              // Clean up screenshot file
              try { unlinkSync(screenshotPath); } catch { /* best effort */ }
    
              return {
                content: [
                  {
                    type: "image",
                    data: base64,
                    mimeType: "image/png",
                  },
                ],
              };
            } finally {
              // Clean up temp script
              try { unlinkSync(scriptPath); } catch { /* best effort */ }
            }
          } catch (err) {
            const message = err instanceof Error ? err.message : "Unknown error";
            return {
              isError: true,
              content: [
                {
                  type: "text",
                  text: formatError({
                    message: `Screenshot capture failed: ${message}`,
                    suggestion:
                      "Ensure Godot is installed and a display server is available. " +
                      "The project must be able to render to a viewport.",
                  }),
                },
              ],
            };
          }
        }
      );
    }
  • Generates the GDScript that loads a scene, waits 10 frames for rendering, captures the viewport texture as PNG, and saves it to user://mcp_screenshot.png.
    function makeScreenshotScript(scenePath: string | null): string {
      // If no scene specified, we capture whatever the project's main scene is.
      // We do this by not calling change_scene and letting the project run normally.
      const loadScene = scenePath
        ? `\tchange_scene_to_file("${scenePath}")`
        : "\t# Using project's main scene (run/main_scene from project.godot)";
    
      return `extends SceneTree
    
    func _init():
    ${loadScene}
    	# Wait for the scene tree to settle and render
    	for i in 10:
    		await process_frame
    	var image = get_root().get_viewport().get_texture().get_image()
    	image.save_png("user://mcp_screenshot.png")
    	quit()
    `;
    }
  • Resolves the Godot user:// data path for the screenshot file on the host OS (macOS, Windows, Linux), including fallback paths in the project directory.
    function getUserDataPaths(projectDir: string, projectName: string): string[] {
      const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
      const paths: string[] = [];
    
      switch (process.platform) {
        case "darwin":
          // macOS: ~/Library/Application Support/Godot/app_userdata/<project_name>/
          paths.push(
            join(home, "Library", "Application Support", "Godot", "app_userdata", projectName, "mcp_screenshot.png")
          );
          break;
    
        case "win32":
          // Windows: %APPDATA%\Godot\app_userdata\<project_name>\
          const appData = process.env.APPDATA ?? join(home, "AppData", "Roaming");
          paths.push(
            join(appData, "Godot", "app_userdata", projectName, "mcp_screenshot.png")
          );
          break;
    
        case "linux":
          // Linux: ~/.local/share/godot/app_userdata/<project_name>/
          const xdgData = process.env.XDG_DATA_HOME ?? join(home, ".local", "share");
          paths.push(
            join(xdgData, "godot", "app_userdata", projectName, "mcp_screenshot.png")
          );
          break;
      }
    
      // Fallback: check project directory itself
      paths.push(resolve(projectDir, "mcp_screenshot.png"));
      paths.push(resolve(projectDir, ".godot", "mcp_screenshot.png"));
    
      return paths;
    }
  • Input schema for the godot_screenshot tool: optional 'scene' string parameter (res:// path to the scene to capture, defaults to project's main scene).
    {
      scene: z
        .string()
        .optional()
        .describe("Scene to capture (e.g., res://scenes/main.tscn). If omitted, captures the project's main scene."),
    },
  • Import of registerScreenshot from screenshot.ts, and call at line 23 to register the tool with the MCP server.
    import { registerScreenshot } from "./tools/screenshot.js";
Behavior4/5

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

Annotations already indicate read-only and idempotent behavior. The description adds valuable behavioral context (display server requirement and return format) beyond annotations. No contradiction with annotations.

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?

Two sentences with no redundant information. Front-loaded with the core action and return type, followed by a critical usage note. Every sentence serves a purpose.

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

Completeness4/5

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

Given a simple tool with one optional parameter, the description covers the essential behavior, return format, and key constraint. No output schema exists, but the description explains the output format. Minor gap: doesn't mention potential errors or performance impacts.

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 sufficiently explains the optional 'scene' parameter. The description doesn't add extra meaning beyond 'If omitted, captures main scene', so baseline 3 is appropriate.

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

Purpose5/5

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

The description clearly states the tool's verb (Capture), resource (viewport screenshot), and return format (base64-encoded PNG). It distinguishes from sibling analysis tools by specifying 'screenshot' functionality.

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

Usage Guidelines4/5

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

The description includes an important precondition: 'Requires a display server (not headless mode)', which guides when not to use. However, it doesn't explicitly compare to alternatives or state when to choose this tool over siblings.

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/gregario/godot-forge'

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