Skip to main content

Add your description here

Project description

Gmail MCP Server

smithery badge

A powerful and flexible Gmail integration server built using the MCP (Message Control Protocol) framework. This server provides a robust interface to interact with Gmail APIs, offering functionality for reading, sending, and managing emails programmatically.

Features

  • Read emails from multiple Gmail accounts
  • Send emails with attachments
  • Search emails with advanced query options
  • Download email attachments
  • Handle email conversations and threads
  • Real-time email monitoring
  • Support for multiple Gmail accounts

Prerequisites

Before running the Gmail MCP server, ensure you have the following:

  1. Python 3.12 or higher
  2. Google Cloud Project with Gmail API enabled
  3. OAuth 2.0 Client ID credentials
  4. Required Python packages (specified in pyproject.toml)

Installation

Installing via Smithery

To install Gmail Integration Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install @Quantum-369/Gmail-mcp-server --client claude
  1. Clone the repository:
git clone <your-repository-url>
cd gmail-mcp-server
  1. Create and activate a virtual environment:
python -m venv venv
# On Windows
venv\Scripts\activate
# On Unix/MacOS
source venv/bin/activate
  1. Install dependencies:
pip install .

Running on Ubuntu

  1. Install Python 3.12 and create a virtual environment if you haven't already:
    sudo apt install python3.12 python3.12-venv -y
    python3.12 -m venv venv
    source venv/bin/activate
    
  2. Place your downloaded client_secret.json in the project root.
  3. Generate an OAuth token for the Gmail account you want to use. Copy the URL printed by the script into a web browser and complete the sign-in process:
    python gmail_token_creator.py
    
  4. Start the server:
    python gmail_server.py
    

Setup Google Cloud Project

  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Gmail API for your project
  4. Create OAuth 2.0 credentials:
    • Go to "APIs & Services" > "Credentials"
    • Click "Create Credentials" > "OAuth client ID"
    • Choose "Desktop app" as application type
    • Download the client configuration file
  5. Rename the downloaded file to client_secret.json and place it in the project root directory

Configuration

  1. Set up email identifiers in gmail_token_creator.py:
email_identifier = 'your.email@gmail.com'  # Change this for each account
  1. Run the token creator to authenticate your Gmail accounts:
python gmail_token_creator.py

The script prints an authorization URL. Copy this URL into your web browser, complete the Google consent flow, and copy the verification code back into the terminal if prompted. A token file will be created inside token_files/ for future use.

  1. Repeat the process for each Gmail account you want to integrate

Server Structure

  • gmail_server.py: Main MCP server implementation
  • gmail_api.py: Gmail API interaction functions
  • google_apis.py: Google API authentication utilities
  • Supporting files:
    • read_emails.py: Email reading functionality
    • search_emails.py: Email search functionality
    • send_emails.py: Email sending functionality

Usage

Starting the Server

python gmail_server.py

Running with Docker

You can also build a container image using the provided Dockerfile:

docker build -t gmail-mcp-server .
docker run -v $(pwd)/client_secret.json:/app/client_secret.json \
           -v $(pwd)/token_files:/app/token_files gmail-mcp-server

The container runs the same server and stores authentication tokens in the token_files directory on the host so they persist between runs.

Available Tools

  1. Send Email:
await send_gmail(
    email_identifier="your.email@gmail.com",
    to="recipient@example.com",
    subject="Test Subject",
    body="Email body content",
    attachment_paths=["path/to/attachment"]
)
  1. Search Emails:
await search_email_tool(
    email_identifier="your.email@gmail.com",
    query="from:someone@example.com",
    max_results=30,
    include_conversations=True
)
  1. Read Latest Emails:
await read_latest_emails(
    email_identifier="your.email@gmail.com",
    max_results=5,
    download_attachments=False
)
  1. Download Attachments:
await download_email_attachments(
    email_identifier="your.email@gmail.com",
    msg_id="message_id",
    download_all_in_thread=False
)

Security Considerations

  • Store client_secret.json securely and never commit it to version control
  • Keep token files secure and add them to .gitignore
  • Use environment variables for sensitive information
  • Regularly rotate OAuth credentials
  • Monitor API usage and set appropriate quotas

Error Handling

The server includes comprehensive error handling and logging:

  • Logs are written to gmail_mcp.log
  • Both file and console logging are enabled
  • Detailed error messages for debugging

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

Apachelicense2.0

Support

For issues and feature requests, please use the GitHub issue tracker.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_quantum_369_gmail_server-0.1.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_quantum_369_gmail_server-0.1.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_quantum_369_gmail_server-0.1.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_quantum_369_gmail_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b2124cb9a32e51f37b05f1b35e68e378fcab2ced39b8f8352fe94c5f9938a891
MD5 0f8fb967794f1e78ade05498e87fb79f
BLAKE2b-256 c5896e28e8b1ebbbfaf0502eca8e46a43b686c84ddb652f70d024a0451162ef3

See more details on using hashes here.

File details

Details for the file iflow_mcp_quantum_369_gmail_server-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_quantum_369_gmail_server-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_quantum_369_gmail_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e574507d90466a2bdefb96e9b69b71c70a96b17bbc61e8dbb395808d49dea3a
MD5 ce5f1f3516ef94c501e87fb1068a24b2
BLAKE2b-256 0a118fc9cfa5f50fc0cabb446ab272fcae51083006ddf701cb4f879a5b8ed8cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page