create_metabase_dashboard
Create a new dashboard in Metabase to visualize and organize data insights with customizable parameters, tabs, and collection settings.
Instructions
Create a new dashboard in Metabase.
Args: name (str): Name of the dashboard. description (str, optional): Dashboard description. collection_id (int, optional): Collection ID. parameters (list, optional): Parameters for the dashboard. tabs (list, optional): Tabs for the dashboard (list of {"name": "Tab Name"}). cache_ttl (int, optional): Cache time to live in seconds. collection_position (int, optional): Position in the collection.
Returns: Dict[str, Any]: Created dashboard metadata.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| description | No | ||
| collection_id | No | ||
| parameters | No | ||
| tabs | No | ||
| cache_ttl | No | ||
| collection_position | No |
Implementation Reference
- src/metabase_mcp_server.py:729-770 (handler)The create_metabase_dashboard tool handler function that creates a new dashboard in Metabase. Accepts parameters for name, description, collection_id, parameters, tabs, cache_ttl, and collection_position. Constructs a payload and makes a POST request to /api/dashboard endpoint.
async def create_metabase_dashboard( name: str, description: Optional[str] = None, collection_id: Optional[int] = None, parameters: Optional[List] = None, tabs: Optional[List[Dict[str, str]]] = None, cache_ttl: Optional[int] = None, collection_position: Optional[int] = None ) -> Dict[str, Any]: """ Create a new dashboard in Metabase. Args: name (str): Name of the dashboard. description (str, optional): Dashboard description. collection_id (int, optional): Collection ID. parameters (list, optional): Parameters for the dashboard. tabs (list, optional): Tabs for the dashboard (list of {"name": "Tab Name"}). cache_ttl (int, optional): Cache time to live in seconds. collection_position (int, optional): Position in the collection. Returns: Dict[str, Any]: Created dashboard metadata. """ payload = { "name": name, } if description is not None: payload["description"] = description if collection_id is not None: payload["collection_id"] = collection_id if parameters is not None: payload["parameters"] = parameters if tabs is not None: payload["tabs"] = tabs if cache_ttl is not None: payload["cache_ttl"] = cache_ttl if collection_position is not None: payload["collection_position"] = collection_position logger.info(f"Creating dashboard '{name}'") return await make_metabase_request(RequestMethod.POST, "/api/dashboard", json=payload) - src/metabase_mcp_server.py:728-728 (registration)The @mcp.tool() decorator registers the create_metabase_dashboard function as an MCP tool, making it available for invocation through the Model Context Protocol.
@mcp.tool() - src/metabase_mcp_server.py:162-210 (helper)The make_metabase_request helper function that handles all HTTP requests to the Metabase API. Used by create_metabase_dashboard to make the actual POST request to /api/dashboard endpoint.
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}") # Log request payload for debugging (omit sensitive info) if json and logger.level <= logging.DEBUG: sanitized_json = {**json} if 'password' in sanitized_json: sanitized_json['password'] = '********' logger.debug(f"Request payload: {sanitized_json}") response = await session.request( method=method.name, url=endpoint, - src/models/dashboard_tab.py:4-14 (schema)DashboardTab dataclass model that represents a tab within a Metabase dashboard. Contains id (optional) and name fields. Referenced in the create_metabase_dashboard function signature for the tabs parameter.
@dataclass class DashboardTab: """ Represents a tab within a Metabase dashboard. Attributes: id (Optional[int]): The tab ID, optional for new tabs name (str): The name of the tab """ id: Optional[int] = None name: str = ""