Skip to main content
Glama
sejalpatole

Gmail MCP Server

by sejalpatole
README.md
# šŸ“§ Gmail MCP Server using FastMCP

A Model Context Protocol (MCP) server built with FastMCP that integrates with the Gmail API. This project demonstrates how to create AI-accessible tools for reading and sending emails using Google OAuth authentication.

## šŸš€ Features

- šŸ” Google OAuth 2.0 authentication
- šŸ“© Send emails through Gmail
- šŸ“„ Read Gmail messages
- šŸ› ļø MCP tools using FastMCP
- ⚔ Lightweight Python implementation
- šŸ”’ Secure credential management using environment variables

## šŸ› ļø Tech Stack

- Python 3.13
- FastMCP
- Gmail API
- Google OAuth 2.0
- Uvicorn
- python-dotenv

## šŸ“‚ Project Structure

```
.
ā”œā”€ā”€ main.py
ā”œā”€ā”€ oauth.py
ā”œā”€ā”€ tools/
│   ā”œā”€ā”€ gmail.py
│   └── __init__.py
ā”œā”€ā”€ .env
ā”œā”€ā”€ requirements.txt
└── README.md
```

## āš™ļø Installation

1. Clone the repository

```bash
git clone https://github.com/your-username/mcp-practice.git
cd mcp-practice
```

2. Create a virtual environment

```bash
python -m venv .venv
```

3. Activate the environment

Windows

```bash
.venv\Scripts\activate
```

Linux/macOS

```bash
source .venv/bin/activate
```

4. Install dependencies

```bash
pip install -r requirements.txt
```

## šŸ”‘ Configure Environment Variables

Create a `.env` file and add:

```env
GOOGLE_CLIENT_SECRET_PATH=client_secret.json
GOOGLE_TOKEN_PATH=token.json
```

## ā–¶ļø Authenticate Gmail

```bash
python oauth.py
```

This will open a browser for Google authentication and generate `token.json`.

## ā–¶ļø Run the MCP Server

```bash
python main.py
```

or

```bash
uv run fastmcp dev main.py:mcp
```

## šŸ“š Learning Objectives

This project was created to practice:

- Model Context Protocol (MCP)
- FastMCP framework
- Tool decorators
- Prompt decorators
- Google OAuth
- Gmail API integration
- AI tool development

## šŸ“Œ Future Improvements

- Email search
- Delete emails
- Mark emails as read/unread
- Attachment support
- Async MCP tools
- Better error handling

## šŸ¤ Contributing

Contributions and suggestions are welcome.

## šŸ“„ License

This project is for educational and learning purposes.