# Multi-Workspace Agent Mail Setup
Guide for running Agent Mail across multiple beads repositories.
## Service Management
### Start Agent Mail Server (One Instance for All Projects)
```bash
# Start in background with nohup
cd ~/src/mcp_agent_mail
source .venv/bin/activate
nohup python -m mcp_agent_mail.cli serve-http --host 127.0.0.1 --port 8765 > ~/agent-mail.log 2>&1 &
echo $! > ~/agent-mail.pid
```
### Check Server Status
```bash
# Health check
curl http://127.0.0.1:8765/health
# View logs
tail -f ~/agent-mail.log
# Check process
ps aux | grep mcp_agent_mail
# Or use saved PID
ps -p $(cat ~/agent-mail.pid) || echo "Server not running"
```
### Restart Server
```bash
# Kill old server
kill $(cat ~/agent-mail.pid) 2>/dev/null || pkill -f mcp_agent_mail
# Start fresh
cd ~/src/mcp_agent_mail
source .venv/bin/activate
nohup python -m mcp_agent_mail.cli serve-http --host 127.0.0.1 --port 8765 > ~/agent-mail.log 2>&1 &
echo $! > ~/agent-mail.pid
```
### Auto-Start on Reboot (macOS launchd)
```bash
# Create ~/Library/LaunchAgents/com.user.mcp-agent-mail.plist
cat > ~/Library/LaunchAgents/com.user.mcp-agent-mail.plist <<'EOF'
Label
com.user.mcp-agent-mail
ProgramArguments
/Users/stevey/src/mcp_agent_mail/.venv/bin/python
-m
mcp_agent_mail.cli
serve-http
--host
127.0.0.1
--port
8765
WorkingDirectory
/Users/stevey/src/mcp_agent_mail
StandardOutPath
/Users/stevey/agent-mail.log
StandardErrorPath
/Users/stevey/agent-mail-error.log
RunAtLoad
KeepAlive
EOF
# Load service
launchctl load ~/Library/LaunchAgents/com.user.mcp-agent-mail.plist
# Check status
launchctl list | grep mcp-agent-mail
```
## Project Configuration Strategy
**Three team channels** for tightly-coupled workers:
```bash
beads.dev → All beads workers (5 repos)
vc.dev → All vc workers (5 repos)
wyvern.dev → All wyvern workers (3 repos)
```
**Why this design:**
- Each team's workers are tightly coupled and need frequent coordination
- Simple namespace strings (no filesystem paths required)
- Usenet-style naming for clarity
- Cross-project filing handled via git/PRs for now (until Agent Mail adds cross-project messaging)
### Configuration by Workspace
```bash
# All beads repos use same project
~/src/beads → BEADS_PROJECT_ID=beads.dev
~/src/cino/beads → BEADS_PROJECT_ID=beads.dev
~/src/dave/beads → BEADS_PROJECT_ID=beads.dev
~/src/emma/beads → BEADS_PROJECT_ID=beads.dev
~/src/fred/beads → BEADS_PROJECT_ID=beads.dev
# All vc repos use same project
~/src/cino/vc → BEADS_PROJECT_ID=vc.dev
~/src/dave/vc → BEADS_PROJECT_ID=vc.dev
~/src/fred/vc → BEADS_PROJECT_ID=vc.dev
~/src/vc → BEADS_PROJECT_ID=vc.dev
(standalone at ~/src/vc if exists)
# All wyvern repos use same project
~/src/cino/wyvern → BEADS_PROJECT_ID=wyvern.dev
~/src/fred/wyvern → BEADS_PROJECT_ID=wyvern.dev
~/src/wyvern → BEADS_PROJECT_ID=wyvern.dev
```
## Per-Directory Configuration
Create `.envrc` or `.env` file in each workspace:
### Example: ~/src/fred/vc/.envrc
```bash
# Agent Mail Configuration for fred's vc
export BEADS_AGENT_MAIL_URL=http://127.0.0.1:8765
export BEADS_AGENT_NAME=fred-vc-$(hostname)
export BEADS_PROJECT_ID=vc.dev
# Load with direnv
# Install direnv: brew install direnv
# Then: direnv allow
```
### Example: ~/src/cino/beads/.envrc
```bash
# Agent Mail Configuration for cino's beads fork
export BEADS_AGENT_MAIL_URL=http://127.0.0.1:8765
export BEADS_AGENT_NAME=cino-beads-$(hostname)
export BEADS_PROJECT_ID=beads.dev
```
### Quick Setup Script
```bash
#!/bin/bash
# setup-agent-mail.sh - Run in each workspace
WORKSPACE=$(pwd)
WORKSPACE_NAME=$(basename $WORKSPACE)
PARENT=$(basename $(dirname $WORKSPACE))
# Determine project ID based on coupling
case "$WORKSPACE_NAME" in
vc|wyvern)
# Tightly coupled - use parent coordination project
PROJECT_ID="/Users/stevey/src/${PARENT}/coordination"
;;
beads)
# Loosely coupled - use workspace as project
PROJECT_ID="$WORKSPACE"
;;
*)
# Default - use workspace
PROJECT_ID="$WORKSPACE"
;;
esac
cat > .envrc < ~/agent-mail.log 2>&1 &
echo $! > ~/agent-mail.pid
```
## Best Practices
1. **Use direnv for automatic env loading**
```bash
brew install direnv
# Add to ~/.zshrc: eval "$(direnv hook zsh)"
# Then create .envrc in each workspace
```
2. **Descriptive agent names**
```bash
# Bad: export BEADS_AGENT_NAME=agent1
# Good: export BEADS_AGENT_NAME=fred-vc-macbook
```
3. **Monitor server logs**
```bash
tail -f ~/agent-mail.log
```
4. **Health check in scripts**
```bash
if ! curl -sf http://127.0.0.1:8765/health > /dev/null; then
echo "WARNING: Agent Mail unavailable (falling back to git-only)"
fi
```
5. **Document project relationships**
- Keep this file updated when adding workspaces
- Add comments in .envrc explaining project coupling
## Summary
- **One server** handles all projects (lightweight HTTP API)
- **Project ID = namespace** for agent isolation
- **Tight coupling** → shared project (vc + wyvern)
- **Loose coupling** → separate projects (beads forks)
- **Auto-restart** via launchd recommended
- **Per-directory .envrc** for automatic config loading