Gmail MCP Server is a Model Context Protocol implementation that provides a standardized interface for managing Gmail services including emails, threads, labels, drafts, and settings. It connects your applications to Gmail through a secure OAuth2 authentication process with Google Cloud credentials.
To install the Gmail MCP server, you'll need:
~/.gmail-mcp/gcp-oauth.keys.json
.gmail-mcp
directory~/.gmail-mcp/gcp-oauth.keys.json
file to their computer at the same pathnpx @shinzolabs/gmail-mcp auth
~/.gmail-mcp/credentials.json
To install using Smithery's CLI:
npx -y @smithery/cli install @shinzo-labs/gmail-mcp
You'll be prompted to enter your CLIENT_ID
, CLIENT_SECRET
, and REFRESH_TOKEN
.
Add the following configuration to your MCP client's config.json
:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": [
"@shinzolabs/gmail-mcp"
]
}
}
}
Clone the repository:
git clone https://github.com/shinzo-labs/gmail-mcp.git
Install packages and build:
pnpm i && pnpm build
Configure your MCP client's config.json
:
{
"mcpServers": {
"gmail": {
"command": "node",
"args": [
"/path/to/gmail-mcp/dist/index.js"
]
}
}
}
The following environment variables can be used to configure the server:
Variable | Description | Required? | Default |
---|---|---|---|
AUTH_SERVER_PORT |
Port for OAuth authentication server | No | 3000 |
CLIENT_ID |
Google API client ID | For remote server | '' |
CLIENT_SECRET |
Google API client secret | For remote server | '' |
GMAIL_CREDENTIALS_PATH |
Path to user credentials file | No | MCP_CONFIG_DIR/credentials.json |
GMAIL_OAUTH_PATH |
Path to Google API Client file | No | MCP_CONFIG_DIR/gcp-oauth.keys.json |
MCP_CONFIG_DIR |
Directory for configuration files | No | ~/.gmail-mcp |
REFRESH_TOKEN |
OAuth refresh token | For remote server | '' |
PORT |
Port for HTTP transport | No | 3000 |
TELEMETRY_ENABLED |
Enable telemetry | No | true |
The Gmail MCP server provides endpoints for various Gmail operations:
To list messages with optional filtering:
const result = await mcp.invoke("gmail", "list_messages", {
maxResults: 10,
q: "is:unread"
});
To get a specific message:
const result = await mcp.invoke("gmail", "get_message", {
id: "message-id-here",
format: "full"
});
To send an email:
const result = await mcp.invoke("gmail", "send_message", {
message: {
to: ["[email protected]"],
subject: "Hello",
body: "This is a test email"
}
});
To list all labels:
const result = await mcp.invoke("gmail", "list_labels", {});
To create a new label:
const result = await mcp.invoke("gmail", "create_label", {
name: "My New Label",
labelListVisibility: "labelShow",
messageListVisibility: "show"
});
To list email threads:
const result = await mcp.invoke("gmail", "list_threads", {
maxResults: 10,
q: "label:inbox"
});
To create a draft email:
const result = await mcp.invoke("gmail", "create_draft", {
message: {
to: ["[email protected]"],
subject: "Draft Email",
body: "This is a draft email"
}
});
To get vacation responder settings:
const result = await mcp.invoke("gmail", "get_vacation", {});
To update vacation responder:
const result = await mcp.invoke("gmail", "update_vacation", {
enableAutoReply: true,
responseSubject: "Out of Office",
responseBodyHtml: "<p>I am currently out of office until January 1st.</p>",
startTime: "2023-12-24T00:00:00Z",
endTime: "2024-01-01T23:59:59Z"
});
To get a message attachment:
const result = await mcp.invoke("gmail", "get_attachment", {
messageId: "message-id-here",
id: "attachment-id-here"
});
To modify multiple messages at once:
const result = await mcp.invoke("gmail", "batch_modify_messages", {
ids: ["msg1", "msg2", "msg3"],
addLabelIds: ["Label_123"],
removeLabelIds: ["UNREAD"]
});
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "gmail" '{"command":"npx","args":["@shinzolabs/gmail-mcp"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": [
"@shinzolabs/gmail-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": [
"@shinzolabs/gmail-mcp"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect