Skip to main content
Glama

gmail_create_label

Create custom labels in Gmail to organize emails by project, priority, or category. Add optional color coding for visual identification and use nested labels with forward slashes for hierarchical organization.

Instructions

Create a new Gmail label with optional custom colors. Returns the new label's ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
label_nameYesName for the new label. Use forward slashes for nested labels (e.g., 'Projects/Work').
background_colorNoHex color code for label background (e.g., '#16a765'). Optional.
text_colorNoHex color code for label text (e.g., '#ffffff'). Optional.

Implementation Reference

  • MCP tool handler logic for 'gmail_create_label': validates input, checks for existing label, calls GmailClient.create_label, and formats response.
    elif name == "gmail_create_label":
        label_name = arguments.get("label_name")
        if not label_name:
            return [TextContent(type="text", text="Error: label_name is required.")]
        
        # Check if label already exists
        existing = await client.find_label_by_name(label_name)
        if existing:
            return [TextContent(
                type="text",
                text=f"Error: A label named '{label_name}' already exists (ID: {existing['id']})."
            )]
        
        background_color = arguments.get("background_color")
        text_color = arguments.get("text_color")
        
        result = await client.create_label(label_name, background_color, text_color)
        if result["success"]:
            label = result["label"]
            return [TextContent(
                type="text",
                text=f"Success: Created label '{label['name']}' with ID: {label['id']}"
            )]
        else:
            return [TextContent(type="text", text=f"Error: Failed to create label. {result['error']}")]
  • JSON schema definition for 'gmail_create_label' tool inputs: label_name (required), optional background_color and text_color.
    Tool(
        name="gmail_create_label",
        description="Create a new Gmail label with optional custom colors. Returns the new label's ID.",
        inputSchema={
            "type": "object",
            "properties": {
                "label_name": {
                    "type": "string",
                    "description": "Name for the new label. Use forward slashes for nested labels (e.g., 'Projects/Work')."
                },
                "background_color": {
                    "type": "string",
                    "description": "Hex color code for label background (e.g., '#16a765'). Optional."
                },
                "text_color": {
                    "type": "string",
                    "description": "Hex color code for label text (e.g., '#ffffff'). Optional."
                }
            },
            "required": ["label_name"]
        },
    ),
  • GmailClient.create_label method: constructs label body with name and optional colors, calls Gmail API labels.create, returns success/error with label details.
    async def create_label(self, name: str, background_color: str | None = None, text_color: str | None = None) -> dict:
        """Create a new Gmail label.
        
        Args:
            name: Label name (can include / for nested labels)
            background_color: Optional hex color for background (e.g., '#16a765')
            text_color: Optional hex color for text (e.g., '#ffffff')
            
        Returns:
            The created label object
        """
        try:
            label_body = {
                "name": name,
                "labelListVisibility": "labelShow",
                "messageListVisibility": "show",
            }
            
            if background_color or text_color:
                label_body["color"] = {}
                if background_color:
                    label_body["color"]["backgroundColor"] = background_color
                if text_color:
                    label_body["color"]["textColor"] = text_color
            
            result = self.service.users().labels().create(
                userId="me",
                body=label_body
            ).execute()
            
            logger.info(f"Created label: {name} (ID: {result['id']})")
            return {"success": True, "label": result}
            
        except HttpError as e:
            logger.error(f"Failed to create label: {e}")
            return {"success": False, "error": str(e)}
  • Server registration: list_tools handler returns GMAIL_TOOLS list which includes the 'gmail_create_label' tool definition.
    @server.list_tools()
    async def list_tools() -> list[Tool]:
        return GMAIL_TOOLS
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool creates a new label and returns an ID, but lacks critical details: it doesn't mention authentication requirements, rate limits, error conditions (e.g., duplicate label names), or whether the operation is idempotent. For a mutation tool with zero annotation coverage, this is a significant gap.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose ('Create a new Gmail label') and includes key details (optional colors, return value) without any wasted words. Every part earns its place by adding value.

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

Completeness2/5

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

Given this is a mutation tool with no annotations and no output schema, the description is incomplete. It mentions the return value (ID) but lacks other critical context: authentication needs, error handling, or behavioral traits like idempotency. For a tool that modifies Gmail state, this leaves significant gaps for an AI agent.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already fully documents all three parameters (label_name, background_color, text_color) with descriptions and optionality. The description adds no additional parameter semantics beyond what's in the schema, such as format examples or constraints, so it meets the baseline of 3.

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 the specific action ('Create a new Gmail label') and resource ('Gmail label'), distinguishing it from siblings like gmail_list_labels (read) or gmail_delete_label (delete). It also mentions the optional feature of custom colors, adding specificity beyond just the basic creation function.

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. It doesn't mention prerequisites (e.g., needing authentication), compare it to similar tools like gmail_rename_label for modifying existing labels, or specify scenarios where creating a label is appropriate versus unnecessary.

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/murphy360/mcp_gmail'

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