A Model Context Protocol (MCP) server for Gmail integration, built with FastMCP. This server provides AI assistants with the ability to interact with Gmail through a set of standardized tools.
This project implements an MCP server that allows AI assistants to perform various Gmail operations including:
- Fetching emails from your inbox
- Searching emails by subject
- Searching emails from specific senders
- Retrieving unread emails
- Sending emails to recipients
The server uses IMAP for email retrieval and SMTP for sending emails, all secured through Gmail's authentication system.
- Clone the repository
git clone https://github.com/shubhiscoding/Gmail-MCP-Server
cd gmail-mcp- Install dependencies
npm install- Create a
.envfile in the root directory with the following variables:
GMAIL_USER=your_gmail_address
GMAIL_APP_PASSWORD=your-app-password
To generate an App Password for your Gmail account:
- Go to your Google Account > Security
- Enable 2-Step Verification if not already enabled
- Go to App passwords
- Select "Mail" and your device
- Click "Generate"
Start the server in development mode:
npm run devConfigure mcp_config.json to add gmail-mcp server:
{
"mcpServers": {
"gmail-mcp": {
"command": "bash",
"args": [
"-c",
"cd ~Your-Path-To-The-Repo/Gmail-MCP-Server && npm run start"
],
"disabled": false
}
}
}
{
"mcpServers": {
"gmail-mcp": {
"command": "cmd",
"args": ["/c", "cd /d ~Your-Path-To-The-Repo\\Gmail-MCP-Server && npm run start"]
}
}
}
gmail_mcp.mp4
Claude.demo.mp4
The server provides the following tools for AI assistants:
Fetches emails from your inbox with optional filtering.
Parameters:
limit(optional): Maximum number of emails to fetch (default: 10)mailbox(optional): Mailbox to fetch emails from (default: 'INBOX')searchCriteria(optional): IMAP search criteria (default: ['ALL'])
Fetches emails with a specific subject.
Parameters:
subject: Subject to search forlimit(optional): Maximum number of emails to fetch (default: 10)
Fetches emails from a specific sender.
Parameters:
sender: Email address of the senderlimit(optional): Maximum number of emails to fetch (default: 10)
Fetches unread emails from your inbox.
Parameters:
limit(optional): Maximum number of emails to fetch (default: 10)
Sends an email to a specified recipient.
Parameters:
to: Email address of the recipientsubject: Subject of the emailbody: Body of the email
This server uses environment variables to store sensitive information like your Gmail credentials. Never commit your .env file to version control.
The project is built with:
- TypeScript for type safety
- Node.js IMAP and Nodemailer libraries for email operations
- FastMCP for MCP server implementation
- dotenv for environment variable management