AI Agent Tool Server for Comprehensive Gmail Operations - n8n Workflow

Deploy a powerful n8n workflow acting as an AI Agent Tool Server for Gmail. Enable large language models to search, reply, label, manage drafts, and manipulate threads using this robust n8n node setup.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users utilizing AI Agents (LLMs) to perform complex, multi-step email management tasks.
n8n automation specialists building sophisticated conversational agents that require real-time Gmail access.
Developers needing a single, robust n8n API endpoint for 19 distinct Gmail functionalities.
Teams looking for advanced, AI-driven alternatives to standard n8n templates for inbox management.

Overview

This configuration is not a standard scheduled n8n workflow; it's designed specifically to function as a powerful tool server for an external AI Agent. It uses a specialized n8n trigger (mcpTrigger) to expose 19 critical Gmail operations as callable tools. This allows the AI Agent to perform advanced tasks—such as searching for specific emails, marking them as read, applying/removing labels, managing drafts, and replying to entire threads—all through a single, secure n8n endpoint.

By leveraging this n8n node setup, you create a seamless bridge between your Large Language Model and your email account, providing precise, context-aware execution capabilities that go far beyond what simple webhook n8n templates can achieve. This robust n8n workflow simplifies the LLM's interaction with complex email functionality.

How it Works

The entire process is initiated by the custom n8n trigger node, named Gmail MCP Server (mcpTrigger). This specialized n8n node listens on a dedicated path (/gmail). When an external AI Agent decides it needs to perform a Gmail operation (e.g., searching for a message or creating a draft), it calls this server endpoint, providing the required input parameters (like MessageID, SearchQuery, or Message content).

This core n8n trigger then routes the request to the appropriate downstream gmailTool n8n node—such as search, reply, or createDraft—based on the command sent by the AI Agent. Each of the subsequent gmailTool nodes uses expressions like {{ $fromAI('ParameterName') }} to dynamically extract the necessary variables supplied by the Agent. The chosen gmailTool executes the specific Gmail action using the pre-configured OAuth2 credentials and returns the outcome (e.g., the message content, a list of threads, or a confirmation of the action) back through the n8n workflow to the initiating AI Agent. This design ensures that the AI Agent can execute complex, multi-step Gmail tasks with accuracy using the full power of the n8n automation platform.

Installation Guide


  1. Import the n8n workflow: Copy the provided JSON data and paste it into your n8n instance using the "New" -> "Import from JSON" option.

  2. Configure Gmail Credentials: All gmailTool n8n node instances rely on a single, shared Gmail OAuth2 credential named 'Your Gmail Account'. You must set up or select an existing Gmail credential with appropriate read, write, and manage permissions.

  3. Activate the Server: Ensure the Gmail MCP Server n8n trigger node (the mcpTrigger) is active and obtain its specific Server-Sent Events (SSE) URL. This is the URL your AI Agent will use to send requests.

  4. Configure the AI Agent: In your primary AI Agent n8n workflow (not included here), configure the LLM to recognize and utilize this gmail tool and the specific functions it exposes. Ensure the agent is aware of the required input parameters for each function (e.g., Message_ID for 'get' or 'reply', or a Search string for 'search').

Node Details

This n8n workflow exposes 19 functions using the gmailTool n8n node, all managed by a single mcpTrigger.

Gmail MCP Server (@n8n/n8n-nodes-langchain.mcpTrigger):
Function: The central entry point (n8n trigger) that listens for calls from the AI Agent.
Key Configuration: Path is set to gmail.

Message Operations (n8n node: gmailTool):
search: Executes complex Gmail search queries (q, sender, receivedAfter, receivedBefore) and returns matching messages.
get: Retrieves the full content of a single email using the dynamically supplied MessageID.
reply: Sends a response to a message, accepting inputs for Message, CC, BCC, and optional attachments.
delete: Permanently deletes the message specified by Message
ID.
addLabels / removeLabels: Modifies the labels on a message using LabelNamesorIDs.
markAsRead / markAsUnread: Toggles the read status of a message, configured via the Message
ID input.

Label Management Operations (n8n node: gmailTool, Resource: Label):
getLabels: Retrieves a list of all available labels in the account.
createLabel: Creates a new custom label.
deleteLabel: Removes an existing label by ID.

Draft Operations (n8n node: gmailTool, Resource: Draft):
createDraft: Composes a new draft email, accepting inputs for Subject and Message.
getDraft / getManyDrafts: Retrieves single or multiple drafts, supporting filters like IncludeSpamandTrash.
deleteDraft: Deletes a specific draft using its Draft
ID.

Thread Operations (n8n node: gmailTool, Resource: Thread):
getManyThreads / getThread: Allows the AI Agent to search for or retrieve entire conversational threads.
replyThread: Sends a reply that automatically threads correctly using the Thread_ID.
addLabelThread / removeLabelThread: Applies or removes labels to the entire thread conversation, ensuring all related messages are categorized consistently. This complete n8n workflow provides powerful AI control.

Related n8n Workflows

Free

Nodes: 3 Nodes
Updated: December 26 2025
View all
Created by

Experienced Linux administrator, entrepreneur, and automation enthusiast, I specialize in crafting robust, scalable workflows with n8n. I have a passion for business automation, integrating complex systems seamlessly, and sharing practical templates that empower others to automate effectively.

Featured*