gmail-app-password-mcp 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/README.md +129 -0
- package/index.js +102 -0
- package/package.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# 📧 Gmail MCP Server
|
|
2
|
+
|
|
3
|
+
Connect Claude directly to your Gmail — send emails, list messages, and read emails!
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🚀 Quick Setup (5 Steps)
|
|
8
|
+
|
|
9
|
+
### Step 1 — Get Google OAuth Credentials
|
|
10
|
+
|
|
11
|
+
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
|
|
12
|
+
2. Create a **new project** (or select an existing one)
|
|
13
|
+
3. Go to **APIs & Services → Library** → Search **"Gmail API"** → Click **Enable**
|
|
14
|
+
4. Go to **APIs & Services → Credentials**
|
|
15
|
+
5. Click **Create Credentials → OAuth 2.0 Client IDs**
|
|
16
|
+
6. Choose **Desktop app** → Give it a name → Click **Create**
|
|
17
|
+
7. Click **Download JSON** and save it as **`credentials.json`** in this folder
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
### Step 2 — Install Dependencies
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
cd gmail-mcp
|
|
25
|
+
npm install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### Step 3 — Authorize the App (one-time only)
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
node auth.js
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- It will print a Google URL — open it in your browser
|
|
37
|
+
- Sign in with your Gmail account
|
|
38
|
+
- Copy the authorization code shown
|
|
39
|
+
- Paste it back in the terminal
|
|
40
|
+
- A `token.json` file will be saved — **keep this secret!**
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### Step 4 — Add to Claude Desktop
|
|
45
|
+
|
|
46
|
+
Open your Claude Desktop config file:
|
|
47
|
+
|
|
48
|
+
| OS | Path |
|
|
49
|
+
|---------|-------------------------------------------------------------|
|
|
50
|
+
| macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
51
|
+
| Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
|
|
52
|
+
| Linux | `~/.config/Claude/claude_desktop_config.json` |
|
|
53
|
+
|
|
54
|
+
Add this to the `mcpServers` section:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"gmail": {
|
|
60
|
+
"command": "node",
|
|
61
|
+
"args": ["/ABSOLUTE/PATH/TO/gmail-mcp/index.js"]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
> ⚠️ Replace `/ABSOLUTE/PATH/TO/gmail-mcp/` with the actual full path to this folder.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
### Step 5 — Restart Claude Desktop
|
|
72
|
+
|
|
73
|
+
Quit and reopen Claude Desktop. You should see Gmail tools available! 🎉
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 🛠️ Available Tools
|
|
78
|
+
|
|
79
|
+
| Tool | Description |
|
|
80
|
+
|------|-------------|
|
|
81
|
+
| `send_email` | Send an email to anyone |
|
|
82
|
+
| `list_messages` | List recent emails (with optional search) |
|
|
83
|
+
| `read_email` | Read the full content of an email |
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 💬 Example Prompts
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
Send an email to friend@gmail.com saying happy birthday!
|
|
91
|
+
|
|
92
|
+
List my last 5 emails from boss@company.com
|
|
93
|
+
|
|
94
|
+
Read the email with ID 18f2a3b4c5d6e7f8
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 🔒 Security Notes
|
|
100
|
+
|
|
101
|
+
- `credentials.json` and `token.json` give access to your Gmail — **never share them**
|
|
102
|
+
- Add both files to `.gitignore` if using Git
|
|
103
|
+
- The token auto-refreshes, so you only need to run `auth.js` once
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 🐛 Troubleshooting
|
|
108
|
+
|
|
109
|
+
**"credentials.json not found"** → Make sure you downloaded and placed the file correctly (Step 1)
|
|
110
|
+
|
|
111
|
+
**"No token found"** → Run `node auth.js` again (Step 3)
|
|
112
|
+
|
|
113
|
+
**"Access blocked"** → In Google Cloud Console, go to OAuth consent screen → Add your Gmail as a test user
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 📁 File Structure
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
gmail-mcp/
|
|
121
|
+
├── index.js ← MCP server (main file)
|
|
122
|
+
├── auth.js ← One-time authorization script
|
|
123
|
+
├── package.json ← Dependencies
|
|
124
|
+
├── credentials.json ← Your Google OAuth credentials (you add this)
|
|
125
|
+
├── token.json ← Auto-generated after running auth.js
|
|
126
|
+
└── README.md ← This file
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gmail MCP Server (App Password version - no OAuth needed!)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { Server } = require("@modelcontextprotocol/sdk/server/index.js");
|
|
8
|
+
const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
9
|
+
const {
|
|
10
|
+
CallToolRequestSchema,
|
|
11
|
+
ListToolsRequestSchema,
|
|
12
|
+
} = require("@modelcontextprotocol/sdk/types.js");
|
|
13
|
+
const nodemailer = require("nodemailer");
|
|
14
|
+
|
|
15
|
+
// ── Your Gmail credentials (edit these two lines!) ──────────────────────────
|
|
16
|
+
const GMAIL_USER = "paraschauhan05112001@gmail.com"; // your Gmail
|
|
17
|
+
const GMAIL_APP_PASSWORD = "zfuy wpew zrde nmij"; // paste app password here (no spaces)
|
|
18
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
const transporter = nodemailer.createTransport({
|
|
21
|
+
service: "gmail",
|
|
22
|
+
auth: {
|
|
23
|
+
user: GMAIL_USER,
|
|
24
|
+
pass: GMAIL_APP_PASSWORD,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const server = new Server(
|
|
29
|
+
{ name: "gmail-mcp", version: "2.0.0" },
|
|
30
|
+
{ capabilities: { tools: {} } }
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
34
|
+
tools: [
|
|
35
|
+
{
|
|
36
|
+
name: "send_email",
|
|
37
|
+
description: "Send an email via Gmail to anyone",
|
|
38
|
+
inputSchema: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
to: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "Recipient email address",
|
|
44
|
+
},
|
|
45
|
+
subject: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "Subject of the email",
|
|
48
|
+
},
|
|
49
|
+
body: {
|
|
50
|
+
type: "string",
|
|
51
|
+
description: "Body of the email",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
required: ["to", "subject", "body"],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
61
|
+
const { name, arguments: args } = request.params;
|
|
62
|
+
|
|
63
|
+
if (name === "send_email") {
|
|
64
|
+
const { to, subject, body } = args;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const info = await transporter.sendMail({
|
|
68
|
+
from: `"Gmail MCP" <${GMAIL_USER}>`,
|
|
69
|
+
to,
|
|
70
|
+
subject,
|
|
71
|
+
text: body,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: "text",
|
|
78
|
+
text: `✅ Email sent successfully!\nTo: ${to}\nSubject: ${subject}\nMessage ID: ${info.messageId}`,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
} catch (err) {
|
|
83
|
+
return {
|
|
84
|
+
content: [{ type: "text", text: `❌ Failed to send email: ${err.message}` }],
|
|
85
|
+
isError: true,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
async function main() {
|
|
94
|
+
const transport = new StdioServerTransport();
|
|
95
|
+
await server.connect(transport);
|
|
96
|
+
console.error("Gmail MCP server running (App Password mode)...");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
main().catch((err) => {
|
|
100
|
+
console.error("Fatal error:", err);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gmail-app-password-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Gmail MCP server using App Password - easiest Gmail setup for Claude",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"gmail-app-password-mcp": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js"
|
|
11
|
+
],
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
14
|
+
"nodemailer": "^6.9.0"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
}
|
|
19
|
+
}
|