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
Path to saved user credentials JSON file. Defaults to
GOOGLE_USER_CREDENTIALS env var or credentials.jsonPre-loaded credentials object. Overrides credentials_path if provided
Methods
search_messages
Search Gmail using the same query syntax as the web UI.Gmail search query (e.g.,
from:alice has:attachment newer_than:7d)Optional Gmail label IDs to filter by
ISO date string to filter messages after
ISO date string to filter messages before
Number of messages to return (1-50, default: 20)
list_messages
List message IDs (fast, metadata-only).Optional Gmail label IDs to filter by
Optional Gmail query string
Number of messages to return (1-50, default: 20)
Pagination token from previous call
Whether to include spam and trash (default: False)
get_message
Fetch a single Gmail message (metadata only).Gmail message ID
get_message_body
Fetch a single Gmail message body for display or summarization.Gmail message ID
“text” or “html” (default: “text”)
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