This project demonstrates how to use FastAgent to interact with Gmail API via MCP to search and read emails.
- Python 3.8+
- UV package manager (
pip install uv
) - Node.js and npm (for Gmail OAuth server)
- Ollama (for running LLMs)
uv pip install fast-agent-mcp - Install fast-agent.
fast-agent setup - Create Agent and Configuration files in your current directory. Switch to your workspace directory before you run.
Update fastagent.config.yaml
with the following model configuration:
default_model: generic.granite3.3:latest #To switch model, change this to any of the following
generic.qwen3:8b:
api_key: "ollama"
base_url: "http://localhost:11434/v1"
generic.llama3.2:latest:
api_key: "ollama" # Default for Ollama, change as needed
base_url: "http://localhost:11434/v1" # Default for Ollama
generic.granite3.3:latest:
api_key: "ollama"
base_url: "http://localhost:11434/v1"
Add the server-gmail-autoauth-mcp to your fastagent.secrets.yaml
under mcp>server:
mcp:
servers:
server-gmail-autoauth-mcp:
command: "npx"
args: ["@gongrzhe/server-gmail-autoauth-mcp"]
- Enable Gmail API and get gcp-oauth.keys.json from Google Developer Console. For further information, see the Gongrzhe GitHub repository.
- Install the Gmail OAuth MCP server:
npx -y @smithery/cli install @gongrzhe/server-gmail-autoauth-mcp
# Create directory for OAuth credentials
mkdir -p ~/.gmail-mcp
# Place your GCP OAuth credentials file (gcp-oauth.keys.json) in the directory
mv gcp-oauth.keys.json ~/.gmail-mcp/
- First, authenticate with Gmail:
Follow the OAuth flow in your browser to grant access to your Gmail account.
npx @gongrzhe/server-gmail-autoauth-mcp auth
Run the Gmail agent:
uv run agent.py
The script will:
- Search for your latest email
- Display the email details in the console
The gmail.py
script uses FastAgent to:
- Search for emails using the
search_emails
MCP model - Read the full content of the latest email using the
read_email
MCP model - Print the results to the console
You can modify the search criteria in gmail.py
by changing the parameters passed to agent.email_reader()
. For example:
# To get the 5 most recent emails
result = await agent.email_reader({"maxResults": 5})