Skip to content

InitialForce/mcp_agent_mail_rust

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,188 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCP Agent Mail (Rust)

MCP Agent Mail - A mail-like coordination layer for AI coding agents

CI License: MIT+Rider

"It's like Gmail for your coding agents!"

A mail-like coordination layer for AI coding agents, exposed as an MCP server with 34 tools and 20+ resources, Git-backed archive, SQLite indexing, and an interactive 15-screen TUI operations console. The Rust rewrite of the original Python project (1,700+ stars).

Supported agents: Claude Code, Codex CLI, Gemini CLI, GitHub Copilot CLI, and any MCP-compatible client.

Watch the 23-minute walkthrough to see seven AI coding agents send over 1,000 messages to each other while implementing a development plan over two days.

Quick Install

curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/mcp_agent_mail_rust/main/install.sh?$(date +%s)" | bash

Works on Linux and macOS (x86_64 and aarch64). Auto-detects your platform and downloads the right binary.


Table of Contents


TL;DR

The Problem: Modern projects often run multiple coding agents at once (backend, frontend, scripts, infra). Without a shared coordination fabric, agents overwrite each other's edits, miss critical context from parallel workstreams, and require humans to relay messages across tools and teams.

The Solution: Agent Mail gives every coding agent a persistent identity (e.g., GreenCastle), an inbox/outbox, searchable threaded conversations, and advisory file reservations (leases) to signal editing intent. Everything is backed by Git for human-auditable artifacts and SQLite for fast indexing and search.

Why Use Agent Mail?

Feature What It Does
Advisory File Reservations Agents declare exclusive or shared leases on file globs before editing, preventing conflicts with a pre-commit guard
Asynchronous Messaging Threaded inbox/outbox with subjects, CC/BCC, acknowledgments, and importance levels
Token-Efficient Messages stored in a per-project archive, not in agent context windows
34 MCP Tools Infrastructure, identity, messaging, contacts, reservations, search, macros, product bus, and build slots
11-Screen TUI Real-time dashboard, message browser, thread view, agent roster, search, reservations, metrics, health, timeline, projects, and contacts
Robot Mode 16 agent-optimized CLI subcommands with toon/json/md output for non-interactive workflows
Git-Backed Archive Every message, reservation, and agent profile stored as files in per-project Git repos
Hybrid Search Search V3 via frankensearch with lexical, semantic, and hybrid routing
Pre-Commit Guard Git hook that blocks commits touching files reserved by other agents
Dual-Mode Interface MCP server (mcp-agent-mail) and operator CLI (am) share tools but enforce strict surface separation

Quick Example

# Install and start (auto-detects all installed coding agents)
am

# That's it. Server starts on 127.0.0.1:8765 with the interactive TUI.

# Agents coordinate through MCP tools:
#   ensure_project(project_key="/abs/path")
#   register_agent(project_key, program="claude-code", model="opus-4.6")
#   file_reservation_paths(project_key, agent_name, ["src/**"], ttl_seconds=3600, exclusive=true)
#   send_message(project_key, from_agent, to_agent, subject="Starting refactor", thread_id="FEAT-123")
#   fetch_inbox(project_key, agent_name)

# Or use the robot CLI for non-interactive agent workflows:
am robot status --project /abs/path --agent BlueLake
am robot inbox --project /abs/path --agent BlueLake --urgent --format json
am robot reservations --project /abs/path --agent BlueLake --conflicts

What Agent Conversations Look Like

Example exchange between two agents coordinating a refactor:

┌──────────────────────────────────────────────────────────────────────────────┐
│ Thread: FEAT-123 - Auth module refactor                                      │
├──────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│ ┌──────────────────────────────────────────────────────────────────────────┐ │
│ │ GreenCastle -> BlueLake                                 2026-02-16 10:03 │ │
│ │ Subject: Starting auth refactor                                          │ │
│ ├──────────────────────────────────────────────────────────────────────────┤ │
│ │ I'm reserving src/auth/** for the next hour. Can you focus on the API    │ │
│ │ tests in tests/api/** instead?                                           │ │
│ │ [ack_required: true]                                                     │ │
│ └──────────────────────────────────────────────────────────────────────────┘ │
│                                                                              │
│ ┌──────────────────────────────────────────────────────────────────────────┐ │
│ │ BlueLake -> GreenCastle                                 2026-02-16 10:04 │ │
│ │ Subject: Re: Starting auth refactor                                      │ │
│ ├──────────────────────────────────────────────────────────────────────────┤ │
│ │ Confirmed. Releasing my reservation on src/auth/** and taking            │ │
│ │ tests/api/** exclusively. Will sync when I hit the auth middleware       │ │
│ │ boundary.                                                                │ │
│ │ [ack: OK]                                                                │ │
│ └──────────────────────────────────────────────────────────────────────────┘ │
│                                                                              │
│ ┌──────────────────────────────────────────────────────────────────────────┐ │
│ │ BlueLake -> GreenCastle                                 2026-02-16 10:31 │ │
│ │ Subject: Re: Starting auth refactor                                      │ │
│ ├──────────────────────────────────────────────────────────────────────────┤ │
│ │ Found a broken assertion in tests/api/auth_test.rs:142 -- the expected   │ │
│ │ token format changed. Heads up if you're touching the JWT issuer.        │ │
│ └──────────────────────────────────────────────────────────────────────────┘ │
│                                                                              │
│ ┌──────────────────────────────────────────────────────────────────────────┐ │
│ │ GreenCastle -> BlueLake                                 2026-02-16 10:33 │ │
│ │ Subject: Re: Starting auth refactor                                      │ │
│ ├──────────────────────────────────────────────────────────────────────────┤ │
│ │ Good catch. I just changed the claims struct. Updated the test fixture   │ │
│ │ in my commit. Releasing src/auth/** now -- all yours if you need it.     │ │
│ └──────────────────────────────────────────────────────────────────────────┘ │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

No human relay needed. Agents negotiate file ownership, flag breaking changes in real time, and hand off work through structured, threaded messages stored in Git.


Why This Exists

Modern projects often run multiple coding agents at once (backend, frontend, scripts, infra). Without a shared coordination fabric, agents overwrite each other's edits, miss critical context from parallel workstreams, and require humans to relay messages across tools and teams.

Agent Mail was the first open-source agent coordination system that works across providers (Claude Code, Codex CLI, Gemini CLI, etc.), available since October 2025. You're going to hear about a lot of agent communication systems because it's such an obviously good idea, but Agent Mail sidesteps all the footguns that a naive implementation falls prey to. Combined with Beads and bv, it unlocks truly insane productivity gains.

The Footguns Agent Mail Avoids

No "broadcast to all" mode. Agents are lazy and will default to broadcasting everything to everyone if you let them. That's like your email system at work defaulting to reply-all every time; it spams every agent with mostly irrelevant information and burns precious context.

Obsessively refined API ergonomics. Bad MCP documentation and poor agent ergonomics are the silent killers. It takes a huge amount of careful iteration, observation, and refinement to get the balance so tools just work reliably without wasting tokens. Agent Mail's 34 tool definitions have been through hundreds of rounds of real-world tuning.

No git worktrees. Worktrees demolish development velocity and create debt you need to pay later when the agents diverge. Working in one shared space surfaces conflicts immediately so you can deal with them, which is easy when agents can communicate. Instead of isolating agents, Agent Mail coordinates them.

Advisory file reservations instead of hard locks. There's a much better way to prevent conflicts than worktrees: agents call dibs temporarily on files while they're working on them, but it's not rigorously enforced, and reservations expire. Agents can observe if reserved files haven't been touched recently and reclaim them. You want a system that's robust to agents suddenly dying or getting their memory wiped, because that happens all the time. Hard locks would deadlock.

Semi-persistent identity. An identity that can last for the duration of a discrete task (for the purpose of coordination), but one that can also vanish without a trace and not break things. You don't want ringleader agents whose death takes down the whole system. Agent Mail identities are memorable (e.g., GreenCastle), but ephemeral by design.

Graph-aware task selection. If you have 200-500 tasks, you don't want agents randomly choosing them or wasting context communicating about what to do. There's usually a "right answer" for what each agent should work on, and that right answer comes from the dependency structure of the tasks. That's what bv computes using graph theory, like a compass that tells each agent which direction will unlock the most work overall.

What Agent Mail Gives You

  • Prevents conflicts: Explicit file reservations (leases) for files/globs prevent agents from overwriting each other
  • Eliminates human liaisons: Agents send messages directly to each other with threaded conversations, acknowledgments, and priority levels
  • Keeps communication off the token budget: Messages stored in per-project Git archive, not consuming agent context windows
  • Offers quick reads: resource://inbox/{Agent}, resource://thread/{id}, and 20+ other MCP resources
  • Provides full audit trails: Every instruction, lease, message, and attachment is in Git for human review
  • Scales across repos: Frontend and backend agents in different repos coordinate through the product bus and contact system

Typical Use Cases

  • Multiple agents splitting a large refactor across services while staying in sync
  • Frontend and backend agent teams coordinating thread-by-thread across repositories
  • Protecting critical migrations with exclusive file reservations and pre-commit guards
  • Searching and summarizing long technical discussions as threads evolve
  • Running agent swarms with Beads task tracking for dependency-aware work selection

Productivity Math

One disciplined hour of AI coding agents often produces 10-20 "human hours" of work because the agents reason and type at machine speed. Agent Mail multiplies that: you invest 1-2 hours of human supervision, but dozens of agent-hours execute in parallel with clear audit trails and conflict-avoidance baked in. A single developer running Agent Mail + Beads + bv can ship what would normally take a team of engineers weeks.


What People Are Saying

"Agent Mail and Beads feel like the first 'agent-native' tooling." — @jefftangx

"Agent mail is a truly brain-melting experience the first time. Thanks for building it." — @quastora

"Between Claude Code, Codex CLI, and Gemini; Beads; and Agent Mail — basically already 80% the way to the autonomous corporation. It blows my mind this all works now!" — @curious_vii

"Use it with agent mail == holy grail." — @metapog

"The only correct answer to this is mcp agent mail." — @skillcreatorai

"GPT 5.2 suggesting beads + agent mail for agent co-ordination (of course, I am already using them)." — @jjpcodes


Design Philosophy

Mail metaphor, not chat. Agents send discrete messages with subjects, recipients, and thread IDs. Work coordination is structured communication with clear intent, not a firehose. Imagine if your email system at work defaulted to reply-all every time; that's what chat-based coordination does, and it burns context fast.

Git as the source of truth. Every message, agent profile, and reservation artifact lives as a file in a per-project Git repository. The entire communication history is human-auditable, diffable, and recoverable. SQLite is the fast index, not the authority.

Advisory, not mandatory. File reservations are advisory leases, not hard locks. The pre-commit guard enforces them at commit time, but agents can always override if needed. Deadlocks become impossible while accidental conflicts still get caught. Reservations expire on a TTL, so crashed agents don't hold files hostage forever.

Resilient to agent death. Agents die all the time: context windows overflow, sessions crash, memory gets wiped. Any agent can vanish without breaking the system. No ringleader agents, no single points of failure. Semi-persistent identities exist for coordination but don't create hard dependencies.

Dual persistence. Human-readable Markdown in Git for auditability; SQLite for indexing plus Search V3 for fast lexical/semantic retrieval. Both stay in sync through the write pipeline.

Structured concurrency, no Tokio. The entire async stack uses asupersync with Cx-threaded structured concurrency. No orphan tasks, cancel-correct channels, and deterministic testing with virtual time.


Rust vs. Python: Stress Test Results

The Python implementation had three recurring failure modes under real multi-agent workloads: Git lock file contention from concurrent writes, SQLite pool exhaustion under sustained load, and cascading failures when many agents hit the server simultaneously. The Rust rewrite was designed specifically to eliminate these, and a dedicated stress test suite proves it.

The 10-Test Gauntlet

Test Result Key Metrics
30-agent message pipeline PASS 150/150 success, p99=6.8s, 0 errors
10-project concurrent ops PASS 150/150 success, 0 errors
Commit coalescer batching PASS 9.1x batching ratio (100 writes → 11 commits)
Stale git lock recovery PASS Lock detected, cleaned, writes resumed
Mixed reservations + messages PASS 80+80 ops, 0 errors
WBQ saturation PASS 2000/2000 enqueued, 0 errors, 0 fallbacks
Pool exhaustion (60 threads, pool=15) PASS 600/600 success, 0 timeouts, 24 ops/sec
Sustained 30s mixed workload PASS 1494 ops, ~49 RPS, p99=2.6s, 0 errors
Thundering herd (50 threads, 1 agent) PASS All 50 got same ID, 0 errors
Inbox reads during message storm PASS 150 sends + 300 reads, 0 errors

Python Problem → Rust Fix

Python Failure Mode What the Rust Tests Exercise Result
Git lock file contention Commit coalescer batching (100 concurrent writes → 11 commits, 9.1x reduction), stale lock recovery, multi-project isolation 0 lock errors
SQLite pool exhaustion 60 threads on pool of 15, sustained 50 RPS for 30s, thundering herd (50 threads → 1 agent) 0 timeouts, 0 DB errors
Overloading with many agents 30 agents × 5 messages, 10 projects × 5 agents, 2000 WBQ operations, mixed reservation+message workload 0 errors across all

What Makes the Difference

  • Git lock contention eliminated. The commit coalescer batches rapid-fire writes into far fewer git commits (9.1x reduction observed). Lock-free git plumbing commits avoid index.lock entirely in most cases.
  • Pool exhaustion handled gracefully. Even with 4x more threads than pool connections (60 vs 15), all 600 operations succeeded with 0 timeouts. WAL mode + 60s busy_timeout lets writers queue rather than fail.
  • Stale lock recovery works. Crashed-process lock files are detected via PID checking and cleaned up automatically, so a dead agent never holds the archive hostage.
  • Write-behind queue backpressure is clean. 2000 rapid-fire enqueues from 20 threads — all accepted with 0 fallbacks or errors.
  • Read/write concurrency is solid. Concurrent inbox reads and message writes produce 0 errors. WAL mode allows unlimited readers alongside writers.

The stress tests live in crates/mcp-agent-mail-storage/tests/stress_pipeline.rs (Rust unit tests targeting the DB+Git pipeline) and tests/e2e/test_stress_load.sh (HTTP E2E tests hammering a live server through the full network→server→DB→git pipeline).


Installation

One-Liner (recommended)

curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/mcp_agent_mail_rust/main/install.sh?$(date +%s)" | bash

Downloads the right binary for your platform, installs to ~/.local/bin, and optionally updates your PATH. Supports --verify for checksum + Sigstore cosign verification.

Options: --version vX.Y.Z, --dest DIR, --system (installs to /usr/local/bin), --from-source, --verify, --easy-mode (auto-update PATH), --force, --uninstall, --yes, --purge.

Windows One-Liner (PowerShell)

iwr -useb "https://raw.githubusercontent.com/Dicklesworthstone/mcp_agent_mail_rust/main/install.ps1?$(Get-Random)" | iex

PowerShell options: -Version vX.Y.Z, -Dest PATH, -Force.

From Source

git clone https://github.com/Dicklesworthstone/mcp_agent_mail_rust
cd mcp_agent_mail_rust
cargo build --release
# Binaries at target/release/mcp-agent-mail and target/release/am

Requires Rust nightly (see rust-toolchain.toml). Also requires sibling workspace crates: fastmcp_rust, sqlmodel_rust, asupersync, frankentui, beads_rust, frankensearch, toon_rust.

Platforms

Platform Architecture Binary
Linux x86_64 mcp-agent-mail-x86_64-unknown-linux-gnu
Linux aarch64 mcp-agent-mail-aarch64-unknown-linux-gnu
macOS x86_64 mcp-agent-mail-x86_64-apple-darwin
macOS Apple Silicon mcp-agent-mail-aarch64-apple-darwin
Windows x86_64 mcp-agent-mail-x86_64-pc-windows-msvc.zip

Quick Start

1. Start the server

am

Auto-detects all installed coding agents (Claude Code, Codex CLI, Gemini CLI, etc.), configures their MCP connections, and starts the HTTP server on 127.0.0.1:8765 with the interactive TUI.

2. Agents register and coordinate

Once the server is running, agents use MCP tools to coordinate:

# Register identity
ensure_project(project_key="/abs/path/to/repo")
register_agent(project_key, program="claude-code", model="opus-4.6")

# Reserve files before editing
file_reservation_paths(project_key, agent_name, ["src/**"], ttl_seconds=3600, exclusive=true)

# Send a message
send_message(project_key, from_agent="GreenCastle", to_agent="BlueLake",
             subject="Starting auth refactor", thread_id="FEAT-123", ack_required=true)

# Check inbox
fetch_inbox(project_key, agent_name)
acknowledge_message(project_key, agent_name, message_id)

3. Use macros for common flows

# Boot a full session (register + discover inbox + check reservations)
macro_start_session(project_key, program, model)

# Prepare for a thread (fetch context + recent messages)
macro_prepare_thread(project_key, agent_name, thread_id)

# Reserve, work, release cycle
macro_file_reservation_cycle(project_key, agent_name, paths, ttl_seconds)

# Contact handshake between agents in different projects
macro_contact_handshake(from_project, from_agent, to_project, to_agent)

Agent Configuration

The am command auto-detects installed agents, but you can also configure them manually.

Claude Code

Add to your project's .mcp.json or ~/.claude/settings.json:

{
  "mcpServers": {
    "agent-mail": {
      "command": "mcp-agent-mail",
      "args": []
    }
  }
}

Or for HTTP transport (when the server is already running):

{
  "mcpServers": {
    "agent-mail": {
      "type": "url",
      "url": "http://127.0.0.1:8765/mcp/"
    }
  }
}

Codex CLI

Add to .codex/config.json:

{
  "mcpServers": {
    "agent-mail": {
      "command": "mcp-agent-mail",
      "args": []
    }
  }
}

Gemini CLI

Add to ~/.gemini/settings.json:

{
  "mcpServers": {
    "agent-mail": {
      "command": "mcp-agent-mail",
      "args": []
    }
  }
}

Any MCP-Compatible Client

Agent Mail supports both stdio and HTTP transports:

  • stdio: Run mcp-agent-mail as a subprocess (the default for most MCP clients)
  • HTTP: Connect to http://127.0.0.1:8765/mcp/ when the server is running via am or mcp-agent-mail serve

Server Modes

MCP Server (default)

mcp-agent-mail                          # stdio transport (for MCP client integration)
mcp-agent-mail serve                    # HTTP server with TUI (default 127.0.0.1:8765)
mcp-agent-mail serve --no-tui           # Headless server (CI/daemon mode)
mcp-agent-mail serve --reuse-running    # Reuse existing server on same port

CLI Operator Tool

am                                      # Auto-detect agents, configure MCP, start server + TUI
am serve-http --port 9000               # Different port
am serve-http --host 0.0.0.0            # Bind to all interfaces
am serve-http --no-auth                 # Skip authentication (local dev)
am serve-http --path api                # Use /api/ transport instead of /mcp/
am --help                               # Full operator CLI

Dual-Mode Interface

This project keeps MCP server and CLI command surfaces separate:

Use case Entry point Notes
MCP server (default) mcp-agent-mail Default: MCP stdio transport. HTTP: serve.
CLI (operator + agent-first) am Recommended CLI entry point.
CLI via single binary AM_INTERFACE_MODE=cli mcp-agent-mail Same CLI surface, one binary.

Running CLI-only commands via the MCP binary produces a deterministic denial on stderr with exit code 2, and vice versa, preventing accidental mode confusion in automated workflows.


The 34 MCP Tools

9 Clusters

Cluster Count Tools
Infrastructure 4 health_check, ensure_project, ensure_product, products_link
Identity 3 register_agent, create_agent_identity, whois
Messaging 5 send_message, reply_message, fetch_inbox, acknowledge_message, mark_message_read
Contacts 4 request_contact, respond_contact, list_contacts, set_contact_policy
File Reservations 4 file_reservation_paths, renew_file_reservations, release_file_reservations, force_release_file_reservation
Search 2 search_messages, summarize_thread
Macros 4 macro_start_session, macro_prepare_thread, macro_contact_handshake, macro_file_reservation_cycle
Product Bus 5 ensure_product, products_link, search_messages_product, fetch_inbox_product, summarize_thread_product
Build Slots 3 acquire_build_slot, renew_build_slot, release_build_slot

20+ MCP Resources

Read-only resources for fast lookups without tool calls:

resource://inbox/{Agent}?project=<abs-path>&limit=20
resource://thread/{id}?project=<abs-path>&include_bodies=true
resource://agents?project=<abs-path>
resource://reservations?project=<abs-path>
resource://metrics
resource://health

Macros vs. Granular Tools

  • Prefer macros when you want speed or are on a smaller model: macro_start_session, macro_prepare_thread, macro_file_reservation_cycle, macro_contact_handshake
  • Use granular tools when you need control: register_agent, file_reservation_paths, send_message, fetch_inbox, acknowledge_message

TUI Operations Console

The interactive TUI has 15 screens. Jump directly with 1-9, 0 (screen 10), and shifted digits !, @, #, $, % (screens 11-15). Use Tab/Shift+Tab to cycle in order.

# Screen Shows
1 Dashboard Real-time operational overview with event stream and anomaly rail
2 Messages Message browser with detail pane, presets, and compose/reply flows
3 Threads Thread explorer and conversation drill-down
4 Agents Agent roster with activity, state, and quick actions
5 Search Unified multi-scope search with facets and preview
6 Reservations File reservation status, conflicts, and create/release actions
7 Tool Metrics Per-tool call counts, latency distributions, and failures
8 System Health Probe/circuit/disk/memory diagnostics
9 Timeline Events/Commits/Combined timeline views with inspector
10 Projects Project inventory and routing helpers
11 Contacts Contact links, policy view, and graph/mermaid modes
12 Explorer Unified inbox/outbox explorer with direction and ack filters
13 Analytics Anomaly insight feed with confidence and deep links
14 Attachments Attachment inventory with preview and provenance
15 Archive Browser Two-pane Git archive browser with tree + file preview

Global keys: ? help, Ctrl+P/: command palette, / global search focus, . contextual action menu, Ctrl+N compose overlay, Ctrl+Y toast-focus mode, Ctrl+T/Shift+T cycle theme, m toggle MCP/API transport, q quit.

Screen-specific highlights: Messages uses g for Local/Global inbox; Threads uses e/c for expand/collapse-all in conversation view; Timeline uses V for Events/Commits/Combined and v for visual selection; Search uses f + facet rail navigation for scope/sort/field controls; Contacts uses n for Table/Graph mode; batch-capable screens share Space/v/A/C; preset-enabled screens use Ctrl+S/Ctrl+L.

Command palette: Press Ctrl+P (or : outside text-entry) to open a searchable action launcher that includes screen navigation, transport/layout controls, and dynamic entities (agents/projects/threads/tools/reservations).

Themes: Cyberpunk Aurora, Darcula, Lumen Light, Nordic Frost, High Contrast. Accessibility support includes high-contrast mode and reduced motion. Archive Browser note: use Enter to expand/preview, Tab to switch tree vs preview pane, / to filter filenames, and Ctrl+D/U for preview paging.


Robot Mode (am robot)

Non-interactive, agent-first CLI surface for TUI-equivalent situational awareness. Use it when you need structured snapshots quickly, especially in automated loops and when tokens matter.

16 Subcommands

Command Purpose Key flags
am robot status Dashboard synthesis --format, --project, --agent
am robot inbox Actionable inbox with urgency/ack synthesis --urgent, --ack-overdue, --unread, --all, --limit, --include-bodies
am robot timeline Event stream since last check --since, --kind, --source
am robot overview Cross-project summary --format, --project, --agent
am robot thread <id> Full thread rendering --limit, --since, --format
am robot search <query> Full-text search with facets/relevance --kind, --importance, --since, --format
am robot message <id> Single-message deep view --format, --project, --agent
am robot navigate <resource://...> Resolve resources into robot-formatted output --format, --project, --agent
am robot reservations Reservation view with conflict/expiry awareness --all, --conflicts, --expiring, --agent
am robot metrics Tool call rates, failures, latency percentiles --format, --project, --agent
am robot health Runtime/system diagnostics --format, --project, --agent
am robot analytics Anomaly and remediation summary --format, --project, --agent
am robot agents Agent roster and activity overview --active, --sort
am robot contacts Contact graph and policy surface --format, --project, --agent
am robot projects Per-project aggregate stats --format, --project, --agent
am robot attachments Attachment inventory and provenance --format, --project, --agent

Output Formats

  • toon (default at TTY): Token-efficient, compact, optimized for agent parsing
  • json (default when piped): Machine-readable envelope with _meta, _alerts, _actions
  • md (thread/message-focused): Human-readable narrative for deep context

Agent Workflow Recipes

# Startup triage
am robot status --project /abs/path --agent AgentName

# Immediate urgency pass
am robot inbox --project /abs/path --agent AgentName --urgent --format json

# Incremental monitoring loop
am robot timeline --project /abs/path --agent AgentName --since 2026-02-16T10:00:00Z

# Deep thread drill-down
am robot thread br-123 --project /abs/path --agent AgentName --format md

# Reservation safety check before edits
am robot reservations --project /abs/path --agent AgentName --conflicts --expiring 30

File Reservations for Multi-Agent Editing

Before editing, agents reserve file paths to avoid conflicts:

file_reservation_paths(project_key, agent_name, ["src/**"], ttl_seconds=3600, exclusive=true)

The pre-commit guard (mcp-agent-mail-guard) installs as a Git hook and blocks commits that touch files reserved by other agents. Reservations are advisory, TTL-based, and support glob patterns.

Area Reserve glob
Core types/config crates/mcp-agent-mail-core/src/**
SQLite layer crates/mcp-agent-mail-db/src/**
Git archive crates/mcp-agent-mail-storage/src/**
Tool implementations crates/mcp-agent-mail-tools/src/**
TUI crates/mcp-agent-mail-server/src/tui_*.rs
CLI/launcher crates/mcp-agent-mail-cli/src/**

Multi-Agent Coordination Workflows

How Agents Interact (Protocol Flow)

sequenceDiagram
    participant A as Agent A (GreenCastle)
    participant S as Agent Mail Server
    participant B as Agent B (BlueLake)

    A->>S: ensure_project("/abs/path")
    A->>S: register_agent(program="claude-code")
    S-->>A: identity: GreenCastle

    B->>S: register_agent(program="codex-cli")
    S-->>B: identity: BlueLake

    A->>S: file_reservation_paths(["src/auth/**"], exclusive=true)
    S-->>A: reserved ✓

    B->>S: file_reservation_paths(["src/auth/**"], exclusive=true)
    S-->>B: CONFLICT — reserved by GreenCastle

    B->>S: file_reservation_paths(["tests/api/**"], exclusive=true)
    S-->>B: reserved ✓

    A->>S: send_message(to=BlueLake, thread="FEAT-123", ack_required=true)
    S-->>B: new message in inbox

    B->>S: fetch_inbox()
    S-->>B: [message from GreenCastle]

    B->>S: acknowledge_message(message_id)
    S-->>A: ack received ✓

    A->>S: release_file_reservations(["src/auth/**"])
    S-->>A: released ✓
Loading

Same Repository

  1. Register identity: ensure_project + register_agent using the repo's absolute path as project_key
  2. Reserve files before editing: file_reservation_paths(project_key, agent_name, ["src/**"], ttl_seconds=3600, exclusive=true)
  3. Communicate with threads: send_message(..., thread_id="FEAT-123"), check with fetch_inbox, acknowledge with acknowledge_message
  4. Quick reads: resource://inbox/{Agent}?project=<abs-path>&limit=20

Across Different Repos

  • Option A (single project bus): Register both repos under the same project_key. Keep reservation patterns specific (frontend/** vs backend/**).
  • Option B (separate projects): Each repo has its own project_key. Use macro_contact_handshake to link agents, then message directly. Keep a shared thread_id across repos.

With Beads Task Tracking

Agent Mail pairs with Beads (br) for dependency-aware task selection:

  1. Pick ready work: br ready --json (choose highest priority, no blockers)
  2. Reserve edit surface: file_reservation_paths(..., reason="br-123")
  3. Announce start: send_message(..., thread_id="br-123", subject="[br-123] Start: <title>", ack_required=true)
  4. Work and update: Reply in-thread with progress
  5. Complete and release: br close 123, release_file_reservations(...), final Mail reply

Use the Beads issue ID (br-123) as the Mail thread_id and prefix message subjects with [br-123] to keep everything linked.


Browser State Sync Endpoint

For browser/WASM clients, Agent Mail exposes a polling-based state sync contract:

  • GET /mail/ws-state returns a snapshot payload
  • GET /mail/ws-state?since=<seq>&limit=<n> returns deltas since a sequence
  • POST /mail/ws-input accepts remote terminal ingress events (Input, Resize)

Note: /mail/ws-state is intentionally HTTP polling, not WebSocket upgrade. WebSocket upgrade attempts return 501 Not Implemented.

# Snapshot
curl -sS 'http://127.0.0.1:8765/mail/ws-state?limit=50' | jq .

# Delta from a known sequence
curl -sS 'http://127.0.0.1:8765/mail/ws-state?since=1200&limit=200' | jq .

# Input ingress (key event)
curl -sS -X POST 'http://127.0.0.1:8765/mail/ws-input' \
  -H 'Content-Type: application/json' \
  --data '{"type":"Input","data":{"kind":"Key","key":"j","modifiers":0}}' | jq .

Web UI

The server includes a lightweight, server-rendered web UI for humans at /mail/. Agents should continue using MCP tools and resources; the web UI is for human review and oversight.

Routes

Route What You See
/mail/ Unified inbox across all projects, project list, related project suggestions
/mail/{project} Project overview with search, agent roster, quick links to reservations and attachments
/mail/{project}/inbox/{agent} Reverse-chronological inbox for one agent with pagination
/mail/{project}/message/{id} Full message detail with metadata, thread context, and attachments
/mail/{project}/search?q=... Search V3-powered query route with field filters (subject:foo, body:"multi word")
/mail/{project}/file_reservations Active and historical file reservations
/mail/{project}/attachments Messages with attachments

Auth: set HTTP_BEARER_TOKEN for production. For local dev, set HTTP_ALLOW_LOCALHOST_UNAUTHENTICATED=true to browse without headers.

Human Overseer

Sometimes you need to redirect agents mid-session. The Overseer compose form at /mail/{project}/overseer/compose lets humans send high-priority messages directly to any combination of agents.

Overseer messages:

  • Come from a special HumanOverseer agent (program: WebUI, model: Human)
  • Are always marked high importance so they stand out in agent inboxes
  • Bypass normal contact policies so you can always reach any agent
  • Include a preamble instructing agents to pause current work, handle the request, then resume

Agents see overseer messages in their normal inbox via fetch_inbox or resource://inbox/{name}. They can reply in-thread like any other message. Everything is stored identically to agent-to-agent messages (Git + SQLite), fully auditable.


Deployment Validation

# Export a bundle
am share export -o /tmp/agent-mail-bundle --no-zip

# Verify a live deployment against the bundle
am share deploy verify-live https://example.github.io/agent-mail \
  --bundle /tmp/agent-mail-bundle \
  --json > /tmp/verify-live.json

# Inspect verdict
jq '.verdict, .summary, .config' /tmp/verify-live.json

Exit codes: 0 = pass, 1 = fail.


Configuration

All configuration via environment variables. The server reads them at startup via Config::from_env().

Variable Default Description
AM_INTERFACE_MODE (unset = MCP) mcp or cli
HTTP_HOST 127.0.0.1 Bind address
HTTP_PORT 8765 Bind port
HTTP_PATH /mcp/ MCP base path
HTTP_BEARER_TOKEN (from .env file) Auth token
DATABASE_URL sqlite:///:memory: SQLite connection URL
STORAGE_ROOT ~/.mcp_agent_mail Archive root directory
LOG_LEVEL info Minimum log level
TUI_ENABLED true Interactive TUI toggle
TUI_HIGH_CONTRAST false Accessibility mode
AM_TUI_TOAST_ENABLED true Enable toast notifications
AM_TUI_TOAST_SEVERITY info Minimum toast severity (info/warning/error/off)
AM_TUI_TOAST_POSITION top-right Toast stack position
AM_TUI_TOAST_MAX_VISIBLE 3 Max visible toasts at once
AM_TUI_TOAST_INFO_DISMISS_SECS 5 Info toast auto-dismiss timeout
AM_TUI_TOAST_WARN_DISMISS_SECS 8 Warning toast auto-dismiss timeout
AM_TUI_TOAST_ERROR_DISMISS_SECS 15 Error toast auto-dismiss timeout
AM_TUI_THREAD_PAGE_SIZE 20 Thread conversation page size
AM_TUI_THREAD_GUIDES rounded (theme default) Thread tree guide style (ascii/unicode/bold/double/rounded)
AM_TUI_COACH_HINTS_ENABLED true Enable contextual coach-hint notifications
AM_TUI_EFFECTS true Enable text/animation effects
AM_TUI_AMBIENT subtle Ambient mode (off/subtle/full)
WORKTREES_ENABLED false Build slots feature flag

For the full list of 100+ env vars, see crates/mcp-agent-mail-core/src/config.rs.

For operations guidance and troubleshooting, see docs/OPERATOR_RUNBOOK.md.


Architecture

Cargo workspace with strict dependency layering:

MCP Client (agent) ──── stdio/HTTP ────► mcp-agent-mail-server
                                              │
                                    ┌─────────┼─────────┐
                                    ▼         ▼         ▼
                               34 Tools   20+ Resources  TUI
                                    │         │
                              mcp-agent-mail-tools
                                    │
                         ┌──────────┼──────────┐
                         ▼          ▼          ▼
                    mcp-agent-mail-db   mcp-agent-mail-storage
                    (SQLite index)      (Git archive)
                         │
                    mcp-agent-mail-core
                    (config, models, errors, metrics)

Workspace Structure

mcp_agent_mail_rust/
├── Cargo.toml                              # Workspace root (12 member crates)
├── crates/
│   ├── mcp-agent-mail-core/                # Zero-dep: config, models, errors, metrics
│   ├── mcp-agent-mail-db/                  # SQLite schema, queries, pool, cache, Search V3 integration
│   ├── mcp-agent-mail-storage/             # Git archive, commit coalescer, notification signals
│   ├── mcp-agent-mail-search-core/         # Pluggable search traits
│   ├── mcp-agent-mail-guard/               # Pre-commit guard, reservation enforcement
│   ├── mcp-agent-mail-share/               # Snapshot, scrub, bundle, crypto, export
│   ├── mcp-agent-mail-tools/               # 34 MCP tool implementations (9 clusters)
│   ├── mcp-agent-mail-server/              # HTTP/MCP runtime, dispatch, TUI (15 screens)
│   ├── mcp-agent-mail/                     # Server binary (mcp-agent-mail)
│   ├── mcp-agent-mail-cli/                 # CLI binary (am) with robot mode
│   ├── mcp-agent-mail-conformance/         # Python parity tests
│   └── mcp-agent-mail-wasm/                # Browser/WASM TUI frontend
├── tests/e2e/                              # End-to-end test scripts
├── scripts/                                # CLI integration tests, utilities
├── docs/                                   # ADRs, specs, runbooks, migration guides
├── install.sh                              # Unix installer
├── install.ps1                             # Windows PowerShell installer
└── rust-toolchain.toml                     # Nightly toolchain requirement

Storage Layout

~/.mcp_agent_mail/                          # STORAGE_ROOT
├── projects/
│   └── {project_slug}/
│       ├── .git/                           # Per-project git repository
│       ├── messages/
│       │   └── {YYYY}/{MM}/               # Date-partitioned canonical messages
│       ├── agents/
│       │   └── {agent_name}/
│       │       ├── inbox/                  # Agent inbox copies
│       │       └── outbox/                 # Agent outbox copies
│       ├── build_slots/                    # Build slot leases (JSON)
│       └── file_reservations/              # Reservation artifacts
└── .archive.lock                           # Global advisory lock

Key Design Decisions

  • Git-backed archive for human auditability; SQLite as fast index
  • WAL mode with PRAGMA tuning and connection pooling for concurrent access
  • Write-behind cache with dual-indexed ReadCache and deferred touch batching (30s flush)
  • Async git commit coalescer (write-behind queue) to avoid commit storms
  • i64 microseconds for all timestamps (no chrono::NaiveDateTime in storage layer)
  • Search V3 via frankensearch with lexical/semantic/hybrid routing and unified diagnostics
  • Conformance testing against the Python reference implementation (23 tools, 23+ resources)
  • Advisory file reservations with symmetric fnmatch, archive reading, and rename handling
  • #![forbid(unsafe_code)] across all crates
  • asupersync exclusively for all async operations (no Tokio, reqwest, hyper, or axum)

Comparison vs. Alternatives

Feature MCP Agent Mail Shared Files / Lockfiles Custom MCP Tools Chat-Based Coordination
Agent identity & discovery Persistent names, profiles, directory queries None Manual Ephemeral
Threaded messaging Subjects, CC/BCC, ack, importance, search N/A Build yourself Linear chat, no structure
File reservation / advisory locks Glob patterns, TTL, exclusive/shared, pre-commit guard Lockfiles (no TTL, no glob) Build yourself None
Audit trail Full Git history of all communication File timestamps Depends Chat logs (if saved)
Cross-repo coordination Product bus, contact system Manual Build yourself Manual
Search Search V3 (lexical + semantic + hybrid) grep Build yourself Limited
Operational visibility 15-screen TUI, robot CLI, metrics None None None
Token efficiency Messages stored externally, not in context Files in context Varies All in context

Development

# Quality gates
cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo check --workspace --all-targets
cargo test --workspace

# Conformance tests (parity with Python reference)
cargo test -p mcp-agent-mail-conformance

# Run specific crate tests
cargo test -p mcp-agent-mail-db
cargo test -p mcp-agent-mail-tools
cargo test -p mcp-agent-mail-server

# E2E tests
tests/e2e/test_stdio.sh         # MCP stdio transport
tests/e2e/test_http.sh           # HTTP transport
tests/e2e/test_guard.sh          # Pre-commit guard
tests/e2e/test_macros.sh         # Macro tools
tests/e2e/test_share.sh          # Share/export
tests/e2e/test_dual_mode.sh      # Mode switching
scripts/e2e_cli.sh               # CLI integration (99 assertions)

# Native E2E runner (authoritative path)
am e2e list
am e2e run --project .                 # all suites
am e2e run --project . stdio http      # selected suites
am e2e run --project . --include tui_  # pattern include

# Legacy compatibility shim (deprecated primary path)
./scripts/e2e_test.sh stdio
# rollback guard: AM_E2E_FORCE_LEGACY=1 ./scripts/e2e_test.sh stdio

# Benchmarks
cargo bench -p mcp-agent-mail

# Multi-agent builds: isolate target dir to avoid lock contention
export CARGO_TARGET_DIR="/tmp/target-$(whoami)-am"

E2E Entrypoint Policy (T9.9)

  • Native am e2e is authoritative for operator and CI invocation.
  • scripts/e2e_test.sh remains compatibility-only and emits deprecation guidance.
  • Rollback condition: set AM_E2E_FORCE_LEGACY=1 only if native runner regression is confirmed.

Verification checklist:

  • am e2e list and am e2e run --project . <suite> succeed for targeted suites.
  • Artifact repro commands reference am e2e run (not script-first commands).
  • CI/release docs and runbooks do not present scripts/e2e_test.sh as the primary command.

Key Dependencies

Crate Purpose
asupersync Structured async runtime (channels, sync, regions, HTTP, testing)
fastmcp_rust MCP protocol implementation (JSON-RPC, stdio, HTTP transport)
sqlmodel_rust SQLite ORM (schema, queries, migrations, pool)
frankentui TUI rendering (widgets, themes, accessibility, markdown, syntax highlighting)
frankensearch Hybrid search engine (lexical + semantic, two-tier fusion, reranking)
beads_rust Issue tracking integration
toon Token-efficient compact encoding for robot mode output

Mailbox Diagnostics (am doctor)

Over time, mailbox state can drift: stale locks from crashed processes, orphaned records, FTS index desync, expired reservations piling up. The doctor command group detects and repairs these issues.

# Run diagnostics (fast, non-destructive)
am doctor check
am doctor check --verbose
am doctor check --json          # Machine-readable output

# Repair (creates backup first, prompts before data changes)
am doctor repair --dry-run      # Preview what would change
am doctor repair                # Apply safe fixes, prompt for data fixes
am doctor repair --yes          # Auto-confirm everything (CI/automation)

# Backup management
am doctor backups               # List available backups
am doctor restore /path/to/backup.sqlite3

What check inspects:

Check Detects
Locks Stale .archive.lock / .commit.lock from crashed processes
Database SQLite corruption via PRAGMA integrity_check
Orphaned records Message recipients without corresponding agents
FTS index Message count vs FTS index entry mismatch
File reservations Expired reservations pending cleanup
WAL files Orphan SQLite WAL/SHM files

The repair command applies safe fixes (stale locks, expired reservations) automatically and prompts before data-affecting changes (orphan cleanup, FTS rebuild). A backup is always created before any modifications.


Troubleshooting

Problem Fix
"from_agent not registered" Always register_agent in the correct project_key first
"FILE_RESERVATION_CONFLICT" Adjust patterns, wait for TTL expiry, or use non-exclusive reservation
Auth errors with JWT Include bearer token with matching kid in the request header
Port 8765 already in use am serve-http --port 9000 or stop the existing server
TUI not rendering Check TUI_ENABLED=true and that your terminal supports 256 colors
Empty inbox Verify recipient names match exactly and messages were sent to that agent
Search returns nothing Try simpler terms and fewer filters; inspect diagnostics in search_messages explain output
Pre-commit guard blocking Check am robot reservations --conflicts for active reservations

Limitations

  • Rust nightly required. Uses Rust 2024 edition features that require the nightly compiler.
  • Local workspace dependencies. Building from source requires sibling directories for fastmcp_rust, sqlmodel_rust, asupersync, frankentui, frankensearch, beads_rust, and toon_rust.
  • Single-machine coordination. Designed for agents running on the same machine or accessing the same filesystem. Not a distributed system.
  • Advisory, not enforced. File reservations are advisory. Agents can bypass the pre-commit guard with --no-verify.
  • No built-in authentication federation. JWT support exists, but there's no centralized auth service. Each server manages its own tokens.

FAQ

Q: How is this different from the Python version? A: This is a ground-up Rust rewrite with the same conceptual model but significant improvements: a 15-screen interactive TUI, robot mode CLI, hybrid search, build slots, the product bus for cross-project coordination, and substantially better performance. The conformance test suite ensures output format parity with the Python reference.

Q: Do I need to run a separate server for each project? A: No. One server handles multiple projects. Each project is identified by its absolute filesystem path as the project_key.

Q: How do agents get their names? A: Agent Mail generates memorable adjective+noun names (e.g., GreenCastle, BlueLake, RedHarbor) when agents register. Agents can also specify a name explicitly.

Q: Can agents in different repos talk to each other? A: Yes. Use request_contact / respond_contact (or macro_contact_handshake) to establish a link between agents in different projects, then message directly. The product bus enables cross-project search and inbox queries.

Q: Does this work with Claude Code's Max subscription? A: Yes. You can use a Max account with Agent Mail. Each agent session connects to the same MCP server regardless of subscription tier.

Q: What happens if the server crashes? A: Git is the source of truth. SQLite indexes can be rebuilt from the Git archive. The commit coalescer uses a write-behind queue that flushes on graceful shutdown.

Q: How does this integrate with Beads? A: Use the Beads issue ID (e.g., br-123) as the Mail thread_id. Beads owns task status/priority/dependencies; Agent Mail carries the conversations and audit trail. The installer can optionally set up Beads alongside Agent Mail.


Ready-Made Blurb for Your AGENTS.md

Add this to your project's AGENTS.md or CLAUDE.md to help agents use Agent Mail effectively:

## MCP Agent Mail: coordination for multi-agent workflows

What it is
- A mail-like layer that lets coding agents coordinate asynchronously via MCP tools and resources.
- Provides identities, inbox/outbox, searchable threads, and advisory file reservations,
  with human-auditable artifacts in Git.

Why it's useful
- Prevents agents from stepping on each other with explicit file reservations (leases).
- Keeps communication out of your token budget by storing messages in a per-project archive.
- Offers quick reads (resource://inbox/..., resource://thread/...) and macros that bundle common flows.

How to use effectively
1) Register an identity: call ensure_project, then register_agent using this repo's
   absolute path as project_key.
2) Reserve files before you edit: file_reservation_paths(project_key, agent_name,
   ["src/**"], ttl_seconds=3600, exclusive=true)
3) Communicate with threads: use send_message(..., thread_id="FEAT-123"); check inbox
   with fetch_inbox and acknowledge with acknowledge_message.
4) Quick reads: resource://inbox/{Agent}?project=<abs-path>&limit=20

Macros vs granular tools
- Prefer macros for speed: macro_start_session, macro_prepare_thread,
  macro_file_reservation_cycle, macro_contact_handshake.
- Use granular tools for control: register_agent, file_reservation_paths, send_message,
  fetch_inbox, acknowledge_message.

Common pitfalls
- "from_agent not registered": always register_agent in the correct project_key first.
- "FILE_RESERVATION_CONFLICT": adjust patterns, wait for expiry, or use non-exclusive.

Documentation

Document Purpose
OPERATOR_RUNBOOK.md Deployment, troubleshooting, diagnostics
DEVELOPER_GUIDE.md Dev setup, debugging, testing
MIGRATION_GUIDE.md Python to Rust migration
RUNBOOK_LEGACY_PYTHON_TO_RUST_IMPORT.md am legacy / am upgrade migration operations
RELEASE_CHECKLIST.md Pre-release validation
ROLLOUT_PLAYBOOK.md Staged rollout strategy
TEMPLATE_OLD_REPO_RUST_CUTOVER_PR_CHECKLIST.md Canonical old-repo cutover PR checklist
TEMPLATE_OLD_REPO_RUST_CUTOVER_RELEASE_NOTES.md Release-notes template for Rust cutover
ADR-001 Dual-mode interface design
ADR-002 Single binary with mode switch
ADR-003 Search v3 implementation

About Contributions

Please don't take this the wrong way, but I do not accept outside contributions for any of my projects. I simply don't have the mental bandwidth to review anything, and it's my name on the thing, so I'm responsible for any problems it causes; thus, the risk-reward is highly asymmetric from my perspective. I'd also have to worry about other "stakeholders," which seems unwise for tools I mostly make for myself for free. Feel free to submit issues, and even PRs if you want to illustrate a proposed fix, but know I won't merge them directly. Instead, I'll have Claude or Codex review submissions via gh and independently decide whether and how to address them. Bug reports in particular are welcome. Sorry if this offends, but I want to avoid wasted time and hurt feelings. I understand this isn't in sync with the prevailing open-source ethos that seeks community contributions, but it's the only way I can move at this velocity and keep my sanity.


License

MIT License (with OpenAI/Anthropic Rider). See LICENSE.

About

Rust MCP server for multi-agent coordination: 34 tools, Git-backed archive, SQLite indexing, advisory file locks, and an interactive TUI console

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Rust 81.6%
  • Shell 14.9%
  • HTML 2.7%
  • Python 0.5%
  • JavaScript 0.1%
  • PowerShell 0.1%
  • CSS 0.1%