diff --git a/.claude/bootstrap-version b/.claude/bootstrap-version new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/.claude/bootstrap-version @@ -0,0 +1 @@ +2 diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..0917541 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,25 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "f=$(cat | python3 -c 'import json,sys;print(json.load(sys.stdin).get(\"tool_input\",{}).get(\"file_path\",\"\"))'); case \"$f\" in *.py) python3 -m py_compile \"$f\" ;; esac" + } + ] + } + ], + "Stop": [ + { + "hooks": [ + { + "type": "command", + "command": "cd \"$CLAUDE_PROJECT_DIR\" && python3 -m py_compile server.py" + } + ] + } + ] + } +} diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..0ade5d4 --- /dev/null +++ b/.env.example @@ -0,0 +1,17 @@ +# Copy to email-mcp.env (gitignored) and fill in real values. Never commit real values. + +# IMAP server used to read/manage mail +IMAP_HOST= +IMAP_PORT=993 + +# SMTP server used to send mail +SMTP_HOST= +SMTP_PORT=465 + +# JSON object mapping each account's email address to its password, e.g. +# EMAIL_ACCOUNTS={"user@example.com":"app-password"} +EMAIL_ACCOUNTS= + +# Address/port the MCP server binds to +BIND_HOST=127.0.0.1 +BIND_PORT=8084 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4dcc8a2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: + pull_request: + branches: [development] + push: + branches: [development, main] + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + + - name: Install dependencies + run: pip install -r requirements.txt + + # No linter is configured yet; this is a minimal syntax check. + - name: Syntax check + run: python -m py_compile server.py + + # No test suite exists yet. + - name: Tests + run: echo "No test suite configured yet; skipping." diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..f442666 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,68 @@ +name: Version + +on: + push: + branches: [development, main] + +permissions: + contents: write + +jobs: + bump: + if: github.actor != 'github-actions[bot]' && !contains(github.event.head_commit.message, '[skip ci]') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Configure git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Bump version + id: bump + run: | + set -euo pipefail + current=$(cat VERSION) + IFS=. read -r major minor patch <<< "$current" + + if [ "${{ github.ref_name }}" = "development" ]; then + patch=$((patch + 1)) + else + # main: MINOR bump only when every commit on this push came from development + # (i.e. this push is a merge of development into main), otherwise a hotfix PATCH bump. + is_merge_from_development=true + for sha in $(git rev-list ${{ github.event.before }}..${{ github.sha }}); do + if ! git merge-base --is-ancestor "$sha" origin/development 2>/dev/null; then + is_merge_from_development=false + break + fi + done + if [ "$is_merge_from_development" = true ]; then + minor=$((minor + 1)) + patch=0 + else + patch=$((patch + 1)) + fi + fi + + new_version="$major.$minor.$patch" + echo "$new_version" > VERSION + echo "new_version=$new_version" >> "$GITHUB_OUTPUT" + + - name: Commit and push + run: | + git add VERSION + git commit -m "chore(release): v${{ steps.bump.outputs.new_version }} [skip ci]" + git push origin HEAD:${{ github.ref_name }} + + - name: Merge main back into development + if: github.ref_name == 'main' + run: | + git fetch origin development + git checkout development + git merge --no-edit origin/main + git push origin development diff --git a/.gitignore b/.gitignore index 6d48c8a..c46317d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ email-mcp.env +__pycache__/ +*.pyc + diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..5304f60 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,37 @@ +# CLAUDE.md + +## Overview +A single-file MCP (Model Context Protocol) server exposing IMAP/SMTP email operations +(list/read/move/delete emails, manage folders, send mail) as MCP tools over +streamable-http, for one or more configured email accounts. + +## Commands +- Run locally: `python server.py` (requires env vars below; see `.env.example`). +- Install dependencies: `pip install -r requirements.txt`. +- Test: no test suite yet. +- Lint/format: no linter/formatter configured yet. +- Build: none (plain Python script, deployed via Nixpacks — see `nixpacks.toml`). + +## Architecture +Everything lives in `server.py`: env-based config, IMAP/SMTP helper functions, and +`@mcp.tool()`-decorated functions exposed to MCP clients. See `docs/` for any deeper +notes as they are added. + +## Conventions +- Python 3, stdlib `imaplib`/`smtplib`/`email` for all mail access — no mail client + framework. +- Tools return plain strings or JSON-serializable dicts/lists, never raw IMAP data. + +## Workflow quirks +- `EMAIL_ACCOUNTS` is a JSON object mapping account (email address) to password; it is + read from the environment, never from a committed file. + +## Deployment +Deployed via Nixpacks (`nixpacks.toml`: `python server.py`) to a PaaS-style host, not +the LXC/systemd pattern. The server binds to `BIND_HOST`/`BIND_PORT` and speaks MCP +over streamable-http. + +## Gotchas +- `purge_email` permanently deletes a message; there is no undo. +- Real credentials belong in `email-mcp.env` (gitignored), never in `.env.example` or + in code. diff --git a/LESSONS.md b/LESSONS.md new file mode 100644 index 0000000..33855ad --- /dev/null +++ b/LESSONS.md @@ -0,0 +1,6 @@ +# LESSONS.md + +Recurring mistakes in this repo and how to avoid them. Read before starting work, add +to it when a mistake repeats. + +(No recurring mistakes recorded yet.) diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6e3407 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# ZenvairoEmail-mcp + +An MCP server that exposes IMAP/SMTP email operations (list accounts and folders, +read/move/delete emails, send mail) as tools for MCP clients. + +## Quick start + +```bash +pip install -r requirements.txt +cp .env.example email-mcp.env # fill in real values +set -a; source email-mcp.env; set +a +python server.py +``` + +See `CLAUDE.md` for architecture and conventions, and `docs/` for further documentation. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/docs/.gitkeep b/docs/.gitkeep new file mode 100644 index 0000000..e69de29