Skip to main content
Glama
CW-Codewalnut

Metabase MCP Server

delete_metabase_user

Remove user accounts from the Metabase business intelligence platform by specifying the user ID to manage access control and user administration.

Instructions

Delete a user from Metabase.

Args: user_id (int): ID of the user to delete.

Returns: Dict[str, Any]: Deletion confirmation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
user_idYes

Implementation Reference

  • The main handler function for the 'delete_metabase_user' tool. It is decorated with @mcp.tool() and accepts a user_id parameter to delete a user from Metabase via the DELETE /api/user/{user_id} endpoint.
    @mcp.tool()
    async def delete_metabase_user(user_id: int) -> Dict[str, Any]:
        """
        Delete a user from Metabase.
    
        Args:
            user_id (int): ID of the user to delete.
    
        Returns:
            Dict[str, Any]: Deletion confirmation.
        """
        logger.info(f"Deleting user {user_id}")
        return await make_metabase_request(RequestMethod.DELETE, f"/api/user/{user_id}")
  • The FastMCP instance initialization that enables tool registration via the @mcp.tool() decorator pattern.
    mcp = FastMCP("metabase", lifespan=app_lifespan)
  • The 'make_metabase_request' helper function that handles HTTP requests to the Metabase API. It manages the session, request construction, error handling, and response parsing for all API calls including the delete_metabase_user tool.
    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)

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