Skip to main content
Glama
CW-Codewalnut

Metabase MCP Server

create_metabase_user

Add new users to Metabase by providing their name, email, password, and optional group assignments or permissions.

Instructions

Create a new user in Metabase.

Args: first_name (str): User's first name. last_name (str): User's last name. email (str): Email address. password (str): Account password. login_attributes (dict, optional): Additional login metadata. group_ids (list, optional): List of group IDs to assign the user. is_superuser (bool, optional): Whether the user is a superuser.

Returns: Dict[str, Any]: Created user metadata.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
first_nameYes
last_nameYes
emailYes
passwordYes
login_attributesNo
group_idsNo
is_superuserNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The create_metabase_user tool handler function. Decorated with @mcp.tool(), it accepts user details (first_name, last_name, email, password) and optional parameters (login_attributes, group_ids, is_superuser), constructs a payload, and makes a POST request to /api/user endpoint to create a new Metabase user.
    @mcp.tool()
    async def create_metabase_user(
        first_name: str,
        last_name: str,
        email: str,
        password: str,
        login_attributes: Optional[Dict[str, Any]] = None,
        group_ids: Optional[List] = None,
        is_superuser: Optional[bool] = None
    ) -> Dict[str, Any]:
        """
        Create a new user in Metabase.
    
        Args:
            first_name (str): User's first name.
            last_name (str): User's last name.
            email (str): Email address.
            password (str): Account password.
            login_attributes (dict, optional): Additional login metadata.
            group_ids (list, optional): List of group IDs to assign the user.
            is_superuser (bool, optional): Whether the user is a superuser.
    
        Returns:
            Dict[str, Any]: Created user metadata.
        """
        payload = {
            "first_name": first_name,
            "last_name": last_name,
            "email": email,
            "password": password,
        }
        if login_attributes is not None:
            payload["login_attributes"] = login_attributes
        if group_ids is not None:
            payload["group_ids"] = group_ids
        if is_superuser is not None:
            payload["is_superuser"] = is_superuser
    
        logger.info(f"Creating user '{email}'")
        return await make_metabase_request(RequestMethod.POST, "/api/user", json=payload)
  • The @mcp.tool() decorator registers the create_metabase_user function as an MCP tool, making it available to clients via the Model Context Protocol.
    @mcp.tool()
  • The make_metabase_request helper function that handles all HTTP communication with the Metabase API. It validates environment variables, manages the HTTP session, handles request/response processing, error handling, and sanitizes sensitive data (like passwords) in logs. This function is called by create_metabase_user to make the actual API request.
    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
  • Type annotations defining the input schema for create_metabase_user. Parameters include required fields (first_name: str, last_name: str, email: str, password: str) and optional fields (login_attributes: Optional[Dict[str, Any]], group_ids: Optional[List], is_superuser: Optional[bool]). FastMCP uses these type hints for automatic schema generation and validation.
    async def create_metabase_user(
        first_name: str,
        last_name: str,
        email: str,
        password: str,
        login_attributes: Optional[Dict[str, Any]] = None,
        group_ids: Optional[List] = None,
        is_superuser: Optional[bool] = None
    ) -> Dict[str, Any]:
Behavior2/5

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

With no annotations provided, the description carries full burden but only states it 'creates' a user without disclosing behavioral traits like required permissions, whether it sends email notifications, rate limits, or error conditions. It mentions the return type but doesn't explain what 'Created user metadata' includes or potential side effects.

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 well-structured with a clear purpose statement followed by Args and Returns sections, making it easy to parse. It's appropriately sized, though the parameter explanations could be more detailed without sacrificing conciseness.

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?

Given the tool's complexity (7 parameters, mutation operation) and no annotations, the description is moderately complete but has gaps: it doesn't cover error handling, authentication needs, or how it differs from sibling tools. The output schema exists, so describing return values isn't necessary, but more behavioral context would improve completeness.

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?

Schema description coverage is 0%, so the description must compensate—it does by listing all 7 parameters with types and brief explanations, adding meaning beyond the schema's titles. However, it lacks details on format constraints (e.g., email validation, password complexity) or examples for optional parameters like 'login_attributes'.

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

Purpose5/5

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

The description clearly states 'Create a new user in Metabase' with specific verb ('Create') and resource ('user'), distinguishing it from sibling tools like 'update_metabase_user' or 'delete_metabase_user'. It precisely defines what the tool does without ambiguity.

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?

No guidance on when to use this tool versus alternatives like 'update_metabase_user' or 'get_metabase_users' is provided. The description lacks context about prerequisites, permissions needed, or typical use cases, offering only basic functional information.

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