๐ง Agentic Mail MCP
A Model Context Protocol server that lets AI agents work with a Gmail account safely โ read, search, summarize, and (opt-in) forward/archive/label โ behind a layered safety model.
๐ You bring your own Google app. This is a local tool, not a hosted service โ you create your own OAuth client in your own Google Cloud project and authorize your own mailbox. Your credentials and token never leave your machine, and because the app only ever authorizes you, there's no central service and no Google verification to wait for.
โน๏ธ Status: pre-release (
0.1.0), fully functional locally. Not yet on PyPI โ install from source (below).
โจ Features
| ๐ฅ Email operations | Search, read, forward, archive, delete, draft, and label |
| ๐ง Intelligence | Caller-first prompts (summarize, classify, reply, action items) + optional server-side digests |
| ๐ Semantic search | Natural-language vector search over your mail |
| ๐ Notifications | Webhook / Redis event fan-out |
| ๐ก๏ธ Railguards | Read-only by default, allowlists, rate limits, archive-first delete, draft-first send, audit log |
๐ Quick start
You need Python 3.11+ and a Google account. Five minutes end to end.
flowchart LR
A[1. Install] --> B[2. Google<br/>credentials]
B --> C[3. Configure<br/>.env]
C --> D[4. Authorize<br/>agentic-mail-mcp auth]
D --> E[5. Connect agent<br/>or run HTTP]
1. Install (from source until published โ see Installation):
pip install "git+https://github.com/CoolDevGuys/agentic-mail-mcp.git"
2. Get Google credentials โ in your Google Cloud project, enable the Gmail
API, make a Desktop-app OAuth client, and download its credentials.json.
Full walkthrough with the exact clicks:
Getting your Google credentials ๐.
3. Configure โ copy .env.example to .env and point at your downloaded file:
# Easiest: just point at the credentials.json you downloaded.
AGENTIC_MAIL_MCP_GMAIL_CLIENT_SECRETS_FILE=/path/to/credentials.json
AGENTIC_MAIL_MCP_GMAIL_TOKEN_ENCRYPTION_KEY=<any long random string>
# ๐ Writes are denied by default. Keep read_only until you trust the setup.
AGENTIC_MAIL_MCP_RAILGUARDS_ACCESS_LEVEL=read_only
4. Authorize (one-time browser consent โ stores an encrypted token):
agentic-mail-mcp auth
5. Use it โ connect an AI agent over stdio or run the HTTP server. See Usage.
โ Requirements
- ๐ Python 3.11+
- ๐ Your own Google OAuth
credentials.json(a Desktop-app client from your Google Cloud project โ how to get it) - ๐ค (optional) an LLM API key for the digest tools (OpenAI-compatible by default)
๐ฆ Installation
From source (works today):
pip install "git+https://github.com/CoolDevGuys/agentic-mail-mcp.git"
# or, from a clone:
pip install .
Optional extras (combine as needed, e.g. ".[postgresql,search]"):
| Extra | Adds |
|---|---|
postgresql |
PostgreSQL + pgvector backends |
search |
local embeddings + sqlite-vec semantic search |
notifications |
Redis pub/sub notifications |
llm |
local llama.cpp inference |
dev |
test / lint / build tooling |
Docker: docker compose up --build (see HTTP server).
๐ก Once published to PyPI, the recommended install for MCP clients will be
uvx agentic-mail-mcp/pipx run agentic-mail-mcpโ no virtualenv to manage.
โ๏ธ Configuration
Set environment variables with the AGENTIC_MAIL_MCP_ prefix, or use a .env file
(copy .env.example). The table below covers the essentials; every setting,
with defaults and purpose โ and the Google OAuth walkthrough โ is in
specs/docs/configuration.md.
| Variable | Description | Default |
|---|---|---|
AGENTIC_MAIL_MCP_GMAIL_CLIENT_SECRETS_FILE |
Path to your downloaded credentials.json (recommended) |
(one of these two) |
AGENTIC_MAIL_MCP_GMAIL_OAUTH_CLIENT_ID / _SECRET |
โฆor the OAuth client id/secret directly | (one of these two) |
AGENTIC_MAIL_MCP_GMAIL_TOKEN_ENCRYPTION_KEY |
Secret used to encrypt the stored token | (required to store tokens) |
AGENTIC_MAIL_MCP_GMAIL_TOKEN_STORAGE_PATH |
Encrypted token file path (set outside the repo in prod) | token.json |
AGENTIC_MAIL_MCP_DATABASE_URL |
SQLAlchemy URL (synchronous driver) | sqlite:///./agentic_mail_mcp.db |
AGENTIC_MAIL_MCP_RAILGUARDS_ACCESS_LEVEL |
read_only or read_write โ writes denied by default |
read_only |
AGENTIC_MAIL_MCP_LLM_PROVIDER |
openai (HTTP) or llamacpp (local) |
openai |
AGENTIC_MAIL_MCP_LLM_API_KEY |
LLM API key | (required for intelligence) |
AGENTIC_MAIL_MCP_MCP_TRANSPORT |
stdio (default) or http |
stdio |
AGENTIC_MAIL_MCP_MCP_HOST / AGENTIC_MAIL_MCP_MCP_PORT |
HTTP transport bind address | 127.0.0.1 / 8080 |
๐ Usage
The server speaks MCP over two transports:
| Transport | Best for | How |
|---|---|---|
| stdio (default) | one user on a laptop (Claude Desktop, IDE agents) | agent launches the process |
| HTTP (streamable) | shared / containerized deployments | long-running server on a port |
โ ๏ธ Authorize first. Run
agentic-mail-mcp authonce (browser consent) before starting the server โ it stores the encrypted token the server reads on every start. Details: Authorize.Headless server (no browser)?
authneeds a browser + loopback redirect, so you don't run it on the server. Authorize once on a machine that has a browser, then copy the encrypted token file across โ see Headless / server deployment.
๐ป Local (stdio) โ connect an AI agent
Point your MCP client at the agentic-mail-mcp command. Example client config:
{
"mcpServers": {
"gmail": {
"command": "agentic-mail-mcp",
"env": {
"AGENTIC_MAIL_MCP_GMAIL_OAUTH_CLIENT_ID": "...",
"AGENTIC_MAIL_MCP_GMAIL_OAUTH_CLIENT_SECRET": "...",
"AGENTIC_MAIL_MCP_GMAIL_TOKEN_ENCRYPTION_KEY": "...",
"AGENTIC_MAIL_MCP_RAILGUARDS_ACCESS_LEVEL": "read_only"
}
}
}
}
The agent then discovers the tools, resources, and prompts described in the
MCP API reference. Start with read_only and enable
read_write deliberately once you understand the railguards.
HTTP server (deployment)
Run a standalone streamable-HTTP server:
AGENTIC_MAIL_MCP_MCP_TRANSPORT=http AGENTIC_MAIL_MCP_MCP_HOST=0.0.0.0 AGENTIC_MAIL_MCP_MCP_PORT=8080 \
agentic-mail-mcp
Or with Docker (the compose file already sets HTTP transport and a health check):
docker compose up --build # server on http://localhost:8080
๐ Auth on a headless host: authorize on your laptop and mount the encrypted token into the container (e.g.
-v /etc/agentic-mail-mcp:/secrets:ro) โ full steps under Headless / server deployment.
Point an HTTP-capable MCP client at http://<host>:8080. Keep the server behind
your own auth/TLS if it's reachable beyond localhost.
๐งฐ MCP Tools
Full input/output schemas, resources, prompts, and error formats are in the MCP API reference.
Read Tools (always available)
search_emailsโ Search emails by subject, sender, recipient, date range, labels, attachments, unread statusget_emailโ Read a specific email by IDget_threadโ Read a conversation threadlist_unreadโ List unread emailslist_labelsโ List labels (system, user, or all)
Write Tools (require read_write access)
forward_emailโ Forward an email (recipient allowlist enforced)archive_emailโ Archive an email or threaddelete_emailโ Delete an email (trash by default, archive-first policy)create_draftโ Create a draft for reviewsend_draftโ Send a reviewed draftadd_labelโ Add a label to an email
Intelligence โ caller-first ๐ง
The calling agent is itself an LLM, so per-email reasoning ships as MCP prompts
the agent runs on data it fetches with get_email โ no server-side inference,
no added latency, no LLM key required:
- prompts:
summarize_emailยทclassify_emailยทdraft_replyยทextract_action_items
Internal LLM inference is reserved for where it pays off (map-reduce over many emails), and registers only when an LLM is configured:
- tools:
daily_digestยทweekly_digest - (opt-in) set
AGENTIC_MAIL_MCP_LLM_INTERNAL_TOOLS=trueto also expose the per-email ones as server-side tools. See ADR 0006.
Search Tools
semantic_searchโ natural-language vector search (needs thesearchextra)
Project Structure
agentic_mail_mcp/
Bootstrap/ CLI, Settings, Logging, Lifespan, DI Container
Common/ Shared domain primitives
Gmail/ Gmail bounded context
Intelligence/ LLM-powered email analysis
Search/ Semantic/vector search
Notification/ Event notifications
MCP/ MCP server, tools, resources, prompts
tests/
unit/ Unit tests
integration/ Integration tests
fakes/ Test doubles
Railguards (security model)
Writes are denied by default. Safety is layered so an AI agent cannot mutate a mailbox unless a human deliberately enables it:
- Access level โ
read_only(default) orread_write. The master switch. Underread_only, write tools are not even registered with the MCP server (defense in depth), so the agent never sees them โ not merely blocked at call time. - Recipient allowlist โ forwarding is restricted to configured addresses or
domains (
@example.com). - Rate limits โ per-action caps within a trailing 1-hour window
(e.g.
{"forward": 50}). - Archive-first policy โ an email must be archived before it can be permanently deleted; deletes are soft (Trash) by default.
- Draft-first sending โ the agent creates a draft for human review;
send_draftis a separate, explicit step. - Audit log โ every write is recorded (action, email id, correlation id).
A railguard denial surfaces to the agent as a structured permission_denied
error, never as an unhandled exception. See the
railguards configuration and
ADR 0004.
Development
A Makefile wraps the common tasks (run make to list them):
make setup # first-time: create .venv, install dev deps, .env, run migrations
make auth # one-time Google authorization (browser consent)
make run # start the server (stdio); make run-http for HTTP transport
make test # full test suite with coverage gates (as CI runs)
make check # lint (ruff) + type-check (mypy) + tests
make format # auto-format and fix imports
make migrate # apply DB migrations; make migration m="..." to autogenerate
make build # build the sdist + wheel and validate metadata
Prefer raw tools? They work too: pytest, ruff check agentic_mail_mcp tests, mypy agentic_mail_mcp,
alembic upgrade head. All make targets run inside a local .venv.
Contributing
- The architecture (DDD + vertical slicing) and key decisions are recorded as ADRs; read them before adding a bounded context or changing a boundary.
- Changes follow the OpenSpec workflow under
openspec/โ propose a change, generate its spec deltas, implement, then archive. - Keep the tiered coverage floors green (โฅ90% on
Domain/, โฅ80% overall) and ensureruff checkandmypy agentic_mail_mcp/pass before opening a PR.
๐ค Distribution
The recommended distribution is a PyPI package launched via uvx / pipx,
not a compiled binary. MCP clients already know how to run
command: "uvx" / "pipx run", so users get a one-line config with no
virtualenv to manage, and Python-native OAuth/optional-dependency handling stays
simple. A single-file binary would fight the OAuth browser flow and the optional
native extras (llama.cpp, sentence-transformers, sqlite-vec) for little gain. The
Docker image covers HTTP/server deployments.
Releasing (maintainers)
Releases are fully automated by the publish job in
.github/workflows/ci.yml. Publishing a GitHub
Release is the entire flow โ it builds the sdist + wheel and uploads them to
PyPI via Trusted Publishing (OIDC), so no API token is stored in the repo.
One-time PyPI setup (per project, done once in the PyPI web UI):
- On PyPI โ Publishing โ add a
pending trusted publisher with:
- PyPI Project Name:
agentic-mail-mcp - Owner: your GitHub org/user ยท Repository: this repo
- Workflow name:
ci.ymlยท Environment name:pypi
- PyPI Project Name:
- In GitHub โ Settings โ Environments โ create an environment named
pypi(optionally add required reviewers to gate publishes).
To cut a release:
- Bump
project.versioninpyproject.toml, move theCHANGELOG.md[Unreleased]section under the new version, and merge tomain. - On GitHub โ Releases โ Draft a new release โ create a tag (e.g.
v0.1.0) โ Publish release. - CI runs lint / type-check / tests / audit, then the
publishjob builds and uploads to PyPI. Done โuvx agentic-mail-mcpnow resolves the new version.
License
Released under the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentic_mail_mcp-0.1.0.tar.gz.
File metadata
- Download URL: agentic_mail_mcp-0.1.0.tar.gz
- Upload date:
- Size: 104.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
128f307a5775416f9c549486128ddbae0f783c94378990fe8dbdefd6e7091089
|
|
| MD5 |
deda31d829ff07f8c1d566fe43930177
|
|
| BLAKE2b-256 |
1c5e38b0462a79a38276093e1421fb92f9faabf56e2bf5af173fd5536ab0d466
|
Provenance
The following attestation bundles were made for agentic_mail_mcp-0.1.0.tar.gz:
Publisher:
ci.yml on CoolDevGuys/agentic-mail-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentic_mail_mcp-0.1.0.tar.gz -
Subject digest:
128f307a5775416f9c549486128ddbae0f783c94378990fe8dbdefd6e7091089 - Sigstore transparency entry: 2360593103
- Sigstore integration time:
-
Permalink:
CoolDevGuys/agentic-mail-mcp@b2128c67636dbddfe753d9fe0655255a6d7bd78d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/CoolDevGuys
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@b2128c67636dbddfe753d9fe0655255a6d7bd78d -
Trigger Event:
release
-
Statement type:
File details
Details for the file agentic_mail_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentic_mail_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 130.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f60786cd28d76a5975735252318896d70ffa9a8bcdcb34cc9922e391570b978
|
|
| MD5 |
1d3f1762a8ce1406996428ac19f6f1aa
|
|
| BLAKE2b-256 |
2229e82b230f5afd26fb6d6c489f2c17b1888d55fd724834b0b8ef995808c3cd
|
Provenance
The following attestation bundles were made for agentic_mail_mcp-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on CoolDevGuys/agentic-mail-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentic_mail_mcp-0.1.0-py3-none-any.whl -
Subject digest:
7f60786cd28d76a5975735252318896d70ffa9a8bcdcb34cc9922e391570b978 - Sigstore transparency entry: 2360593181
- Sigstore integration time:
-
Permalink:
CoolDevGuys/agentic-mail-mcp@b2128c67636dbddfe753d9fe0655255a6d7bd78d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/CoolDevGuys
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@b2128c67636dbddfe753d9fe0655255a6d7bd78d -
Trigger Event:
release
-
Statement type: