Skip to main content
Glama

get_rendered_component

Generates a rendered image of a design component by specifying its ID, facilitating programmatic interaction with Penpot design files for automated workflows.

Instructions

Return a rendered component image by its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
component_idYes

Implementation Reference

  • The handler function for the 'get_rendered_component' MCP tool. It retrieves a pre-rendered component image from the server's in-memory cache (self.rendered_components) using the provided component_id (a hash). Raises an exception if not found. This function is registered both as a tool (line 389) and as a resource (similar code at lines 155-160).
    @self.mcp.tool() def get_rendered_component(component_id: str) -> Image: """Return a rendered component image by its ID.""" if component_id in self.rendered_components: return self.rendered_components[component_id] raise Exception(f"Component with ID {component_id} not found")
  • Helper code within the 'get_object_tree' tool that generates and caches the rendered component image using 'export_object', computes the image_id hash, stores it in self.rendered_components, and provides the image URI for access via the 'get_rendered_component' tool/resource.
    try: image = export_object( file_id=file_id, page_id=page_id, object_id=object_id ) image_id = hashlib.md5(f"{file_id}:{object_id}".encode()).hexdigest() self.rendered_components[image_id] = image # Image URI preferences: # 1. HTTP server URL if available # 2. Fallback to MCP resource URI image_uri = f"render_component://{image_id}" if hasattr(image, 'http_url'): final_result["image"] = { "uri": image.http_url, "mcp_uri": image_uri, "format": image.format if hasattr(image, 'format') else "png" } else: final_result["image"] = { "uri": image_uri, "format": image.format if hasattr(image, 'format') else "png" }
  • Registration of 'get_rendered_component' as an MCP resource (rendered-component://{component_id}). Identical handler logic to the tool version, allowing direct access to cached rendered images via MCP URIs.
    @self.mcp.resource("rendered-component://{component_id}", mime_type="image/png") def get_rendered_component(component_id: str) -> Image: """Return a rendered component image by its ID.""" if component_id in self.rendered_components: return self.rendered_components[component_id] raise Exception(f"Component with ID {component_id} not found")

Other Tools

Related 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/montevive/penpot-mcp'

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