The Gmail MCP Server provides Gmail API integration for AI assistants through the Model Context Protocol. It enables AI systems to read emails, search for specific messages, send emails, create drafts, and manage various aspects of a Gmail account through a standardized interface.
credentials.json
)google-auth
google-auth-oauthlib
google-api-python-client
mcp
(Model Context Protocol SDK)Clone the repository:
git clone https://github.com/yourusername/gmail-mcp.git
cd gmail-mcp
Install dependencies:
pip install -r requirements.txt
Set up Gmail API credentials:
credentials.json
in the project root directoryTo start the Gmail MCP server:
python -m gmail.server
Or use the convenience script:
python gmail_server.py
The first time you run the server, it will open a browser window for authentication with your Google account. After successful authentication, a token.json
file will be created to store your credentials for future use.
The Gmail MCP server provides the following tools for AI assistants:
Tool Name | Description | Parameters |
---|---|---|
get_labels_tool |
Get all Gmail labels and their IDs | None |
get_inbox_messages |
Get recent messages from the Gmail inbox | max_results (optional, default: 10) |
get_message_content_tool |
Get the full content of a specific email | message_id (required) |
send_email |
Send an email from your Gmail account | to , subject , body (all required) |
search_emails_tool |
Search for emails using Gmail search syntax | query (required), max_results (optional, default: 10) |
create_draft |
Create a draft email | to , subject , body (all required) |
add_label_to_message |
Add a label to a specific email message | message_id , label_name (both required) |
get_thread |
Get all messages in an email conversation thread | thread_id (required) |
mark_as_read |
Mark an email message as read | message_id (required) |
mark_as_unread |
Mark an email message as unread | message_id (required) |
archive_message |
Archive an email message | message_id (required) |
trash_message |
Move an email message to the Gmail trash | message_id (required) |
The server also provides the following MCP resources:
Resource URI | Description |
---|---|
gmail://labels |
List of all Gmail labels |
gmail://inbox |
Recent messages from the inbox |
gmail://message/{message_id} |
Content of a specific email message |
gmail://search/{query} |
Results of a Gmail search query |
In addition to the MCP server, you can use the included command-line interface:
python gmail_cli.py [command] [options]
python gmail_cli.py search "from:[email protected] is:unread" --max 5
This searches for up to 5 unread emails from [email protected].
The Gmail MCP server uses OAuth 2.0 for authentication with the Gmail API:
token.json
Security Notes:
token.json
file contains sensitive authentication information and should be kept secureWhen connected to an AI assistant through MCP, you can ask natural language questions like:
If you encounter authentication problems:
token.json
fileThe Gmail API has usage quotas. If you hit these limits:
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.