gmail-mcp-imap 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/build/gmail-client.d.ts +78 -0
- package/build/gmail-client.d.ts.map +1 -0
- package/build/gmail-client.js +596 -0
- package/build/gmail-client.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +392 -0
- package/build/index.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Suhail
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# gmail-mcp-imap
|
|
2
|
+
|
|
3
|
+
A Gmail MCP (Model Context Protocol) server that provides email management capabilities through IMAP/SMTP. Works with Claude Desktop, Claude Code, and any MCP-compatible client.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Gmail Categories**: Fetch emails by Gmail's smart categories (Primary, Social, Promotions, Updates, Forums)
|
|
8
|
+
- **Full Email Management**: Read, send, reply, star, delete, and label emails
|
|
9
|
+
- **Attachment Handling**: List, download, and save attachments to disk
|
|
10
|
+
- **No Google API Required**: Uses IMAP/SMTP directly with App Password authentication
|
|
11
|
+
- **Date Filtering**: Filter emails by date range
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install gmail-mcp-imap
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or run directly with npx:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx gmail-mcp-imap
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
1. A Gmail account
|
|
28
|
+
2. **App Password** (not your regular password):
|
|
29
|
+
- Go to [Google Account Security](https://myaccount.google.com/security)
|
|
30
|
+
- Enable 2-Step Verification if not already enabled
|
|
31
|
+
- Go to App Passwords (search for "App Passwords" in account settings)
|
|
32
|
+
- Generate a new app password for "Mail"
|
|
33
|
+
- Copy the 16-character password
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
### Environment Variables
|
|
38
|
+
|
|
39
|
+
Set these environment variables before running:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
export GMAIL_EMAIL="your-email@gmail.com"
|
|
43
|
+
export GMAIL_APP_PASSWORD="your-16-char-app-password"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Claude Desktop Configuration
|
|
47
|
+
|
|
48
|
+
Add to your `claude_desktop_config.json`:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"mcpServers": {
|
|
53
|
+
"gmail": {
|
|
54
|
+
"command": "npx",
|
|
55
|
+
"args": ["gmail-mcp-imap"],
|
|
56
|
+
"env": {
|
|
57
|
+
"GMAIL_EMAIL": "your-email@gmail.com",
|
|
58
|
+
"GMAIL_APP_PASSWORD": "your-app-password"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Claude Code Configuration
|
|
66
|
+
|
|
67
|
+
Add to your `.mcp.json`:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"mcpServers": {
|
|
72
|
+
"gmail": {
|
|
73
|
+
"command": "npx",
|
|
74
|
+
"args": ["gmail-mcp-imap"],
|
|
75
|
+
"env": {
|
|
76
|
+
"GMAIL_EMAIL": "your-email@gmail.com",
|
|
77
|
+
"GMAIL_APP_PASSWORD": "your-app-password"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Available Tools
|
|
85
|
+
|
|
86
|
+
### Category Tools
|
|
87
|
+
| Tool | Description |
|
|
88
|
+
|------|-------------|
|
|
89
|
+
| `get_primary_emails` | Important conversations from real people |
|
|
90
|
+
| `get_social_emails` | Social network notifications |
|
|
91
|
+
| `get_promotions_emails` | Marketing emails, deals, offers |
|
|
92
|
+
| `get_updates_emails` | Receipts, bills, statements |
|
|
93
|
+
| `get_forums_emails` | Mailing lists, discussion groups |
|
|
94
|
+
|
|
95
|
+
### Search & Read Tools
|
|
96
|
+
| Tool | Description |
|
|
97
|
+
|------|-------------|
|
|
98
|
+
| `search_emails` | Search emails by keywords |
|
|
99
|
+
| `get_email_content` | Get full email content by UID |
|
|
100
|
+
| `get_emails_by_label` | Get emails from a specific label |
|
|
101
|
+
| `list_labels` | List all Gmail labels/folders |
|
|
102
|
+
|
|
103
|
+
### Action Tools
|
|
104
|
+
| Tool | Description |
|
|
105
|
+
|------|-------------|
|
|
106
|
+
| `send_email` | Send a new email |
|
|
107
|
+
| `reply_to_email` | Reply to an existing email |
|
|
108
|
+
| `mark_as_read` | Mark email as read |
|
|
109
|
+
| `mark_as_unread` | Mark email as unread |
|
|
110
|
+
| `star_email` | Star or unstar an email |
|
|
111
|
+
| `delete_email` | Move email to trash |
|
|
112
|
+
| `apply_label` | Apply a label to an email |
|
|
113
|
+
|
|
114
|
+
### Attachment Tools
|
|
115
|
+
| Tool | Description |
|
|
116
|
+
|------|-------------|
|
|
117
|
+
| `list_attachments` | List attachments in an email |
|
|
118
|
+
| `download_attachment` | Download attachment as Base64 |
|
|
119
|
+
| `save_attachment` | Save attachment to disk |
|
|
120
|
+
|
|
121
|
+
## Usage Examples
|
|
122
|
+
|
|
123
|
+
Once configured, you can ask Claude:
|
|
124
|
+
|
|
125
|
+
- "Show me my primary emails from the last week"
|
|
126
|
+
- "Search for emails from Amazon"
|
|
127
|
+
- "Read the email with UID 12345"
|
|
128
|
+
- "Send an email to john@example.com about the meeting"
|
|
129
|
+
- "Download the PDF attachment from email 12345"
|
|
130
|
+
- "Star the important emails about invoices"
|
|
131
|
+
|
|
132
|
+
## Why IMAP/SMTP?
|
|
133
|
+
|
|
134
|
+
This MCP server uses IMAP/SMTP instead of the Google API because:
|
|
135
|
+
|
|
136
|
+
1. **Simpler Setup**: No OAuth consent screen or API credentials needed
|
|
137
|
+
2. **App Passwords**: More secure than storing your main password
|
|
138
|
+
3. **No Rate Limits**: Google API has strict quotas; IMAP doesn't
|
|
139
|
+
4. **Works Offline**: No dependency on Google's API servers
|
|
140
|
+
5. **Privacy**: Your emails aren't processed through additional Google services
|
|
141
|
+
|
|
142
|
+
## Development
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# Clone the repository
|
|
146
|
+
git clone https://github.com/suhailak/gmail-mcp.git
|
|
147
|
+
cd gmail-mcp
|
|
148
|
+
|
|
149
|
+
# Install dependencies
|
|
150
|
+
npm install
|
|
151
|
+
|
|
152
|
+
# Run in development mode
|
|
153
|
+
npm run dev
|
|
154
|
+
|
|
155
|
+
# Build for production
|
|
156
|
+
npm run build
|
|
157
|
+
|
|
158
|
+
# Run production build
|
|
159
|
+
npm start
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT
|
|
165
|
+
|
|
166
|
+
## Author
|
|
167
|
+
|
|
168
|
+
Suhail ([@ansuhail.ak@gmail.com](mailto:ansuhail.ak@gmail.com))
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
declare const GMAIL_CATEGORIES: readonly ["primary", "social", "promotions", "updates", "forums"];
|
|
2
|
+
type GmailCategory = (typeof GMAIL_CATEGORIES)[number];
|
|
3
|
+
export interface EmailMessage {
|
|
4
|
+
id: string;
|
|
5
|
+
uid: number;
|
|
6
|
+
subject: string;
|
|
7
|
+
from: string;
|
|
8
|
+
to: string;
|
|
9
|
+
date: string;
|
|
10
|
+
snippet: string;
|
|
11
|
+
labels: string[];
|
|
12
|
+
isRead: boolean;
|
|
13
|
+
isStarred: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface EmailContent extends EmailMessage {
|
|
16
|
+
body: string;
|
|
17
|
+
attachments: Array<{
|
|
18
|
+
filename: string;
|
|
19
|
+
contentType: string;
|
|
20
|
+
size: number;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
export interface AttachmentData {
|
|
24
|
+
filename: string;
|
|
25
|
+
contentType: string;
|
|
26
|
+
size: number;
|
|
27
|
+
content: string;
|
|
28
|
+
}
|
|
29
|
+
export interface GmailConfig {
|
|
30
|
+
email: string;
|
|
31
|
+
appPassword: string;
|
|
32
|
+
}
|
|
33
|
+
export declare class GmailClient {
|
|
34
|
+
private config;
|
|
35
|
+
private smtpTransport;
|
|
36
|
+
constructor(config: GmailConfig);
|
|
37
|
+
private createImapConnection;
|
|
38
|
+
private getSmtpTransport;
|
|
39
|
+
private runImapOperation;
|
|
40
|
+
getEmailsByCategory(category: GmailCategory, limit?: number, dateFilter?: {
|
|
41
|
+
after?: string;
|
|
42
|
+
before?: string;
|
|
43
|
+
}): Promise<EmailMessage[]>;
|
|
44
|
+
getEmailsByLabel(label: string, limit?: number): Promise<EmailMessage[]>;
|
|
45
|
+
searchEmails(query: string, limit?: number): Promise<EmailMessage[]>;
|
|
46
|
+
getEmailContent(uid: number): Promise<EmailContent | null>;
|
|
47
|
+
listLabels(): Promise<string[]>;
|
|
48
|
+
sendEmail(to: string, subject: string, body: string, options?: {
|
|
49
|
+
cc?: string;
|
|
50
|
+
bcc?: string;
|
|
51
|
+
html?: boolean;
|
|
52
|
+
replyTo?: string;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
success: boolean;
|
|
55
|
+
messageId?: string;
|
|
56
|
+
error?: string;
|
|
57
|
+
}>;
|
|
58
|
+
replyEmail(uid: number, body: string, options?: {
|
|
59
|
+
html?: boolean;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
success: boolean;
|
|
62
|
+
messageId?: string;
|
|
63
|
+
error?: string;
|
|
64
|
+
}>;
|
|
65
|
+
markAsRead(uid: number, read?: boolean): Promise<boolean>;
|
|
66
|
+
starEmail(uid: number, starred?: boolean): Promise<boolean>;
|
|
67
|
+
deleteEmail(uid: number): Promise<boolean>;
|
|
68
|
+
applyLabel(uid: number, label: string): Promise<boolean>;
|
|
69
|
+
downloadAttachment(uid: number, filename: string): Promise<AttachmentData | null>;
|
|
70
|
+
listAttachments(uid: number): Promise<Array<{
|
|
71
|
+
filename: string;
|
|
72
|
+
contentType: string;
|
|
73
|
+
size: number;
|
|
74
|
+
}>>;
|
|
75
|
+
disconnect(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=gmail-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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