Skip to main content
Glama

gmail_delete_label

Delete custom labels from Gmail by name or ID to organize your inbox. Requires confirmation before removal and cannot delete system labels.

Instructions

Delete a Gmail label by name or ID. Cannot delete system labels. Requires confirmation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
label_nameNoName of the label to delete. Provide either label_name or label_id.
label_idNoID of the label to delete. Provide either label_name or label_id.
confirmYesMust be true to actually delete. Set false to preview what would be deleted.

Implementation Reference

  • Registration of the 'gmail_delete_label' tool including its input schema, description, and parameters.
    Tool(
        name="gmail_delete_label",
        description="Delete a Gmail label by name or ID. Cannot delete system labels. Requires confirmation.",
        inputSchema={
            "type": "object",
            "properties": {
                "label_name": {
                    "type": "string",
                    "description": "Name of the label to delete. Provide either label_name or label_id."
                },
                "label_id": {
                    "type": "string",
                    "description": "ID of the label to delete. Provide either label_name or label_id."
                },
                "confirm": {
                    "type": "boolean",
                    "description": "Must be true to actually delete. Set false to preview what would be deleted."
                }
            },
            "required": ["confirm"]
        },
    ),
  • Handler logic for executing the 'gmail_delete_label' tool: validates input, finds label by name if needed, requires confirmation, calls client.delete_label, and returns success/error message.
    elif name == "gmail_delete_label":
        label_id = arguments.get("label_id")
        label_name = arguments.get("label_name")
        confirm = arguments.get("confirm", False)
        
        if not label_id and not label_name:
            return [TextContent(type="text", text="Error: Provide either label_id or label_name.")]
        
        # Find label by name if ID not provided
        if not label_id:
            label = await client.find_label_by_name(label_name)
            if not label:
                return [TextContent(type="text", text=f"Error: Label not found: {label_name}")]
            label_id = label["id"]
            found_name = label["name"]
        else:
            found_name = label_name or label_id
        
        if not confirm:
            return [TextContent(
                type="text",
                text=f"Preview: Label '{found_name}' (ID: {label_id}) would be deleted. Set confirm=true to proceed."
            )]
        
        result = await client.delete_label(label_id)
        if result["success"]:
            return [TextContent(type="text", text=f"Success: Deleted label '{found_name}'.")]
        else:
            return [TextContent(type="text", text=f"Error: Failed to delete label. {result['error']}")]
  • Core implementation of label deletion using Gmail API: calls service.users().labels().delete and handles errors.
    async def delete_label(self, label_id: str) -> dict:
        """Delete a Gmail label.
        
        Args:
            label_id: The ID of the label to delete
            
        Returns:
            Success/error dict
        """
        try:
            self.service.users().labels().delete(
                userId="me",
                id=label_id
            ).execute()
            
            logger.info(f"Deleted label: {label_id}")
            return {"success": True, "deleted_label_id": label_id}
            
        except HttpError as e:
            logger.error(f"Failed to delete label: {e}")
            return {"success": False, "error": str(e)}
  • Input schema definition for the 'gmail_delete_label' tool specifying parameters: label_name or label_id (string), confirm (boolean required).
    Tool(
        name="gmail_delete_label",
        description="Delete a Gmail label by name or ID. Cannot delete system labels. Requires confirmation.",
        inputSchema={
            "type": "object",
            "properties": {
                "label_name": {
                    "type": "string",
                    "description": "Name of the label to delete. Provide either label_name or label_id."
                },
                "label_id": {
                    "type": "string",
                    "description": "ID of the label to delete. Provide either label_name or label_id."
                },
                "confirm": {
                    "type": "boolean",
                    "description": "Must be true to actually delete. Set false to preview what would be deleted."
                }
            },
            "required": ["confirm"]
        },
    ),

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