Skip to main content
Glama
sejalpatole

Gmail MCP Server

by sejalpatole

šŸ“§ 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

git clone https://github.com/your-username/mcp-practice.git
cd mcp-practice
  1. Create a virtual environment

python -m venv .venv
  1. Activate the environment

Windows

.venv\Scripts\activate

Linux/macOS

source .venv/bin/activate
  1. Install dependencies

pip install -r requirements.txt

šŸ”‘ Configure Environment Variables

Create a .env file and add:

GOOGLE_CLIENT_SECRET_PATH=client_secret.json
GOOGLE_TOKEN_PATH=token.json

ā–¶ļø Authenticate Gmail

python oauth.py

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

ā–¶ļø Run the MCP Server

python main.py

or

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.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sejalpatole/Gmail-MCP-Server-using-FastMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server