Skip to main content
Glama
hqu

Datawrapper MCP

by hqu

export_chart_png

Export Datawrapper charts as PNG images with customizable dimensions, resolution, transparency, and borders for display or download.

Instructions

⚠️ DATAWRAPPER MCP TOOL ⚠️ This is part of the Datawrapper MCP server integration.


Export a Datawrapper chart as PNG and display it inline. The chart must be created first using create_chart. Supports high-resolution output via the zoom parameter. IMPORTANT: Only use this tool when the user explicitly requests to see the chart image or export it as PNG. Do not automatically export charts after creation unless specifically asked.

Args: chart_id: ID of the chart to export width: Width of the image in pixels (optional) height: Height of the image in pixels (optional) plain: If true, exports only the visualization without header/footer zoom: Scale multiplier for resolution, e.g., 2 = 2x resolution transparent: If true, exports with transparent background border_width: Margin around visualization in pixels border_color: Color of the border, e.g., '#FFFFFF' (optional)

Returns: PNG image content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chart_idYes
widthNo
heightNo
plainNo
zoomNo
transparentNo
border_widthNo
border_colorNo

Implementation Reference

  • The main handler logic for the `export_chart_png` tool, which takes chart ID and export parameters, generates the PNG, and encodes it as base64 for MCP response.
    async def export_chart_png(arguments: ExportChartPngArgs) -> list[ImageContent]:
        """Export a chart as PNG and return it as inline image."""
        chart_id = arguments["chart_id"]
    
        # Build export parameters
        export_params: dict[str, Any] = {}
        if "width" in arguments:
            export_params["width"] = arguments["width"]
        if "height" in arguments:
            export_params["height"] = arguments["height"]
        if "plain" in arguments:
            export_params["plain"] = arguments["plain"]
        if "zoom" in arguments:
            export_params["zoom"] = arguments["zoom"]
        if "transparent" in arguments:
            export_params["transparent"] = arguments["transparent"]
        if "border_width" in arguments:
            border_width = arguments["border_width"]
            assert isinstance(border_width, int)
            export_params["border_width"] = border_width
        if "border_color" in arguments:
            export_params["border_color"] = arguments["border_color"]
    
        # Get chart using factory function
        chart = get_chart(chart_id)
    
        # Export PNG using Pydantic instance method
        png_bytes = chart.export_png(**cast(dict[str, Any], export_params))
    
        # Encode to base64
        base64_data = base64.b64encode(png_bytes).decode("utf-8")
    
        return [
            ImageContent(
                type="image",
                data=base64_data,
                mimeType="image/png",
            )
        ]
  • Input argument schema for the `export_chart_png` tool.
    class ExportChartPngArgs(TypedDict):
        """Arguments for export_chart_png handler."""
    
        chart_id: str
        width: NotRequired[int]
        height: NotRequired[int]
        plain: NotRequired[bool]
        zoom: NotRequired[int]
        transparent: NotRequired[bool]
        border_width: NotRequired[int]
        border_color: NotRequired[str]

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/hqu/datawrapper-mcp'

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