Skip to main content
Glama
hqu

Datawrapper MCP

by hqu

create_chart

Create customizable Datawrapper charts by specifying data, chart type, and configuration settings for visualizations with full control over properties like title, axes, colors, and styling.

Instructions

⚠️ THIS IS THE DATAWRAPPER INTEGRATION ⚠️ Use this MCP tool for ALL Datawrapper chart creation.

DO NOT: ❌ Install the 'datawrapper' Python package ❌ Use the Datawrapper API directly ❌ Import 'from datawrapper import ...' ❌ Run pip install datawrapper

This MCP server IS the complete Datawrapper integration. All Datawrapper operations should use the MCP tools provided by this server.


Create a Datawrapper chart with full control using Pydantic models. This allows you to specify all chart properties including title, description, visualization settings, axes, colors, and more. The chart_config should be a complete Pydantic model dict matching the schema for the chosen chart type.

BEST PRACTICES:

  • Start simple, then add customization based on user feedback

  • Only apply styling when requested or when it significantly improves readability

  • Let Datawrapper handle axis scaling automatically unless there's a specific reason to override

QUICK EXAMPLES:

  1. Basic chart with title: chart_config = { "title": "Monthly Sales", "intro": "Sales data for Q1 2024" }

  2. Chart with custom colors: chart_config = { "title": "Product Comparison", "color_category": { "Product A": "#1f77b4", "Product B": "#ff7f0e" } }

  3. Styled line chart: chart_config = { "title": "Sales Trends", "lines": [ {"column": "sales", "width": "style2", "interpolation": "curved"} ], "custom_range_y": [0, 1000] }

STYLING WORKFLOW:

  1. Use list_chart_types to see available chart types

  2. Use get_chart_schema to explore all options for your chosen type

  3. Refer to https://datawrapper.readthedocs.io/en/latest/ for detailed examples

  4. Build your chart_config with the desired styling properties

Common styling patterns:

  • Colors: {"color_category": {"sales": "#1d81a2", "profit": "#15607a"}}

  • Line styling: {"lines": [{"column": "sales", "width": "style1", "interpolation": "curved"}]}

  • Axis ranges: {"custom_range_y": [0, 100], "custom_range_x": [2020, 2024]} NOTE: Datawrapper's automatic axis scaling is excellent. Only set custom ranges when you need specific customization (e.g., comparing multiple charts, forcing zero baseline for specific analytical reasons, or matching a house style guide).

  • Grid formatting: {"y_grid_format": "0", "x_grid": "on", "y_grid": "on"}

  • Tooltips: {"tooltip_number_format": "00.00", "tooltip_x_format": "YYYY"}

  • Annotations: {"text_annotations": [{"x": "2023", "y": 50, "text": "Peak"}]}

See the documentation for chart-type specific examples and advanced patterns.

Args: data: Chart data. RECOMMENDED: Pass data inline as a list or dict. PREFERRED FORMATS (use these first): 1. List of records (RECOMMENDED): [{"year": 2020, "sales": 100}, {"year": 2021, "sales": 150}] 2. Dict of arrays: {"year": [2020, 2021], "sales": [100, 150]} 3. JSON string of format 1 or 2: '[{"year": 2020, "sales": 100}]' ALTERNATIVE (only for extremely large datasets where inline data is impractical): 4. File path to CSV or JSON: "/path/to/data.csv" or "/path/to/data.json" chart_type: Type of chart to create. Use list_chart_types to see all available types. Common types: bar, line, area, arrow, column, multiple_column, scatter, stacked_bar chart_config: Complete chart configuration as a Pydantic model dict

Returns: Chart ID and editor URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYes
chart_typeYes
chart_configYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler implementation for `create_chart` which delegates to either a low-level Datawrapper API call for maps or a Pydantic-based chart class for standard charts.
    async def create_chart(arguments: CreateChartArgs) -> list[TextContent]:
        """Create a chart with full Pydantic model configuration."""
        chart_type = arguments["chart_type"]
    
        # Convert data to DataFrame
        df = json_to_dataframe(arguments["data"])
    
        # Map chart types are not currently represented by Pydantic chart classes,
        # so route those through the low-level Datawrapper API.
        if chart_type in MAP_TYPE_ALIASES:
            token = os.getenv("DATAWRAPPER_ACCESS_TOKEN")
            if not token:
                raise ValueError("DATAWRAPPER_ACCESS_TOKEN environment variable is required")
    
            api_type = MAP_TYPE_ALIASES[chart_type]
            cfg = arguments.get("chart_config", {}) or {}
            title = cfg.get("title", "New Map")
    
            dw = Datawrapper(access_token=token)
            created = dw.create_chart(title=title, chart_type=api_type, data=df)
            chart_id = created.get("id")
    
            # Apply chart config as metadata blocks (best effort).
            metadata_updates: dict[str, Any] = {}
            describe_fields = [
                "title",
                "intro",
                "notes",
                "byline",
                "source-name",
                "source-url",
                "aria-description",
            ]
            describe = {k: cfg[k] for k in describe_fields if k in cfg}
            if describe:
                metadata_updates["describe"] = describe
    
            visualize = {k: v for k, v in cfg.items() if k not in set(describe_fields)}
            if visualize:
                metadata_updates["visualize"] = visualize
    
            if metadata_updates:
                dw.update_chart(chart_id=chart_id, metadata=metadata_updates)
    
            edit_url = f"https://app.datawrapper.de/edit/{chart_id}/visualize#refine"
            result = {
                "chart_id": chart_id,
                "chart_type": chart_type,
                "title": title,
                "edit_url": edit_url,
                "message": (
                    f"Chart created successfully! Edit it at: {edit_url}\n"
                    f"Use publish_chart with chart_id '{chart_id}' to make it public."
                ),
            }
            return [TextContent(type="text", text=json.dumps(result, indent=2))]
    
        # Get chart class and validate config
        chart_class: type[Any] = CHART_CLASSES[chart_type]
    
        # Validate and create chart using Pydantic model
        try:
            chart = chart_class.model_validate(arguments["chart_config"])
        except Exception as e:
            raise ValueError(
                f"Invalid chart configuration: {str(e)}\n\n"
                f"Use get_chart_schema with chart_type '{chart_type}' "
                f"to see the valid schema."
            )
    
        # Set data on chart instance
        chart.data = df
    
        # Create chart using Pydantic instance method
        chart.create()
    
        result = {
            "chart_id": chart.chart_id,
            "chart_type": chart_type,
            "title": chart.title,
            "edit_url": chart.get_editor_url(),
            "message": (
                f"Chart created successfully! Edit it at: {chart.get_editor_url()}\n"
                f"Use publish_chart with chart_id '{chart.chart_id}' to make it public."
            ),
        }
    
        return [TextContent(type="text", text=json.dumps(result, indent=2))]
  • Input schema for the `create_chart` tool arguments.
    class CreateChartArgs(TypedDict):
        """Arguments for create_chart handler."""
  • server.py:208-217 (registration)
    Registration of the `create_chart` tool in the MCP server.
    try:
        arguments = cast(
            CreateChartArgs,
            {
                "data": data,
                "chart_type": chart_type,
                "chart_config": chart_config,
            },
        )
        result = await create_chart_handler(arguments)
Behavior4/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It does an excellent job describing workflow patterns, best practices, and constraints (e.g., 'Let Datawrapper handle axis scaling automatically unless there's a specific reason to override'). It explains the return format ('Chart ID and editor URL') and provides extensive examples. The only minor gap is explicit mention of authentication requirements or rate limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is comprehensive but lengthy (over 700 words). While well-structured with clear sections (warning, purpose, best practices, examples, workflow, parameter details), it could be more front-loaded. The core purpose appears after the warning section, and some examples could be streamlined. Every sentence adds value, but the overall length reduces conciseness.

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

Completeness5/5

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

Given the complexity (3 parameters with nested objects, 0% schema coverage, no annotations, but with output schema), the description is exceptionally complete. It covers purpose, usage guidelines, parameter semantics, workflow patterns, examples, and return values. The output schema exists, so the description appropriately focuses on explaining parameters and behavior rather than return format details.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing detailed semantic explanations for all three parameters. For 'data', it explains recommended formats, preferred order, and alternative approaches. For 'chart_type', it references sibling tools and provides common examples. For 'chart_config', it explains this should be 'a complete Pydantic model dict' and provides extensive examples and styling patterns.

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 tool's purpose: 'Create a Datawrapper chart with full control using Pydantic models.' It specifies the verb ('Create'), resource ('Datawrapper chart'), and scope ('full control'), distinguishing it from siblings like update_chart or delete_chart. The initial warning section reinforces this is the primary creation tool for Datawrapper integration.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool versus alternatives. It starts with a strong directive: 'Use this MCP tool for ALL Datawrapper chart creation' and lists specific alternatives to avoid (Python package, direct API). It also references sibling tools like list_chart_types and get_chart_schema for preparatory work, and mentions styling workflows that guide when to apply customization.

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

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