export_object
Export a specific design object from Penpot as an image by specifying file, page, and object IDs. Supports formats like PNG and SVG with adjustable scale for precise output.
Instructions
Export a Penpot design object as an image.
Args:
file_id: The ID of the Penpot file
page_id: The ID of the page containing the object
object_id: The ID of the object to export
export_type: Image format (png, svg, etc.)
scale: Scale factor for the exported image
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| export_type | No | png | |
| file_id | Yes | ||
| object_id | Yes | ||
| page_id | Yes | ||
| scale | No |
Implementation Reference
- penpot_mcp/server/mcp_server.py:217-270 (handler)The primary handler function for the 'export_object' MCP tool. It downloads the exported image from Penpot API, creates an MCP Image object, and optionally adds it to an HTTP image server.def export_object( file_id: str, page_id: str, object_id: str, export_type: str = "png", scale: int = 1) -> Image: """Export a Penpot design object as an image. Args: file_id: The ID of the Penpot file page_id: The ID of the page containing the object object_id: The ID of the object to export export_type: Image format (png, svg, etc.) scale: Scale factor for the exported image """ temp_filename = None try: import tempfile temp_dir = tempfile.gettempdir() temp_filename = os.path.join(temp_dir, f"{object_id}.{export_type}") output_path = self.api.export_and_download( file_id=file_id, page_id=page_id, object_id=object_id, export_type=export_type, scale=scale, save_to_file=temp_filename ) with open(output_path, "rb") as f: file_content = f.read() image = Image(data=file_content, format=export_type) # If HTTP server is enabled, add the image to the server if self.image_server and self.image_server.is_running: image_id = hashlib.md5(f"{file_id}:{page_id}:{object_id}".encode()).hexdigest() # Use the current image_server_url to ensure the correct port image_url = self.image_server.add_image(image_id, file_content, export_type) # Add HTTP URL to the image metadata image.http_url = image_url return image except Exception as e: if isinstance(e, CloudFlareError): raise Exception(f"CloudFlare Protection: {str(e)}") else: raise Exception(f"Export failed: {str(e)}") finally: if temp_filename and os.path.exists(temp_filename): try: os.remove(temp_filename) except Exception as e: print(f"Warning: Failed to delete temporary file {temp_filename}: {str(e)}") @self.mcp.tool()
- The function signature defines the input schema (parameters) and output type (Image) for the export_object tool.def export_object( file_id: str, page_id: str, object_id: str, export_type: str = "png", scale: int = 1) -> Image:
- penpot_mcp/server/mcp_server.py:217-217 (registration)The @self.mcp.tool() decorator registers this function as the MCP tool named 'export_object'.def export_object(