GmailTool provides read-only access to Gmail for listing, searching, and fetching messages using the Gmail API.
Installation
Install the Google dependencies:Authentication
GmailTool requires Google OAuth2 credentials:- Create credentials using the
superauthlibrary - Save credentials to a JSON file
- Provide the path or set
GOOGLE_USER_CREDENTIALSenvironment variable
Constructor
str
Path to saved user credentials JSON file. Defaults to
GOOGLE_USER_CREDENTIALS env var or credentials.jsonCredentialRecord
Pre-loaded credentials object. Overrides credentials_path if provided
Methods
search_messages
Search Gmail using the same query syntax as the web UI.str
required
Gmail search query (e.g.,
from:alice has:attachment newer_than:7d)List[str]
Optional Gmail label IDs to filter by
str
ISO date string to filter messages after
str
ISO date string to filter messages before
int
Number of messages to return (1-50, default: 20)
list_messages
List message IDs (fast, metadata-only).List[str]
Optional Gmail label IDs to filter by
str
Optional Gmail query string
int
Number of messages to return (1-50, default: 20)
str
Pagination token from previous call
bool
Whether to include spam and trash (default: False)
get_message
Fetch a single Gmail message (metadata only).str
required
Gmail message ID
get_message_body
Fetch a single Gmail message body for display or summarization.str
required
Gmail message ID
str
“text” or “html” (default: “text”)
int
Max characters to return (default: 50000)
Usage
Basic setup
Searching emails
Reading message bodies
Privacy and security
Error handling
Source reference
src/agentor/tools/gmail.py:19