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
| Name | Required | Description | Default |
|---|---|---|---|
| component_id | Yes |
Implementation Reference
- penpot_mcp/server/mcp_server.py:389-394 (handler)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" }
- penpot_mcp/server/mcp_server.py:155-160 (registration)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")