cnye36/gmail-mcp-server
If you are the rightful owner of gmail-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server that provides comprehensive Gmail integration for AI assistants.
Gmail MCP Server
A Model Context Protocol (MCP) server that provides comprehensive Gmail integration for AI assistants. Built with the mcp-framework, this server enables AI models to send emails, search your inbox, read messages, manage drafts, and more through Gmail's API.
š Features
Available Gmail Tools
- š§ gmail.sendEmail - Send plain-text emails
- š gmail.searchEmails - Search emails using Gmail's powerful query syntax
- š gmail.readEmail - Read full email content by message ID
- š gmail.createDraft - Create and save draft emails
- šļø gmail.deleteEmail - Delete or move emails to trash
- š·ļø gmail.listLabels - List all Gmail labels and folders
- š¤ gmail.getUserProfile - Get user's Gmail profile information
Transport & Authentication
- HTTP Stream Transport - RESTful API following MCP 2025-03-26 specification
- Token-based Authentication - Secure authentication using Google access tokens
- CORS Support - Ready for web-based integrations
- Environment Configuration - Flexible setup via environment variables
š Prerequisites
- Node.js 18 or later
- pnpm package manager (recommended) or npm
- Google Cloud Project with Gmail API enabled
- Gmail API credentials (OAuth 2.0)
ā” Quick Start
1. Clone and Install
git clone https://github.com/cnye36/gmail-mcp-server.git
cd gmail-mcp-server
pnpm install
2. Environment Setup
Create a .env
file in the root directory:
# Server Configuration
PORT=8080
# Gmail API Access Token (required)
GOOGLE_ACCESS_TOKEN=your-google-access-token-here
# Optional: Google OAuth Client ID for ID token authentication
GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com
3. Google API Setup
Option A: OAuth2 Playground (Easiest for testing)
- Visit Google OAuth2 Playground
- Configure with your OAuth credentials (click gear icon āļø)
- Select Gmail API scopes:
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/gmail.send
https://www.googleapis.com/auth/gmail.modify
- Complete authorization and get your access token
- Add the token to your
.env
file
Option B: Google Cloud Console
- Go to Google Cloud Console
- Create/select a project and enable Gmail API
- Create OAuth 2.0 credentials
- Use your client ID in the
.env
file
4. Build and Start
# Build the TypeScript project
pnpm run build
# Start the server
pnpm start
Server will be available at: http://localhost:8080/mcp
š Usage
With Claude Desktop
Add to your Claude Desktop MCP configuration:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"gmail": {
"command": "node",
"args": ["/absolute/path/to/gmail-mcp-server/dist/index.js"],
"env": {
"GOOGLE_ACCESS_TOKEN": "your-access-token-here",
"PORT": "8080"
}
}
}
}
HTTP API Example
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-H "x-google-access-token: your-access-token" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "gmail.searchEmails",
"arguments": {
"query": "from:example@gmail.com is:unread",
"maxResults": 10
}
}
}'
Gmail Search Query Examples
The gmail.searchEmails
tool supports Gmail's full query syntax:
from:sender@example.com # From specific sender
to:recipient@example.com # To specific recipient
subject:"meeting notes" # Subject contains phrase
has:attachment # Has attachments
is:unread # Unread emails
is:important # Important emails
label:work # Has specific label
newer_than:7d # Last 7 days
older_than:1m # Older than 1 month
š ļø Development
Project Structure
gmail-mcp-server/
āāā src/
ā āāā auth/ # Authentication providers
ā ā āāā TokenAuthProvider.ts
ā ā āāā GoogleAuthProvider.ts
ā āāā tools/ # Gmail tool implementations
ā ā āāā SendEmail.ts
ā ā āāā SearchEmails.ts
ā ā āāā ReadEmail.ts
ā ā āāā CreateDraft.ts
ā ā āāā DeleteEmail.ts
ā ā āāā ListLabels.ts
ā ā āāā GetUserProfile.ts
ā āāā index.ts # Server entry point
āāā package.json
āāā tsconfig.json
āāā .env # Environment variables
āāā SETUP.md # Detailed setup guide
Available Scripts
pnpm run build # Build TypeScript to JavaScript
pnpm run start # Start the production server
pnpm run dev # Start development with file watching
pnpm run test # Build and test the server
pnpm run clean # Remove build artifacts
Adding New Tools
- Create a new file in
src/tools/
- Extend the
MCPTool
class - Define your tool's schema and execute method
- The framework will auto-discover your tool
Example:
import { MCPTool } from "mcp-framework";
import { z } from "zod";
export default class MyGmailTool extends MCPTool<{param: string}> {
name = "gmail.myTool";
description = "Description of what this tool does";
schema = {
param: {
type: z.string(),
description: "Parameter description"
},
};
async execute({param}: {param: string}) {
// Your Gmail API integration here
return { result: "success" };
}
}
š Security
- Token Management: Access tokens are passed via headers, never logged
- Environment Variables: Sensitive data kept in
.env
(not in version control) - CORS Configuration: Configurable origins for web integrations
- Error Handling: Detailed errors without exposing sensitive information
š¤ Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
š License
This project is licensed under the MIT License - see the LICENSE file for details.
š Support
- š Detailed setup instructions: See
- š Issues: GitHub Issues
- š¬ Discussions: MCP Framework Community
š Acknowledgments
- Built with MCP Framework
- Powered by Google Gmail API
- Follows Model Context Protocol specification