Skip to main content
Glama
CW-Codewalnut

Metabase MCP Server

copy_metabase_dashboard

Duplicate an existing Metabase dashboard to create a new version with custom name, description, and collection placement. Optionally copy linked cards for comprehensive replication.

Instructions

Copy a dashboard.

Args: from_dashboard_id (int): ID of the source dashboard to copy. name (str): Name for the new dashboard. description (str, optional): Description for the new dashboard. collection_id (int, optional): Collection ID for the new dashboard. is_deep_copy (bool, optional): Whether to perform a deep copy (copy linked cards too). collection_position (int, optional): Position in the collection.

Returns: Dict[str, Any]: New dashboard metadata.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_dashboard_idYes
nameYes
descriptionNo
collection_idNo
is_deep_copyNo
collection_positionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for 'copy_metabase_dashboard' tool. It accepts dashboard copy parameters (from_dashboard_id, name, description, collection_id, is_deep_copy, collection_position), builds a payload, and makes a POST request to Metabase's /api/dashboard/{from_dashboard_id}/copy endpoint. Registered as an MCP tool via @mcp.tool() decorator.
    @mcp.tool()
    async def copy_metabase_dashboard(
        from_dashboard_id: int,
        name: str,
        description: Optional[str] = None,
        collection_id: Optional[int] = None,
        is_deep_copy: bool = False,
        collection_position: Optional[int] = None
    ) -> Dict[str, Any]:
        """
        Copy a dashboard.
    
        Args:
            from_dashboard_id (int): ID of the source dashboard to copy.
            name (str): Name for the new dashboard.
            description (str, optional): Description for the new dashboard.
            collection_id (int, optional): Collection ID for the new dashboard.
            is_deep_copy (bool, optional): Whether to perform a deep copy (copy linked cards too).
            collection_position (int, optional): Position in the collection.
    
        Returns:
            Dict[str, Any]: New 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 is_deep_copy is not None:
            payload["is_deep_copy"] = is_deep_copy
        if collection_position is not None:
            payload["collection_position"] = collection_position
    
        logger.info(f"Copying dashboard {from_dashboard_id} to '{name}'")
        return await make_metabase_request(
            RequestMethod.POST,
            f"/api/dashboard/{from_dashboard_id}/copy",
            json=payload
        )
  • Helper function 'make_metabase_request' that handles all HTTP communication with the Metabase API. It creates authenticated requests with proper headers, handles errors (connection errors, 5xx responses, non-JSON responses), and returns parsed JSON responses.
    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,
                timeout=aiohttp.ClientTimeout(total=30),
                headers=request_headers,
                data=data,
                params=params,
                json=json,
            )
    
            try:
                # Handle 500 errors with more detailed info
                if response.status >= 500:
                    error_text = await response.text()
                    logger.error(f"Server error {response.status}: {error_text[:200]}")
                    raise MetabaseResponseError(response.status, f"Server Error: {error_text[:200]}", endpoint)
                
                response.raise_for_status()
                response_data = await response.json()
                
                # Ensure the response is a dictionary for FastMCP compatibility
                return ensure_dict_response(response_data)
                
            except aiohttp.ContentTypeError:
                # Handle empty responses or non-JSON responses
                content = await response.text()
                if not content:
                    return {"data": {}}
                logger.warning(f"Received non-JSON response: {content}")
                return {"data": content}
    
        except aiohttp.ClientConnectionError as e:
            logger.error(f"Connection error: {str(e)}")
            raise MetabaseConnectionError("Metabase is unreachable. Is the Metabase server running?") from e
        except aiohttp.ClientResponseError as e:
            logger.error(f"Response error: {e.status}, {e.message}, {e.request_info.url}")
            raise MetabaseResponseError(e.status, e.message, str(e.request_info.url)) from e
        except Exception as e:
            logger.error(f"Request error: {str(e)}")
            raise RuntimeError(f"Request error: {str(e)}") from e
  • FastMCP instance initialization. The 'mcp' object is created with the name 'metabase' and a lifespan context manager. This object is used to register tools via the @mcp.tool() decorator.
    # Initialize FastMCP agent
    mcp = FastMCP("metabase", lifespan=app_lifespan)
  • RequestMethod enum defining HTTP methods (GET, POST, PUT, DELETE) used for API requests. The copy_metabase_dashboard handler uses RequestMethod.POST for the copy operation.
    from enum import Enum, auto
    
    class RequestMethod(Enum):
        GET = auto()
        POST = auto()
        PUT = auto()
        DELETE = auto()
    
        def __str__(self):
            return self.name
Behavior2/5

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

No annotations are provided, so the description carries full burden. While it mentions the tool copies a dashboard and describes parameters, it doesn't disclose important behavioral traits: whether this requires specific permissions, whether the copy is immediate or asynchronous, what happens if the source dashboard doesn't exist, or whether there are rate limits. The 'is_deep_copy' parameter hint is useful but insufficient for full transparency.

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

Conciseness4/5

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

The description is appropriately sized and well-structured with clear sections (Args, Returns). The opening sentence states the core purpose concisely. The parameter explanations are efficient, though the 'Returns' section could be more specific about what 'new dashboard metadata' includes. Overall, it's front-loaded and wastes little space.

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

Completeness3/5

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

For a mutation tool with 6 parameters and no annotations, the description is adequate but has gaps. The output schema exists, so return values don't need explanation. However, it lacks context about permissions, error conditions, and how this tool relates to siblings. Given the complexity of dashboard copying operations, more behavioral context would be helpful despite the parameter documentation.

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

Parameters4/5

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

With 0% schema description coverage, the description compensates well by explaining all 6 parameters in the Args section, adding meaning beyond the bare schema. It clarifies optional vs required parameters and provides semantic context for each (e.g., 'is_deep_copy' copies linked cards). However, it doesn't explain parameter constraints like valid ID ranges or name length limits.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'copy' and resource 'dashboard', making the purpose evident. It distinguishes from siblings like 'create_metabase_dashboard' by specifying it's a copy operation rather than creating from scratch. However, it doesn't explicitly contrast with other dashboard-related tools like 'update_metabase_dashboard' or 'get_dashboard_by_id'.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'create_metabase_dashboard' and 'update_metabase_dashboard', there's no indication whether this should be used for duplicating existing dashboards versus creating new ones from templates or modifying existing ones. The description is purely functional without contextual guidance.

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

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