Skip to content

This project demonstrates how to use FastAgent to interact with Gmail API via MCP to search and read emails.

Notifications You must be signed in to change notification settings

yashwanthm/fastagent-gmail-mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Gmail MCP Agent with FastAgent

This project demonstrates how to use FastAgent to interact with Gmail API via MCP to search and read emails.

Prerequisites

  1. Python 3.8+
  2. UV package manager (pip install uv)
  3. Node.js and npm (for Gmail OAuth server)
  4. Ollama (for running LLMs)

Setup

1. FastAgent Installation

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.

2. Configure FastAgent

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"

3. Add Gmail MCP Server

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"]

3. Set Up Gmail OAuth Server

  1. Enable Gmail API and get gcp-oauth.keys.json from Google Developer Console. For further information, see the Gongrzhe GitHub repository.
  2. 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/
  1. First, authenticate with Gmail:
    npx @gongrzhe/server-gmail-autoauth-mcp auth
    Follow the OAuth flow in your browser to grant access to your Gmail account.

Running the Gmail Agent

Run the Gmail agent:

uv run agent.py

The script will:

  1. Search for your latest email
  2. Display the email details in the console

How It Works

The gmail.py script uses FastAgent to:

  1. Search for emails using the search_emails MCP model
  2. Read the full content of the latest email using the read_email MCP model
  3. Print the results to the console

Customization

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})

About

This project demonstrates how to use FastAgent to interact with Gmail API via MCP to search and read emails.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages