Gmail MCP Server
Enables AI assistants to send, search, and read emails via Gmail using OAuth2 authentication.
README
Gmail MCP Server š§
A powerful Model Context Protocol (MCP) server that enables AI assistants like Claude to interact with Gmail. This server provides seamless integration for sending emails, searching messages, and reading email content directly through Claude.
⨠Features
- Send Emails: Compose and send emails directly through Claude
- Search Emails: Use Gmail's powerful search syntax to find specific messages
- Read Emails: Retrieve and read email content by message ID
- OAuth2 Authentication: Secure authentication using Google OAuth2
- Health Check: Built-in health monitoring endpoint
š Quick Start
Prerequisites
- Python 3.10 or higher
- A Google Cloud Platform account
- Claude Desktop App or any MCP-compatible client
Installation
-
Clone the repository
git clone https://github.com/Arpit-saxena-2004/gmail_mcp_server.git cd gmail_mcp_server -
Create a virtual environment
python -m venv .venv # On Windows .venv\Scripts\activate # On macOS/Linux source .venv/bin/activate -
Install dependencies
pip install -r requirements.txt
š Setting Up Google OAuth2 Credentials
Step 1: Create a Google Cloud Project
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Gmail API for your project:
- Navigate to "APIs & Services" > "Library"
- Search for "Gmail API"
- Click "Enable"
Step 2: Configure OAuth Consent Screen
- Go to "APIs & Services" > "OAuth consent screen"
- Choose "External" user type (or "Internal" if you have a Google Workspace)
- Fill in the required information:
- App name
- User support email
- Developer contact information
- Add scopes:
https://www.googleapis.com/auth/gmail.modify - Add test users (your email address)
Step 3: Create OAuth2 Credentials
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Choose "Desktop app" as the application type
- Name it (e.g., "Gmail MCP Server")
- Click "Create"
- Download the JSON file
- Rename it to
credentials.jsonand place it in the project root directory
āļø Configuration
Connecting to Claude Desktop
-
Locate your Claude Desktop configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
-
Add the MCP server configuration:
{ "mcpServers": { "gmail": { "command": "python", "args": [ "C:\\path\\to\\your\\gmail_mcp_server\\main.py" ] } } }Note: Replace
C:\\path\\to\\your\\gmail_mcp_server\\main.pywith the actual path to yourmain.pyfile. -
Restart Claude Desktop
First-Time Authentication
- When you first use the server, it will open a browser window
- Sign in with your Google account
- Grant the requested permissions
- The server will save a
token.jsonfile for future use - You won't need to authenticate again unless you revoke access
š Usage Examples
Once connected to Claude, you can use natural language to interact with Gmail:
Sending Emails
"Send an email to john@example.com with subject 'Meeting Tomorrow' and tell him about the 2pm meeting"
Searching Emails
"Search my emails for messages from Sarah in the last week"
Reading Emails
"What's the latest email in my inbox?"
š ļø Available Tools
health_check()
Check if the Gmail MCP server is running properly.
send_email(to: str, subject: str, body: str)
Send an email via Gmail.
- to: Recipient email address
- subject: Email subject line
- body: Email content
search_emails(query: str, max_results: int = 5)
Search emails using Gmail's search syntax.
- query: Gmail search query (e.g., "from:john@example.com", "subject:meeting")
- max_results: Maximum number of results to return (default: 5)
read_email(message_id: str)
Read a specific email by its message ID.
- message_id: The unique identifier of the email
š Security Notes
- Never commit
credentials.jsonortoken.jsonto version control - These files are already included in
.gitignore - Store credentials securely and rotate them periodically
- Only grant necessary scopes (currently:
gmail.modify)
š Project Structure
gmail_mcp_server/
āāā main.py # Main MCP server implementation
āāā credentials.json # OAuth2 credentials (not in repo)
āāā token.json # OAuth2 token (auto-generated)
āāā requirements.txt # Python dependencies
āāā pyproject.toml # Project metadata
āāā .gitignore # Git ignore rules
āāā README.md # This file
š Troubleshooting
"credentials.json not found"
- Make sure you've downloaded the OAuth2 credentials from Google Cloud Console
- Rename the file to exactly
credentials.json - Place it in the project root directory
Authentication window doesn't open
- Check if port 0 (random available port) is not blocked by firewall
- Try running the server manually first:
python main.py
"Invalid credentials" error
- Delete
token.jsonand authenticate again - Verify your OAuth2 consent screen is properly configured
- Ensure you've added your email as a test user
Claude can't connect to the server
- Verify the path in
claude_desktop_config.jsonis correct - Make sure you're using absolute paths
- Restart Claude Desktop after configuration changes
š¤ Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
š License
This project is licensed under the MIT License - see the LICENSE file for details.
š Acknowledgments
- Built with FastMCP - A fast, simple framework for building MCP servers
- Uses Google Gmail API
- Designed for Claude by Anthropic
š Support
If you encounter any issues or have questions:
- Open an issue on GitHub
- Check existing issues for solutions
- Review the MCP documentation
š Star History
If you find this project useful, please consider giving it a star! ā
Made with ā¤ļø for the Claude community
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.