@d-mato/gmail-mcp 0.1.6 → 0.1.8
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 +3 -0
- package/build/gmail-client.js +26 -0
- package/build/tools/messages.js +19 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# gmail-mcp
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@d-mato/gmail-mcp)
|
|
4
|
+
|
|
3
5
|
MCP server for Gmail — search, read, archive, and manage your email from any MCP client.
|
|
4
6
|
|
|
5
7
|
## Setup
|
|
@@ -27,6 +29,7 @@ On first launch, a browser window will open for Google account authorization. Af
|
|
|
27
29
|
|------|-------------|
|
|
28
30
|
| `gmail_search` | Search messages using Gmail query syntax (e.g. `from:user@example.com`, `is:unread`) |
|
|
29
31
|
| `gmail_get_message` | Get the full content of a message by ID |
|
|
32
|
+
| `gmail_get_thread` | Get all messages in a thread by thread ID |
|
|
30
33
|
| `gmail_archive` | Archive a message (remove from inbox) |
|
|
31
34
|
| `gmail_batch_archive` | Archive multiple messages |
|
|
32
35
|
| `gmail_trash` | Move a message to trash |
|
package/build/gmail-client.js
CHANGED
|
@@ -59,6 +59,32 @@ export class GmailClient {
|
|
|
59
59
|
body,
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
async getThread(threadId) {
|
|
63
|
+
const res = await this.gmail.users.threads.get({
|
|
64
|
+
userId: "me",
|
|
65
|
+
id: threadId,
|
|
66
|
+
format: "full",
|
|
67
|
+
});
|
|
68
|
+
const data = res.data;
|
|
69
|
+
if (!data.id) {
|
|
70
|
+
throw new Error(`Invalid thread data for id: ${threadId}`);
|
|
71
|
+
}
|
|
72
|
+
const messages = (data.messages ?? []).map((msg) => {
|
|
73
|
+
if (!msg.id || !msg.threadId) {
|
|
74
|
+
throw new Error(`Invalid message data in thread: ${threadId}`);
|
|
75
|
+
}
|
|
76
|
+
const body = msg.payload ? extractTextBody(msg.payload) : "";
|
|
77
|
+
return {
|
|
78
|
+
id: msg.id,
|
|
79
|
+
threadId: msg.threadId,
|
|
80
|
+
snippet: msg.snippet ?? "",
|
|
81
|
+
headers: extractHeaders(msg.payload?.headers),
|
|
82
|
+
labelIds: msg.labelIds ?? [],
|
|
83
|
+
body,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
return { id: data.id, messages };
|
|
87
|
+
}
|
|
62
88
|
async modifyMessage(messageId, addLabelIds = [], removeLabelIds = []) {
|
|
63
89
|
await this.gmail.users.messages.modify({
|
|
64
90
|
userId: "me",
|
package/build/tools/messages.js
CHANGED
|
@@ -25,6 +25,12 @@ function formatMessageDetail(msg) {
|
|
|
25
25
|
msg.body,
|
|
26
26
|
].join("\n");
|
|
27
27
|
}
|
|
28
|
+
function formatThreadDetail(thread) {
|
|
29
|
+
const count = thread.messages.length;
|
|
30
|
+
const header = `Thread: ${thread.id} (${count} ${count === 1 ? "message" : "messages"})`;
|
|
31
|
+
const body = thread.messages.map(formatMessageDetail).join("\n\n---\n\n");
|
|
32
|
+
return `${header}\n\n${body}`;
|
|
33
|
+
}
|
|
28
34
|
export function registerMessageTools(server, gmail) {
|
|
29
35
|
server.tool("gmail_search", "Search Gmail messages using Gmail query syntax (e.g. 'from:user@example.com', 'is:unread', 'subject:hello')", {
|
|
30
36
|
query: z.string().describe("Gmail search query"),
|
|
@@ -58,6 +64,19 @@ export function registerMessageTools(server, gmail) {
|
|
|
58
64
|
return wrapGmailError(err, "Message");
|
|
59
65
|
}
|
|
60
66
|
});
|
|
67
|
+
server.tool("gmail_get_thread", "Get all messages in a Gmail thread by thread ID", {
|
|
68
|
+
threadId: z.string().describe("Gmail thread ID"),
|
|
69
|
+
}, async ({ threadId }) => {
|
|
70
|
+
try {
|
|
71
|
+
const thread = await gmail.getThread(threadId);
|
|
72
|
+
return {
|
|
73
|
+
content: [{ type: "text", text: formatThreadDetail(thread) }],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
return wrapGmailError(err, "Thread");
|
|
78
|
+
}
|
|
79
|
+
});
|
|
61
80
|
server.tool("gmail_archive", "Archive a message (remove from inbox)", {
|
|
62
81
|
messageId: z.string().describe("Gmail message ID"),
|
|
63
82
|
}, async ({ messageId }) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-mato/gmail-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "MCP server for Gmail - search, read, archive, and manage your email",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"zod": "4.3.6"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@biomejs/biome": "2.4.
|
|
34
|
-
"@types/node": "25.
|
|
35
|
-
"typescript": "6.0.
|
|
36
|
-
"vitest": "4.1.
|
|
33
|
+
"@biomejs/biome": "2.4.13",
|
|
34
|
+
"@types/node": "25.6.0",
|
|
35
|
+
"typescript": "6.0.3",
|
|
36
|
+
"vitest": "4.1.5"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc",
|