
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@cristiano-morgante/gmail-mcp-manager
Advanced tools
MCP Server for Gmail API management with OAuth2 authentication and Context7 integration
A complete MCP (Model Context Provider) Server for Gmail API management with OAuth2 authentication and Context7 integration. This package provides both a CLI interface and a programmatic API for managing Gmail operations with automatic documentation integration.
# Install globally for CLI usage
npm install -g @cristiano-morgante/gmail-mcp-manager
# Or install locally for programmatic usage
npm install @cristiano-morgante/gmail-mcp-manager
Get Google OAuth2 Credentials
Configure Environment
# Copy the example environment file
cp .env.example .env
# Edit .env with your credentials
GOOGLE_CLIENT_ID=your_client_id_here
GOOGLE_CLIENT_SECRET=your_client_secret_here
Authenticate
# CLI authentication
gmail-mcp auth login
# Or programmatically (will prompt for auth)
node -e "import('@cristiano-morgante/gmail-mcp-manager').then(({createFromEnvironment}) => createFromEnvironment().initialize())"
# Login with Google OAuth2
gmail-mcp auth login
# Check authentication status
gmail-mcp auth status
# Logout and revoke tokens
gmail-mcp auth logout
# List recent messages
gmail-mcp messages list
# List unread messages
gmail-mcp messages list --query "is:unread"
# List messages with attachments
gmail-mcp messages list --query "has:attachment" --max 20
# Get specific message details
gmail-mcp messages get MESSAGE_ID
# Send an email (interactive)
gmail-mcp messages send
# List drafts
gmail-mcp drafts list
# Create a new draft (interactive)
gmail-mcp drafts create
# Send a draft
gmail-mcp drafts send DRAFT_ID
# Mark messages as read
gmail-mcp batch mark-read MSG_ID1 MSG_ID2 MSG_ID3
# Archive messages
gmail-mcp batch archive MSG_ID1 MSG_ID2
# List all labels
gmail-mcp labels
# Show email statistics
gmail-mcp stats
# Context7 documentation
gmail-mcp context7 status
gmail-mcp context7 get sendMessage
gmail-mcp context7 clear-cache
import { createFromEnvironment } from '@cristiano-morgante/gmail-mcp-manager';
async function example() {
// Create manager from environment variables
const manager = createFromEnvironment();
// Initialize (handles authentication)
await manager.initialize();
// List recent messages
const messages = await manager.listMessages({
maxResults: 10,
query: 'is:unread'
});
// Send an email
const email = {
to: ['recipient@example.com'],
subject: 'Hello from Gmail MCP!',
body: 'This email was sent using Gmail MCP Server.',
isHtml: false
};
const sentMessage = await manager.sendMessage(email);
console.log('Email sent:', sentMessage.id);
}
import { GmailMCPManager, GMAIL_SCOPES } from '@cristiano-morgante/gmail-mcp-manager';
const config = {
oauth2: {
clientId: 'your_client_id',
clientSecret: 'your_client_secret',
redirectUri: 'http://localhost:3000/oauth2callback',
scopes: [GMAIL_SCOPES.MODIFY, GMAIL_SCOPES.COMPOSE]
},
defaultUserId: 'me',
context7Enabled: true,
tokenStoragePath: './custom-tokens.json'
};
const manager = new GmailMCPManager(config);
await manager.initialize();
// Get documentation for specific operations
const docs = await manager.getDocumentation('sendMessage', 'HTML email');
console.log('Documentation:', docs.documentation);
console.log('Examples:', docs.examples);
// Get documentation as code comments
const comments = await manager.getDocumentationAsComments('listMessages');
console.log(comments);
Variable | Required | Default | Description |
---|---|---|---|
GOOGLE_CLIENT_ID | ✅ | - | Google OAuth2 Client ID |
GOOGLE_CLIENT_SECRET | ✅ | - | Google OAuth2 Client Secret |
GOOGLE_REDIRECT_URI | ❌ | http://localhost:3000/oauth2callback | OAuth2 redirect URI |
GOOGLE_SCOPES | ❌ | gmail.modify | Comma-separated Gmail scopes |
TOKEN_STORAGE_PATH | ❌ | ~/.gmail-mcp-tokens.json | Token storage file path |
DEFAULT_USER_ID | ❌ | me | Default Gmail user ID |
CONTEXT7_ENABLED | ❌ | true | Enable Context7 integration |
Available scopes (use GMAIL_SCOPES
constants):
GMAIL_SCOPES.READONLY
- Read-only accessGMAIL_SCOPES.MODIFY
- Read/write access (recommended)GMAIL_SCOPES.COMPOSE
- Compose and send emailsGMAIL_SCOPES.SEND
- Send emails onlyGMAIL_SCOPES.LABELS
- Manage labelsGMAIL_SCOPES.SETTINGS_BASIC
- Basic settings access// Initialization
await manager.initialize(): Promise<void>
// Message operations
await manager.listMessages(options?: EmailListOptions): Promise<ListMessagesResponse>
await manager.getMessage(messageId: string, format?: 'full' | 'metadata' | 'minimal'): Promise<GmailMessage>
await manager.sendMessage(email: EmailComposition): Promise<GmailMessage>
// Draft operations
await manager.createDraft(email: EmailComposition): Promise<GmailDraft>
await manager.updateDraft(draftId: string, email: EmailComposition): Promise<GmailDraft>
await manager.sendDraft(draftId: string): Promise<GmailMessage>
await manager.listDrafts(maxResults?: number, pageToken?: string): Promise<ListDraftsResponse>
// Batch operations
await manager.performBatchOperation(operation: BatchOperation): Promise<void>
// Utility methods
await manager.getLabels(): Promise<ListLabelsResponse>
await manager.getEmailStats(): Promise<EmailStats>
await manager.getThread(threadId: string, format?: string): Promise<GmailThread>
await manager.listThreads(options?: EmailListOptions): Promise<ListThreadsResponse>
// Authentication
await manager.logout(): Promise<void>
await manager.getTokenInfo(): Promise<any>
// Context7 integration
await manager.getDocumentation(operation: string, context?: string): Promise<Context7Response | null>
await manager.getDocumentationAsComments(operation: string, context?: string): Promise<string>
manager.enableContext7(): void
manager.disableContext7(): void
manager.clearContext7Cache(): void
manager.getContext7Stats(): { size: number; keys: string[] }
interface EmailComposition {
to: string[];
cc?: string[];
bcc?: string[];
subject: string;
body: string;
isHtml?: boolean;
attachments?: EmailAttachment[];
}
interface EmailListOptions {
query?: string;
labelIds?: string[];
maxResults?: number;
pageToken?: string;
includeSpamTrash?: boolean;
userId?: string;
}
interface BatchOperation {
messageIds: string[];
action: 'read' | 'unread' | 'archive' | 'delete' | 'trash' | 'spam';
labelIds?: string[];
}
Gmail MCP supports advanced search queries:
// Search examples
await manager.listMessages({ query: 'is:unread' });
await manager.listMessages({ query: 'from:important@company.com' });
await manager.listMessages({ query: 'has:attachment subject:invoice' });
await manager.listMessages({ query: 'is:starred newer_than:7d' });
await manager.listMessages({ query: 'label:important OR label:urgent' });
Efficiently process multiple messages:
const operation = {
messageIds: ['msg1', 'msg2', 'msg3'],
action: 'archive'
};
await manager.performBatchOperation(operation);
const email = {
to: ['recipient@example.com'],
subject: 'Report with Attachment',
body: '<h1>Monthly Report</h1><p>Please find the report attached.</p>',
isHtml: true,
attachments: [
{
filename: 'report.pdf',
content: fileBuffer, // Buffer or base64 string
contentType: 'application/pdf'
}
]
};
await manager.sendMessage(email);
# Clone the repository
git clone https://github.com/Simplify-Technology/gmail-mcp-manager.git
cd gmail-mcp-manager
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Start development mode
npm run dev
src/
├── auth.service.ts # OAuth2 authentication
├── gmail.service.ts # Gmail API operations
├── context7.ts # Context7 integration
├── index.ts # Main module exports
├── cli.ts # CLI interface
└── types.ts # TypeScript definitions
examples/
├── basic-usage.js # Basic usage example
└── advanced-usage.js # Advanced features example
600
permissions (owner read/write only).env
files to version controlgit checkout -b feature/amazing-feature
git commit -m 'Add amazing feature'
git push origin feature/amazing-feature
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ for the MCP ecosystem
FAQs
MCP Server for Gmail API management with OAuth2 authentication and Context7 integration
We found that @cristiano-morgante/gmail-mcp-manager demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.