Skip to main content
Glama
voducdan

metabase-mcp

by voducdan

add_card_to_dashboard

Add a card to a dashboard at a custom grid position and size. Provide the dashboard ID and card ID, then optionally set column, row, width, and height.

Instructions

Add an existing card to a dashboard at a specified position and size.

Args: dashboard_id: The ID of the dashboard to add the card to. card_id: The ID of the card to add. col: Column position on the dashboard grid (default: 0). row: Row position on the dashboard grid (default: 0). size_x: Width of the card in grid units (default: 6). size_y: Height of the card in grid units (default: 4).

Returns: The created dashboard card object.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dashboard_idYes
card_idYes
colNo
rowNo
size_xNo
size_yNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The `add_card_to_dashboard` tool implementation. It fetches the existing dashboard, preserves current dashcards with their layout and mappings, appends a new dashcard entry (with id=-1 to signal a new card), and PUTs the updated dashcards array to the Metabase API.
    @mcp.tool
    async def add_card_to_dashboard(
        dashboard_id: int,
        card_id: int,
        ctx: Context,
        col: int = 0,
        row: int = 0,
        size_x: int = 6,
        size_y: int = 4,
    ) -> dict[str, Any]:
        """
        Add an existing card to a dashboard at a specified position and size.
    
        Args:
            dashboard_id: The ID of the dashboard to add the card to.
            card_id: The ID of the card to add.
            col: Column position on the dashboard grid (default: 0).
            row: Row position on the dashboard grid (default: 0).
            size_x: Width of the card in grid units (default: 6).
            size_y: Height of the card in grid units (default: 4).
    
        Returns:
            The created dashboard card object.
        """
        try:
            await ctx.info(f"Adding card {card_id} to dashboard {dashboard_id}")
    
            # Fetch existing dashboard to get current dashcards
            dashboard = await metabase_client.request("GET", f"/dashboard/{dashboard_id}")
            existing_dashcards = dashboard.get("dashcards", dashboard.get("ordered_cards", []))
    
            # Preserve existing dashcards with their current layout and mappings
            dashcards = [
                {
                    "id": dc["id"],
                    "card_id": dc.get("card_id"),
                    "row": dc.get("row"),
                    "col": dc.get("col"),
                    "size_x": dc.get("size_x"),
                    "size_y": dc.get("size_y"),
                    "parameter_mappings": list(dc.get("parameter_mappings") or []),
                    "visualization_settings": dc.get("visualization_settings") or {},
                    "inline_parameters": list(dc.get("inline_parameters") or []),
                }
                for dc in existing_dashcards
            ]
    
            # Append new card with id: -1 to indicate a new entry
            dashcards.append({
                "id": -1,
                "card_id": card_id,
                "row": row,
                "col": col,
                "size_x": size_x,
                "size_y": size_y,
                "parameter_mappings": [],
                "visualization_settings": {},
            })
    
            result = await metabase_client.request(
                "PUT", f"/dashboard/{dashboard_id}", json={"dashcards": dashcards}
            )
            await ctx.info(
                f"Successfully added card {card_id} to dashboard {dashboard_id} at ({col}, {row})"
            )
    
            return result
        except Exception as e:
            error_msg = f"Error adding card {card_id} to dashboard {dashboard_id}: {e}"
            await ctx.error(error_msg)
            raise ToolError(error_msg) from e
  • server.py:1582-1582 (registration)
    The tool is registered via the `@mcp.tool` decorator on line 1582, which registers `add_card_to_dashboard` as an MCP tool on the FastMCP server instance.
    @mcp.tool

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4.3/5.0
Behavior3/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes the inputs and outputs but does not mention side effects, authentication needs, constraints (e.g., card must exist, dashboard must exist, or duplicate handling), or what happens on failure. This is adequate but minimal.

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

Conciseness5/5

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

The description is efficiently structured as a docstring with a brief summary followed by Args and Returns sections. Each line is necessary, no fluff, and the information is front-loaded with the main action.

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

Completeness4/5

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

The tool has 6 parameters, an output schema, and moderate complexity. The description covers inputs and the returned object. It lacks details about the grid coordinate system bounds, error cases (e.g., invalid position), or behavior when card already exists. These are minor gaps but do not severely hinder usage.

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?

The description provides meaningful explanations for all 6 parameters, including their role (e.g., 'Column position on the dashboard grid') and defaults. This adds significant value beyond the schema, which has 0% description coverage. Each parameter is clearly defined, enabling correct usage.

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 action: adding an existing card to a dashboard at a specified position and size. It distinguishes itself from siblings like create_card (which creates new cards) and get_dashboard_cards (which lists existing cards), making its purpose specific and unambiguous.

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

Usage Guidelines4/5

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

The description provides clear parameter details and implies usage for adding cards to dashboards, but it does not explicitly state when to use this tool versus alternatives like update_card_display or context about prerequisites. However, the context is clear enough for an agent to infer appropriate usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.