Skip to main content
Glama
CW-Codewalnut

Metabase MCP Server

get_dashboard_items

Retrieve all items from a Metabase dashboard using its ID to access charts, cards, and visualizations for data analysis and reporting.

Instructions

Get all items in a dashboard.

Args: dashboard_id (int): ID of the dashboard.

Returns: Dict[str, Any]: All items in the dashboard.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dashboard_idYes

Implementation Reference

  • The get_dashboard_items tool implementation - an async function decorated with @mcp.tool() that takes a dashboard_id parameter and returns all items in the dashboard by making a GET request to the Metabase API endpoint /api/dashboard/{dashboard_id}/items
    @mcp.tool()
    async def get_dashboard_items(dashboard_id: int) -> Dict[str, Any]:
        """
        Get all items in a dashboard.
    
        Args:
            dashboard_id (int): ID of the dashboard.
    
        Returns:
            Dict[str, Any]: All items in the dashboard.
        """
        logger.info(f"Getting items for dashboard {dashboard_id}")
        return await make_metabase_request(RequestMethod.GET, f"/api/dashboard/{dashboard_id}/items")
  • Helper function make_metabase_request that handles HTTP requests to the Metabase API, used by get_dashboard_items to fetch dashboard items
    async def make_metabase_request(
        method: RequestMethod,
        endpoint: str,
        data: Optional[Dict[str, Any] | bytes] = None,
        params: Optional[Dict[str, Any]] = None,
        json: Any = None,
        headers: Optional[Dict[str, str]] = None,
    ) -> Dict[str, Any]:
        """
        Make a request to the Metabase API.
        
        Args:
            method: HTTP method to use (GET, POST, PUT, DELETE)
            endpoint: API endpoint path
            data: Request data (for form data)
            params: URL parameters
            json: JSON request body
            headers: Additional headers
            
        Returns:
            Dict[str, Any]: Response data
            
        Raises:
            MetabaseConnectionError: When the Metabase server is unreachable
            MetabaseResponseError: When Metabase returns a non-2xx status code
            RuntimeError: For other errors
        """
        
        if not METABASE_URL or not METABASE_API_KEY:
            raise RuntimeError("METABASE_URL or METABASE_API_KEY environment variable is not set. Metabase API requests will fail.")
    
        if session is None:
            raise RuntimeError("HTTP session is not initialized. Ensure app_lifespan was called.")
    
        try:
            request_headers = headers or {}
            
            logger.debug(f"Making {method.name} request to {METABASE_URL}{endpoint}")

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/CW-Codewalnut/metabase-mcp-server'

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