MCP Math Gmail Client
Agent with MCP server solves math task and emails the output
movva09
README
MCP Math Gmail Client
The Math Gmail Client (talk2mcp_math_gmail_client.py
) is a Python application that integrates mathematical computations with Gmail functionality. It uses the Gemini AI model to process mathematical queries and can send results via email.
Features
- Integration with Gemini AI for mathematical problem-solving
- Gmail integration for sending mathematical results
- Iterative problem-solving approach
- Support for various mathematical operations
- Automated email generation with mathematical results
- Secure Gmail authentication
- Multiple recipient support
Server Requirements
- MCP Server Setup:
- Python 3.x environment
- MCP server package installed
- Required server dependencies:
mcp
package
Prerequisites
- Python 3.x
- Required Python packages:
python-dotenv
google-generativeai
mcp
packagegoogle-auth
google-auth-oauthlib
google-auth-httplib2
google-api-python-client
Environment Setup
- Create a
.env
file in the project root - Add your API keys:
GEMINI_API_KEY=your_api_key_here GMAIL_CLIENT_ID=your_client_id_here GMAIL_CLIENT_SECRET=your_client_secret_here
Server Setup
-
Install server dependencies:
pip install mcp numpy pandas matplotlib
-
Start the MCP server:
python example2-3_gmail_server_2.py
Available Tools
Currently Implemented Tools
-
Mathematical Operations:
- Basic arithmetic operations (add, subtract, multiply, divide)
- Advanced mathematical functions (exponential, logarithmic)
- ASCII value calculations
- String manipulation and conversion
- Array operations
- Prime number calculations
- Factorial computations
- Fibonacci sequence generation
-
Email Tools:
- Single recipient email sending
- Basic email formatting
- Simple attachment handling
- Basic error handling
- Gmail authentication
- Email queue management
- Basic delivery status tracking
Installation
- Clone the repository
- Install required packages:
pip install python-dotenv google-generativeai mcp google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client
- Set up your environment variables as described above
- Set up Gmail API credentials:
- Go to Google Cloud Console
- Create a new project
- Enable Gmail API
- Create OAuth 2.0 credentials
- Download the credentials file
Usage
- Start the MCP server (see Server Setup section)
- Ensure the server is running and accessible
- Run the client:
python talk2mcp_math_gmail_client.py
Server-Client Communication
-
Connection Protocol:
- Client establishes connection with server
- Authentication handshake
- Tool list synchronization
- Session initialization
- Email service verification
-
Data Flow:
- Client sends mathematical queries
- Server processes requests
- Results are formatted for email
- Email queue is managed
- Delivery status is tracked
- Notifications are sent
-
Error Handling:
- Connection retry mechanism
- Session recovery
- Email queue recovery
- Rate limit handling
- Resource cleanup
Example Queries
- Basic Mathematical Email:
Calculate the factorial of 10 and send the result to user@example.com with the subject "Factorial Calculation Result".
- Complex Mathematical Analysis:
Find the first 50 Fibonacci numbers, calculate their sum, and send the detailed analysis to team@example.com with a graph attachment.
- Multiple Operations with Formatting:
Calculate the roots of the quadratic equation x² + 5x + 6 = 0, format the solution in LaTeX, and send it to professor@example.com with proper mathematical notation.
- Scheduled Mathematical Report:
Generate a report of prime numbers between 1 and 1000, create a histogram of their distribution, and schedule it to be sent to research@example.com tomorrow at 9:00 AM.
How It Works
- The client connects to the MCP server
- It processes mathematical queries using the Gemini AI model
- Results are formatted for email
- The system uses an iterative approach to solve complex problems
- Results are sent via Gmail to specified recipients
Error Handling
The client includes robust error handling for:
- API timeouts
- Invalid inputs
- Connection issues
- Tool execution errors
- Gmail authentication and sending errors
Security
- Uses OAuth 2.0 for Gmail authentication
- Secure storage of API keys and credentials
- Encrypted communication with Gmail API
Contributing
Feel free to submit issues and enhancement requests.
License
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Troubleshooting
-
Common Issues:
- Email delivery failures
- Attachment size limits
- Authentication problems
- Rate limiting issues
- Connection timeouts
-
Solutions:
- Check email server status
- Verify API quotas
- Review error logs
- Check network connectivity
- Validate credentials
Performance Tips
-
Optimization:
- Batch processing for large emails
- Attachment compression
- Connection pooling
- Cache management
- Resource monitoring
-
Best Practices:
- Regular backup of email templates
- Monitor API usage
- Implement retry mechanisms
- Use efficient data structures
- Regular system maintenance
Recommended Servers
Crypto Price & Market Analysis MCP Server
A Model Context Protocol (MCP) server that provides comprehensive cryptocurrency analysis using the CoinCap API. This server offers real-time price data, market analysis, and historical trends through an easy-to-use interface.
MCP PubMed Search
Server to search PubMed (PubMed is a free, online database that allows users to search for biomedical and life sciences literature). I have created on a day MCP came out but was on vacation, I saw someone post similar server in your DB, but figured to post mine.
dbt Semantic Layer MCP Server
A server that enables querying the dbt Semantic Layer through natural language conversations with Claude Desktop and other AI assistants, allowing users to discover metrics, create queries, analyze data, and visualize results.
mixpanel
Connect to your Mixpanel data. Query events, retention, and funnel data from Mixpanel analytics.

Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Nefino MCP Server
Provides large language models with access to news and information about renewable energy projects in Germany, allowing filtering by location, topic (solar, wind, hydrogen), and date range.
Vectorize
Vectorize MCP server for advanced retrieval, Private Deep Research, Anything-to-Markdown file extraction and text chunking.
Mathematica Documentation MCP server
A server that provides access to Mathematica documentation through FastMCP, enabling users to retrieve function documentation and list package symbols from Wolfram Mathematica.
kb-mcp-server
An MCP server aimed to be portable, local, easy and convenient to support semantic/graph based retrieval of txtai "all in one" embeddings database. Any txtai embeddings db in tar.gz form can be loaded
Research MCP Server
The server functions as an MCP server to interact with Notion for retrieving and creating survey data, integrating with the Claude Desktop Client for conducting and reviewing surveys.