Gmail Label & Filter Organizer
Analyzes your Gmail inbox, creates label taxonomy, and sets up filters to auto-sort incoming mail using Gmail API via Google CLI. Prerequisites: gcloud, curl, jq.
MCP get_skill({ skillId: "gmail-label-filter-organizer-3ec573b0" })Use this skill with your agent
Create a free account and connect via MCP
# Gmail Label & Filter Organizer
Analyze your inbox to identify patterns, create a label hierarchy, and set up Gmail filters to auto-organize incoming mail.
## When to Use
- "Organize my Gmail inbox"
- "Set up filters for my newsletters and notifications"
- "Create labels to sort my email by project"
- Inbox has 500+ unread and needs a system
## Requirements
- **Google Cloud CLI** (`gcloud`) authenticated with Gmail API
- OAuth2 scopes: `gmail.labels`, `gmail.settings.basic`, `gmail.readonly`
- `jq` for JSON parsing
## Workflow
### Step 1 — Authenticate
```bash
ACCESS_TOKEN=$(gcloud auth print-access-token)
```
### Step 2 — Analyze Current Inbox Patterns
Fetch recent messages and analyze senders/subjects:
```bash
# Get last 100 inbox messages
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages?q=in:inbox&maxResults=100" | \
jq -r '.messages[].id' > /tmp/gmail_msg_ids.txt
# Extract sender domains and subjects for pattern analysis
while read MSG_ID; do
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages/$MSG_ID?format=metadata&metadataHeaders=From&metadataHeaders=Subject" | \
jq '{from: (.payload.headers[] | select(.name=="From") | .value), subject: (.payload.headers[] | select(.name=="Subject") | .value)}'
done < /tmp/gmail_msg_ids.txt > /tmp/gmail_analysis.json
```
### Step 3 — Identify Categories
Group emails by:
- **Sender domain** — newsletters, notifications, work domains, personal
- **Subject patterns** — invoices, receipts, automated alerts, meeting invites
- **Frequency** — daily digests, weekly reports
Present proposed label taxonomy to user:
```
📁 Work/
📁 Work/ProjectAlpha
📁 Work/ProjectBeta
📁 Newsletters/
📁 Finance/
📁 Finance/Receipts
📁 Finance/Invoices
📁 Notifications/
📁 Notifications/GitHub
📁 Notifications/Social
```
### Step 4 — Create Labels
After user approves the taxonomy:
```bash
# Create a label
curl -s -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "Work/ProjectAlpha", "labelListVisibility": "labelShow", "messageListVisibility": "show"}' \
"https://gmail.googleapis.com/gmail/v1/users/me/labels"
```
Repeat for each label in the hierarchy.
### Step 5 — Create Filters
For each category pattern:
```bash
# Create a filter (e.g., newsletters go to Newsletters label, skip inbox)
curl -s -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"criteria": {"from": "newsletter@example.com"},
"action": {"addLabelIds": ["{LABEL_ID}"], "removeLabelIds": ["INBOX"]}
}' \
"https://gmail.googleapis.com/gmail/v1/users/me/settings/filters"
```
### Step 6 — Apply Labels to Existing Messages
Batch-modify existing messages matching the filter criteria:
```bash
# Find matching messages
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
"https://gmail.googleapis.com/gmail/v1/users/me/messages?q=from:newsletter@example.com" | jq -r '.messages[].id'
# Batch modify
curl -s -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"ids": ["msg1", "msg2"], "addLabelIds": ["{LABEL_ID}"], "removeLabelIds": ["INBOX"]}' \
"https://gmail.googleapis.com/gmail/v1/users/me/messages/batchModify"
```
### Step 7 — Report
Provide summary: labels created, filters set, messages organized. Store the configuration in `outputs/gmail-organization-plan.md`.
## Important Rules
- Always show proposed labels and filters before creating them
- Never delete messages or existing labels without explicit confirmation
- Preserve existing label structure — add, don't replace
## Example Prompts
- "Organize my Gmail inbox by project"
- "Set up filters so newsletters skip inbox"
- "Create a label system for my freelance clients"Related Skills
More skills in Email & Communication
Gmail Cold Outreach Campaign
Research prospects via Brave Search, compose personalized cold outreach emails, and create ready-to-send Gmail drafts with A/B subject line variants. Prerequisites: gcloud, curl, jq, base64, brave-search MCP.
Gmail Email Drafter
Draft and send emails via Gmail using Google CLI. Analyzes your sent mail for tone matching, composes context-aware drafts, and creates Gmail drafts ready to send. Prerequisites: gcloud, curl, jq, base64.
Gmail Follow-Up Tracker
Scans your Gmail sent folder for unanswered emails, identifies stale threads, and creates follow-up drafts with context-aware nudges via Google CLI. Prerequisites: gcloud, curl, jq.
Gmail Inbox Daily Summary
Fetches today's unread Gmail messages via Google CLI, categorizes them by priority, and generates an actionable daily email briefing. Prerequisites: gcloud, curl, jq.
Gmail Response Template Manager
Creates, stores, and applies reusable email response templates. Analyzes your common replies to build a template library, then auto-fills templates for quick Gmail draft creation. Prerequisites: gcloud, curl, jq, base64.
Meeting Notes to Gmail Summary
Converts meeting notes or transcripts into structured summary emails and creates Gmail drafts addressed to all attendees. Prerequisites: gcloud, curl, jq, base64.
Explore Other Categories
Skills from other categories with shared topics
Add Multiple Attendees to a Calendar Event
Add a list of attendees to an existing Google Calendar event and send notifications.
Airtable
Airtable REST API via curl. Records CRUD, filters, upserts.
Announce via Gmail and Google Chat
Send a team announcement via both Gmail and a Google Chat space.