Skip to main content
Glama

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

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:

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