Skip to main content
Glama

godot_screenshot

Read-onlyIdempotent

Capture viewport screenshots from running Godot projects. Returns base64-encoded PNG images for documentation, testing, or debugging purposes.

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 that executes the godot_screenshot tool. Validates inputs, generates a GDScript to capture the viewport, spawns Godot process, locates the screenshot file in user:// paths, and returns the base64-encoded PNG image.
    async (args) => {
      if (!ctx.projectDir) {
        return { content: [{ type: "text", text: formatError(projectNotFound()) }] };
      }
      if (!ctx.godotBinary) {
        return { content: [{ type: "text", text: formatError(godotNotFound()) }] };
      }
    
      // Check for display availability
      if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) {
        return {
          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 {
          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 {
              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 {
          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.",
              }),
            },
          ],
        };
      }
    }
  • Input schema definition using Zod. Defines an optional 'scene' parameter that specifies which scene to capture (e.g., res://scenes/main.tscn). If omitted, captures the 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."),
    },
  • Registration function that registers the 'godot_screenshot' tool with the MCP server. Includes tool name, description, input schema, hints (readOnly, idempotent), and the handler function.
    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 { content: [{ type: "text", text: formatError(projectNotFound()) }] };
          }
          if (!ctx.godotBinary) {
            return { content: [{ type: "text", text: formatError(godotNotFound()) }] };
          }
    
          // Check for display availability
          if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) {
            return {
              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 {
              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 {
                  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 {
              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.",
                  }),
                },
              ],
            };
          }
        }
      );
    }
  • Helper function that generates GDScript code for capturing screenshots. The script loads a scene, waits 10 frames for rendering, captures the viewport, saves as PNG, and quits.
    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()
    `;
    }
  • Helper function that resolves Godot's user:// path to actual filesystem paths across platforms (macOS, Windows, Linux). Returns multiple possible paths to search for the screenshot file.
    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;
    }
Behavior4/5

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

Annotations already indicate read-only, non-open-world, and idempotent behavior. The description adds valuable context beyond this: it specifies the return format ('base64-encoded PNG image') and a key constraint ('requires a display server (not headless mode)'), which are not covered by annotations. This enhances understanding without contradicting the 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?

The description is front-loaded with the core purpose in the first sentence, followed by essential details in subsequent sentences. Every sentence earns its place by providing critical information (return format, constraint) without any waste, making it highly efficient and well-structured.

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 the tool's moderate complexity (capturing screenshots with a display server requirement), the description is mostly complete: it covers purpose, return format, and a key constraint. However, without an output schema, it could benefit from more detail on error conditions or edge cases, but the annotations and schema provide good support, leaving minor gaps.

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 input schema has 100% description coverage, fully documenting the single optional parameter. The description does not add any parameter-specific information beyond what the schema provides, such as syntax or format details. With high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't need to.

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 specific action ('capture a viewport screenshot') and resource ('from the running Godot project'), distinguishing it from siblings like godot_analyze_scene or godot_run_project. It precisely defines what the tool does without being vague or tautological.

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 provides clear context for when to use this tool (capturing screenshots from a running Godot project) and includes a prerequisite ('requires a display server'), but it does not explicitly state when not to use it or name alternatives among siblings. This gives good guidance but lacks explicit exclusions or comparisons.

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