Skip to main content

Email Management Workflow using Gmail MCP Server

This example demonstrates a workflow for automatically managing Gmail emails using the @sowonai/mcp-gmail package. You can see how an AI agent retrieves, reads, classifies, and summarizes emails via the Gmail API.

Source Code: The @sowonai/mcp-gmail package is open source. You can find the source code on GitHub.

Workflow Configuration​

version: "agentflow/v1"
kind: "WorkflowSpec"
metadata:
name: "Gmail Email Management Workflow"
description: "Automated Gmail email management using @sowonai/mcp-gmail"
version: "0.1.0"

agents:
- id: "gmail_assistant"
inline:
type: "agent"
model: "openai/gpt-4.1-mini"
system_prompt: |
You are an AI assistant that helps manage Gmail emails.
Please answer user questions using MCP tools. (MCP tools have the "mcp__" prefix)
Process work-related emails and personal emails separately, and ignore promotional emails.

Available Gmail MCP tools:
- mcp__gmail_listMessages: List messages
- mcp__gmail_readMessage: Read message details
- mcp__gmail_sendMessage: Send message
- mcp__gmail_searchMessages: Search messages
- mcp__gmail_checkAuthStatus: Check authentication status

<recommendation>
After checking the email list, when important emails are identified,
retrieve the details of multiple emails at once instead of opening them one by one.
</recommendation>

<information>
Our company is SowonLabs, established on March 11, 2025.
We are a deep tech company that creates AI-related products, and we are currently developing a product called SowonFlow.
This product is an AI-powered automated YAML workflow engine.
</information>
mcp: ["gmail"]

nodes:
start:
type: "agent_task"
agent: "gmail_assistant"
next: "end"

end:
type: "end"

MCP Server Setup​

To run this workflow, you need to set up the MCP server as follows:

const mcpServers = {
"gmail": {
"command": "npx",
"args": ["-y", "@sowonai/mcp-gmail"],
"env": {
"GOOGLE_CLIENT_ID": process.env.GOOGLE_CLIENT_ID,
"GOOGLE_CLIENT_SECRET": process.env.GOOGLE_CLIENT_SECRET,
"GOOGLE_REFRESH_TOKEN": process.env.GOOGLE_REFRESH_TOKEN
}
}
};

Environment Variable Setup​

You need to set the following environment variables to use the Gmail API:

# Google OAuth Configuration
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REFRESH_TOKEN=your_refresh_token

You can obtain the necessary values for these environment variables using the command below.

npx @sowonai/mcp-gmail --install --credentials ./credentials.json

Usage Examples​

1. Check Recent Work Emails​

"Find and summarize any work-related emails from my recent mail."

2. Search Emails from a Specific Sender​

"Find all emails from example@company.com."

3. Search Emails with Attachments​

"Find emails with attachments and tell me their subjects and senders."

4. Search Emails by Date Range​

"Summarize important emails from yesterday to today."

Gmail Search Syntax​

This workflow supports Gmail's powerful search syntax:

  • from:sender@example.com - Specific sender
  • to:recipient@example.com - Specific recipient
  • subject:keyword - Search by subject
  • has:attachment - Emails with attachments
  • after:2024/01/01 - After a specific date
  • before:2024/12/31 - Before a specific date
  • is:unread - Unread emails
  • larger:5M - Emails larger than 5MB

Example Execution Result​

When the workflow runs, you can get results like this:

📧 Work-related email summary:

1. **Project Meeting Schedule Change** (john@company.com)
- Tomorrow's 3 PM meeting postponed to 4 PM
- Zoom link attached

2. **SowonFlow Beta Test Results** (beta@partner.com)
- Performance test results report
- 3 improvement suggestions

3. **Contract Review Request** (legal@vendor.com)
- New partnership agreement attached
- Request to complete review this week

Through this workflow, you can efficiently manage your Gmail emails and avoid missing important information with the help of AI.