A Python application that uses the Model Context Protocol (MCP) to interact with Gmail and perform mathematical calculations. This application demonstrates the use of multiple MCP servers working together.
- Gmail Operations:
- Send emails
- Read unread emails
- Trash emails
- Open emails in browser
- Mark emails as read
- Mathematical Operations:
- Basic arithmetic (add, subtract, multiply, divide)
- Advanced operations (power, square root, etc.)
- List operations
- Special functions (factorial, trigonometry)
- Python 3.7 or higher
- Google account with Gmail
- Google Cloud Project with Gmail API enabled
- Clone the repository:
git clone https://github.com/RohinSequeira/mcp_gmail.git
cd mcp_gmail- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On macOS/Linux- Install dependencies:
pip install -r requirements.txt- Set up Google API credentials:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Gmail API
- Create OAuth 2.0 credentials
- Download the credentials and save as
credentials.jsonin the project root
- Place your Google API credentials:
- Save your OAuth credentials as
credentials.jsonin the project root - First run will generate
token.jsonafter authentication
- Save your OAuth credentials as
Note: Both credentials.json and token.json are gitignored for security. Keep these files secure and never commit them to version control.
Run the main application:
python talk2mcp-2.pyThe application will:
- Connect to both MCP servers (Gmail and Calculator)
- Initialize the sessions
- Authenticate with Gmail (first run only)
- Process commands for both email and mathematical operations
server.py: Gmail MCP server implementation and email toolsexample2-3.py: Calculator MCP server with math toolstalk2mcp-2.py: Main client application that interfaces with both servers.gitignore: Specifies files to ignore in version controlrequirements.txt: Python package dependencies
send_email(recipient_id, subject, message): Send an emailget_unread_emails(): Get list of unread emailsread_email(email_id): Read a specific emailtrash_email(email_id): Move email to trashopen_email(email_id): Open email in browser
add(a, b): Add two numberssubtract(a, b): Subtract two numbersmultiply(a, b): Multiply two numbersdivide(a, b): Divide two numberspower(a, b): Calculate powersqrt(a): Calculate square root- Additional mathematical functions...
The application includes comprehensive error handling for:
- Gmail API authentication and operations
- Mathematical operations
- Server connections
- Tool execution
- Parameter validation
- OAuth 2.0 authentication for Gmail
- Secure token storage
- Credentials and tokens are not committed to version control
- Environment-based configuration
Feel free to submit issues and enhancement requests!