Skip to main content
Glama
ZatesloFL

Google Workspace MCP Server

by ZatesloFL

batch_modify_gmail_message_labels

Add or remove Gmail labels for multiple messages in a single batch operation. Simplify organizing and categorizing emails efficiently using user-specified label IDs and message IDs.

Instructions

Adds or removes labels from multiple Gmail messages in a single batch request.

Args: user_google_email (str): The user's Google email address. Required. message_ids (List[str]): A list of message IDs to modify. add_label_ids (Optional[List[str]]): List of label IDs to add to the messages. remove_label_ids (Optional[List[str]]): List of label IDs to remove from the messages.

Returns: str: Confirmation message of the label changes applied to the messages.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
add_label_idsNoLabel IDs to add to messages.
message_idsYes
remove_label_idsNoLabel IDs to remove from messages.
user_google_emailYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'batch_modify_gmail_message_labels' tool. It is registered via @server.tool(), handles authentication and errors via decorators, and implements the batch label modification logic using the Gmail API's users.messages.batchModify method. Includes input validation via Pydantic Field and a descriptive docstring serving as schema documentation.
    @server.tool()
    @handle_http_errors("batch_modify_gmail_message_labels", service_type="gmail")
    @require_google_service("gmail", GMAIL_MODIFY_SCOPE)
    async def batch_modify_gmail_message_labels(
        service,
        user_google_email: str,
        message_ids: List[str],
        add_label_ids: List[str] = Field(default=[], description="Label IDs to add to messages."),
        remove_label_ids: List[str] = Field(default=[], description="Label IDs to remove from messages."),
    ) -> str:
        """
        Adds or removes labels from multiple Gmail messages in a single batch request.
    
        Args:
            user_google_email (str): The user's Google email address. Required.
            message_ids (List[str]): A list of message IDs to modify.
            add_label_ids (Optional[List[str]]): List of label IDs to add to the messages.
            remove_label_ids (Optional[List[str]]): List of label IDs to remove from the messages.
    
        Returns:
            str: Confirmation message of the label changes applied to the messages.
        """
        logger.info(
            f"[batch_modify_gmail_message_labels] Invoked. Email: '{user_google_email}', Message IDs: '{message_ids}'"
        )
    
        if not add_label_ids and not remove_label_ids:
            raise Exception(
                "At least one of add_label_ids or remove_label_ids must be provided."
            )
    
        body = {"ids": message_ids}
        if add_label_ids:
            body["addLabelIds"] = add_label_ids
        if remove_label_ids:
            body["removeLabelIds"] = remove_label_ids
    
        await asyncio.to_thread(
            service.users().messages().batchModify(userId="me", body=body).execute
        )
    
        actions = []
        if add_label_ids:
            actions.append(f"Added labels: {', '.join(add_label_ids)}")
        if remove_label_ids:
            actions.append(f"Removed labels: {', '.join(remove_label_ids)}")
    
        return f"Labels updated for {len(message_ids)} messages: {'; '.join(actions)}"
  • The @server.tool() decorator registers this function as an MCP tool named 'batch_modify_gmail_message_labels' (derived from function name).
    @server.tool()
  • Function signature with Pydantic Field annotations for input validation and comprehensive docstring defining the tool's schema (parameters, descriptions, types, and return value).
    async def batch_modify_gmail_message_labels(
        service,
        user_google_email: str,
        message_ids: List[str],
        add_label_ids: List[str] = Field(default=[], description="Label IDs to add to messages."),
        remove_label_ids: List[str] = Field(default=[], description="Label IDs to remove from messages."),
    ) -> str:
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool performs label modifications but doesn't mention authentication requirements, rate limits, error handling, or whether changes are reversible. For a mutation tool with zero annotation coverage, this leaves significant behavioral gaps.

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 and front-loaded with the core purpose, followed by parameter and return details. It's appropriately sized with no redundant sentences, though the parameter explanations could be slightly more concise by integrating them into the main description.

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 (batch mutation with 4 parameters), no annotations, and an output schema that only indicates a string return, the description is moderately complete. It covers the basic operation and parameters but lacks details on permissions, error cases, and practical usage context, which are important for a mutation tool.

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 50% (two of four parameters have descriptions). The description adds value by clarifying that 'add_label_ids' and 'remove_label_ids' are optional and operate on lists, but doesn't explain parameter interactions (e.g., what happens if the same label is in both lists) or provide examples. It partially compensates for the schema gap but not fully.

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 ('Adds or removes labels from multiple Gmail messages') and resource ('Gmail messages'), distinguishing it from sibling tools like 'modify_gmail_message_labels' by emphasizing batch processing. The verb+resource combination is precise and unambiguous.

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 is provided on when to use this tool versus alternatives like 'modify_gmail_message_labels' (which appears to handle single messages). The description mentions batch processing but doesn't explicitly advise on scenarios where batch is preferred over individual modifications or vice versa.

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/ZatesloFL/google_workspace_mcp'

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