gmail-mcp-server
by: jasonsum
Model Context Protocol (MCP) server for Gmail
📌Overview
Purpose: The Gmail Server for Model Context Protocol (MCP) is designed to facilitate the integration of email functionalities within applications, allowing operations such as sending, removing, reading, drafting, and responding to emails.
Overview: This MCP server seamlessly connects with Gmail, enabling clients to manage emails effectively. Users are prompted for confirmation before actions like reading or sending emails are performed, ensuring control over operations.
Key Features:
-
send-email: Sends an email to a specified recipient, taking in the recipient's address, subject, and message content; returns the status of the action and a message ID.
-
trash-email: Moves a specified email to trash by using its auto-generated ID; confirms the action with a success message.
-
mark-email-as-read: Marks a specific email as read, enhancing user organization; returns a confirmation of the action.
-
get-unread-emails: Retrieves a list of unread emails including their IDs, helping users manage their inbox efficiently.
-
read-email: Fetches the content of a given email, marks it as read, and returns its metadata for user reference.
-
open-email: Opens a specified email in the default browser, providing a quick way for users to view email details; confirms successful action with a message.
Gmail Server for Model Context Protocol (MCP)
This MCP server integrates with Gmail to enable sending, removing, reading, drafting, and responding to emails.
Note: The server prompts the user before sending, removing, or reading emails.
Components
Tools
-
send-email
- Sends an email to the recipient.
- Input:
recipient_id
: Email address of the addresseesubject
: Email subjectmessage
: Email content
- Returns: Status and message_id
-
trash-email
- Moves an email to trash.
- Input:
email_id
: Auto-generated ID of the email
- Returns: Success message
-
mark-email-as-read
- Marks an email as read.
- Input:
email_id
: Auto-generated ID of the email
- Returns: Success message
-
get-unread-emails
- Retrieves unread emails.
- Returns: List of unread emails including email IDs
-
read-email
- Retrieves the content of a given email.
- Input:
email_id
: Auto-generated ID of the email
- Returns: Dictionary of email metadata and marks email as read
-
open-email
- Opens an email in the browser.
- Input:
email_id
: Auto-generated ID of the email
- Returns: Success message and opens the email in the default browser
Setup
Gmail API Setup
- Create a new Google Cloud project.
- Enable the Gmail API.
- Configure an OAuth consent screen:
- Select "external" and add your personal email as a "Test user".
- Add OAuth scope
https://www.googleapis.com/auth/gmail/modify
. - Create an OAuth Client ID for application type "Desktop App".
- Download the JSON file of your client's OAuth keys.
- Save the key file to a secure location and note the path.
Authentication
An authentication flow will launch in your system browser when the server starts. Token credentials will be saved in the path specified by the --token-path
parameter.
Parameter | Example |
---|---|
--creds-file-path | /[your-home-folder]/.google/client_creds.json |
--token-path | /[your-home-folder]/.google/app_tokens.json |
Usage with Desktop App
Using uv is recommended. To integrate this server with Claude Desktop, add the following to your app’s server configuration.
{
"mcpServers": {
"gdrive": {
"command": "uv",
"args": [
"--directory",
"[absolute-path-to-git-repo]",
"run",
"gmail",
"--creds-file-path",
"[absolute-path-to-credentials-file]",
"--token-path",
"[absolute-path-to-access-tokens-file]"
]
}
}
}
Parameter | Example |
---|---|
--directory | Absolute path to gmail directory |
--creds-file-path | Absolute path to credentials file |
--token-path | Absolute path to store and retrieve tokens |
Troubleshooting with MCP Inspector
To test the server, use MCP Inspector. Run the following command, adjusting parameters accordingly:
npx @modelcontextprotocol/inspector uv run [absolute-path-to-git-repo]/src/gmail/server.py --creds-file-path [absolute-path-to-credentials-file] --token-path [absolute-path-to-access-tokens-file]