Skip to main content
Glama

drawing_getCanvasPng

Export the current drawing canvas as a PNG image with base64 encoding for saving or sharing.

Instructions

Get the current drawing canvas as a PNG image (base64 encoded).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Tool handler in handleToolCall switch statement: checks for currentCanvas, calls drawingTool.getCanvasPngBase64, returns ImageContent with base64 PNG data.
    case "drawing_getCanvasPng": // Updated tool name
      if (!currentCanvas) {
        return {
          content: [{
            type: "text",
            text: "Error: No canvas generated. Please use 'drawing_generateCanvas' first.",
          }],
          isError: true,
        };
      }
      try {
        const base64Png = await drawingTool.getCanvasPngBase64(currentCanvas); // Use getCanvasPngBase64
        return {
          content: [
            {
              type: "text",
              text: "PNG image of the canvas (base64 encoded):", // Informative text
            },
            {
              type: "image", // Use 'image' content type
              data: base64Png,
              mimeType: "image/png",
            } as ImageContent,
          ],
          isError: false,
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Failed to get canvas PNG data: ${(error as Error).message}`,
          }],
          isError: true,
        };
      }
  • Input schema definition for the tool: no required parameters.
    {
      name: "drawing_getCanvasPng", // Changed name to reflect PNG output
      description: "Get the current drawing canvas as a PNG image (base64 encoded).", // Updated description
      inputSchema: {
        type: "object",
        properties: {}, // No input needed to get canvas data
        required: [],
      },
    },
  • index.ts:286-288 (registration)
    Registers all tools, including drawing_getCanvasPng, via ListToolsRequestSchema handler returning the TOOLS array.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: TOOLS,
    }));
  • Core PNG generation logic in Canvas class: populates PNG data from pixels and packs to base64 using pngjs.
    async getCanvasPngBase64(): Promise<string> {
        const png = new PNG({
            width: this.width,
            height: this.height,
            bitDepth: 8,
            colorType: 6, // truecolor with alpha
            inputColorType: 6,
        });
    
        for (let y = 0; y < this.height; y++) {
            for (let x = 0; x < this.width; x++) {
                const pixel = this.pixels[y][x];
                const idx = (y * this.width + x) << 2; // Faster than * 4
                png.data[idx] = pixel.r;
                png.data[idx + 1] = pixel.g;
                png.data[idx + 2] = pixel.b;
                png.data[idx + 3] = pixel.a;
            }
        }
    
        return new Promise<string>((resolve, reject) => {
            const chunks: Buffer[] = [];
            png.pack()
                .on('data', function(chunk) {
                    chunks.push(chunk);
                })
                .on('end', function() {
                    const pngBuffer = Buffer.concat(chunks);
                    const base64String = pngBuffer.toString('base64');
                    resolve(base64String);
                })
                .on('error', function(error) {
                    reject(error);
                });
        });
    }
  • Exported wrapper function for getCanvasPngBase64 that validates canvas and delegates to Canvas instance method.
    function getCanvasPngBase64(canvas: Canvas): Promise<string> {
        if (!(canvas instanceof Canvas)) {
            throw new Error("Invalid canvas object provided.");
        }
        return canvas.getCanvasPngBase64();
    }
Behavior3/5

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

With no annotations provided, the description carries full burden. It clearly indicates this is a read operation ('Get') that returns encoded image data, but doesn't disclose behavioral traits like performance characteristics, error conditions, or whether it requires a pre-existing canvas. It adds basic context about the output format but lacks deeper operational details.

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?

Single sentence that's perfectly front-loaded with the core purpose, zero wasted words, and appropriately sized for a simple retrieval tool. Every element ('Get', 'current drawing canvas', 'PNG image', 'base64 encoded') earns its place by clarifying the operation.

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

Completeness3/5

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

For a zero-parameter read tool with no annotations and no output schema, the description adequately covers the basic operation but lacks completeness about what 'current' means (e.g., requires an existing canvas), error handling, or response structure. It's minimally viable but leaves contextual gaps an agent might need.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters with 100% schema description coverage, so the schema fully documents the empty parameter set. The description appropriately doesn't discuss parameters, maintaining focus on the tool's purpose. Baseline for 0 parameters is 4, as no parameter guidance is needed.

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 ('Get') and resource ('current drawing canvas'), specifying the output format ('PNG image') and encoding ('base64 encoded'). It distinguishes from siblings like drawing_fillRectangle (modification) and drawing_getCanvasData (different data format).

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 when a PNG representation of the canvas is needed, but doesn't explicitly state when to use this vs. alternatives like drawing_getCanvasData (which might return raw data). No exclusions or prerequisites are mentioned, leaving some ambiguity about optimal tool selection.

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/flrngel/mcp-painter'

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