get_dashboard_cards
Retrieve all cards and their layout details (id, name, display type, size, position) for a specific Metabase dashboard.
Instructions
Get the cards and their layout information for a specific dashboard.
Returns each card's id, name, display type, size, and position on the dashboard grid (col, row, size_x, size_y).
Args: dashboard_id: The ID of the dashboard.
Returns: A list of dashboard card objects with layout and card metadata.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dashboard_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:1430-1477 (handler)Handler function for the get_dashboard_cards tool. Fetches dashboard data from Metabase API, extracts dashcard layout info (position, size, inline parameters), and optionally includes card metadata (name, display, description) from the nested card object.
@mcp.tool async def get_dashboard_cards(dashboard_id: int, ctx: Context) -> list[dict[str, Any]]: """ Get the cards and their layout information for a specific dashboard. Returns each card's id, name, display type, size, and position on the dashboard grid (col, row, size_x, size_y). Args: dashboard_id: The ID of the dashboard. Returns: A list of dashboard card objects with layout and card metadata. """ try: await ctx.info(f"Fetching cards layout for dashboard {dashboard_id}") result = await metabase_client.request("GET", f"/dashboard/{dashboard_id}") dashcards = result.get("dashcards", result.get("ordered_cards", [])) await ctx.info( f"Successfully retrieved {len(dashcards)} cards from dashboard {dashboard_id}" ) cards_layout = [] for dashcard in dashcards: card_info: dict[str, Any] = { "dashcard_id": dashcard.get("id"), "card_id": dashcard.get("card_id"), "col": dashcard.get("col"), "row": dashcard.get("row"), "size_x": dashcard.get("size_x"), "size_y": dashcard.get("size_y"), "inline_parameters": dashcard.get("inline_parameters") or [], } card = dashcard.get("card") if card: card_info["card_name"] = card.get("name") card_info["card_display"] = card.get("display") card_info["card_description"] = card.get("description") cards_layout.append(card_info) return cards_layout except Exception as e: error_msg = f"Error fetching dashboard {dashboard_id} cards: {e}" await ctx.error(error_msg) raise ToolError(error_msg) from e - server.py:1430-1431 (registration)Tool registration using the @mcp.tool decorator on the get_dashboard_cards function, registering it with the FastMCP server instance.
@mcp.tool async def get_dashboard_cards(dashboard_id: int, ctx: Context) -> list[dict[str, Any]]: - server.py:1432-1443 (schema)Docstring defining the input schema (dashboard_id: int) and output schema (list of dashboard card objects with layout/card metadata).
""" Get the cards and their layout information for a specific dashboard. Returns each card's id, name, display type, size, and position on the dashboard grid (col, row, size_x, size_y). Args: dashboard_id: The ID of the dashboard. Returns: A list of dashboard card objects with layout and card metadata. """