Quickstart (self-host)
You need a Linux host with Docker and Compose, a domain name, and a TLS reverse proxy such as Caddy, nginx or Traefik.
1. Google Cloud (one time)
Section titled “1. Google Cloud (one time)”- Create a project and enable the Gmail API (and the Google Calendar API if you set
FEATURES=mail,calendar). - Google Auth Platform → Branding: set the app name, support email, home page, privacy policy link and authorized domain.
- Audience: choose External, then click Publish app to move it to In production. Don’t submit it for verification. In Testing mode Google expires refresh tokens after 7 days, so you would have to relink weekly.
- Data Access: add
openid,.../auth/userinfo.email,.../auth/gmail.readonlyand.../auth/gmail.compose. If you turn on triage, also add.../auth/gmail.modify; for the calendar module,.../auth/calendar.readonlyand.../auth/calendar.events. - Clients → create a Web application client with these redirect URIs:
https://<host>/auth/callbackhttps://<host>/gmail/callbackhttps://<host>/send/auth/callback(only needed withSENDING_ENABLED=trueorFEATURES=mail,calendar)
- If you use Google Workspace, the admin should go to Admin console → Security → API controls → Manage third-party app access, add the app by client ID and mark it Trusted. Otherwise Workspace policy may block mailbox linking.
2. Configure
Section titled “2. Configure”git clone <this repo> /opt/surfski && cd /opt/surfskisudo install -d -m 700 /etc/surfski && sudo install -m 600 deploy/env.example /etc/surfski/envpython3 scripts/gen_secrets.pyPaste the four generated secrets into /etc/surfski/env, then fill in BASE_URL,
GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET and ALLOWED_USERS (and/or ALLOWED_DOMAINS to allow
a whole Workspace domain). The server refuses to start if any secret is missing or malformed, or
if both allowlists are empty.
Aliases: Google sign-in reports a user’s primary address. If your Workspace uses alias domains, put the primary addresses in
ALLOWED_USERS, or the Workspace primary domain inALLOWED_DOMAINS(an alias domain never matches; Google’shdclaim must equal the primary domain). Linking an alias address links the primary mailbox behind it.Secondary domains: if a user’s address is on a secondary domain of a Workspace org, Google’s
hdclaim may still be the org’s primary domain, so list the primary domain inALLOWED_DOMAINS(or list the user inALLOWED_USERS). A mismatch fails closed: the user is refused.
3. Run
Section titled “3. Run”sudo docker compose -p surfski up -d --buildcurl -s 127.0.0.1:38000/healthzPrebuilt image (optional). Instead of building locally, you can use the multi-arch
(amd64/arm64) image published on each release. In compose.yaml, replace build: . and
image: surfski:latest with:
image: ghcr.io/rayhu/surfski:latest # or pin a release, e.g. ghcr.io/rayhu/surfski:v0.1.0Then start it without --build:
sudo docker compose -p surfski up -dPoint your reverse proxy at 127.0.0.1:38000. deploy/Caddyfile.snippet is a Caddy example.
Don’t enable response compression on this route, because the MCP stream uses SSE.
4. Connect Claude
Section titled “4. Connect Claude”In Claude, go to Settings → Connectors → Add custom connector and enter
https://<host>/mcp. Click Connect and sign in with an allowlisted Google account. Then say:
“link my work Gmail as work” and open the link Claude returns.
When you link a mailbox, sign in as that mailbox and tick both permission checkboxes.
Upgrade
Section titled “Upgrade”What changed in each version is in CHANGELOG.md; surfski --version (or
docker compose -p surfski exec app surfski --version) shows what you run.
git pull && sudo docker compose -p surfski up -d --buildWith the prebuilt image, run git pull && sudo docker compose -p surfski pull && sudo docker compose -p surfski up -d instead. The git pull picks up changes to compose.yaml and the env reference.
Backups
Section titled “Backups”scripts/backup.sh backs up the surfski_surfski-data volume to
/var/backups/surfski/surfski-data-YYYYmmdd-HHMMSS.tgz (mode 600) and deletes archives older than
14 days. It takes a consistent SQLite snapshot with Python’s online backup API inside the Surfski
image, so the server can keep running, and adds oauth/ as files. It refuses to run if anything
named env/*.env is in the volume. --dry-run shows what it would do; --help lists options
(--dest, --keep, --volume, --image).
Nightly at 03:15 from root’s crontab (it uses the local surfski:latest image that docker compose build creates):
15 3 * * * /opt/surfski/scripts/backup.sh --keep 14 >> /var/log/surfski-backup.log 2>&1Restore:
docker compose stop appsudo scripts/backup.sh --restore /var/backups/surfski/surfski-data-20260101-031500.tgz --yes# add --force if the volume isn't empty; its contents are replaceddocker compose start appThe backup is useless without TOKEN_ENCRYPTION_KEY and STORAGE_ENCRYPTION_KEY, and it never
contains them. Keep the env file in a separate place, such as a password manager, never in the same
backup. Restore with the same keys that were in use when the backup was made. If you lose the
keys, users simply relink their mailboxes.
Administration (local CLI)
Section titled “Administration (local CLI)”surfski with no arguments (or surfski serve) runs the server; that is what the container’s
CMD does. The admin subcommands work on the database directly and run only from a shell on the
host or inside the container. There is no network admin endpoint. They never print refresh
tokens, ciphertext or keys, and they are safe to run while the server is up.
sudo docker compose -p surfski exec app surfski admin list| Command | What it does |
|---|---|
admin list [--json] | Every owner with their mailboxes: alias, address, created / last used, send policy, triage |
admin unlink --owner X --alias Y [--revoke] | Remove one mailbox (as unlink_account). --revoke also revokes its token at Google |
admin purge-owner --owner X --yes | Erase all of one owner’s data, exactly as their delete_my_data would (revokes at Google; audit rows follow AUDIT_ON_DELETE). Without --yes nothing is deleted |
admin rotate-token-key [--dry-run] | Re-encrypt every refresh token with the current key (see below) |
admin audit --owner X [--since 7d|2026-10-01] | Audit row counts per tool (ok / failed), never details |
Exit codes: 0 success; 1 refused or failed (unknown owner or alias, missing --yes, a failed
revocation at Google, undecryptable rows during rotation); 2 usage or configuration error. When a
revocation fails, unlink and purge-owner have still removed the data. An unexpected error (for example
database is locked) prints one line and exits 1; surfski admin --debug … shows the traceback.
Rotating encryption keys
Section titled “Rotating encryption keys”TOKEN_ENCRYPTION_KEY (Gmail refresh tokens in SQLite). While TOKEN_ENCRYPTION_KEY_OLD is set,
the server decrypts with the new key, then the old one, and always encrypts with the new one, so
it keeps working during the whole rotation:
- Generate a key:
python3 scripts/gen_secrets.pyand take itsTOKEN_ENCRYPTION_KEYline. - In
/etc/surfski/env, move the current value toTOKEN_ENCRYPTION_KEY_OLDand put the new key inTOKEN_ENCRYPTION_KEY. - Restart the server on the new key before rotating:
sudo docker compose -p surfski up -d(a plainrestartdoesn’t reread the env file). This order matters: a server still running on the old key keeps writing old-key rows (every link or relink), and any it writes after step 4 stay on the old key.docker compose execalso takes the container’s env, so the rotate command only sees the new key once the container was recreated. If you got the order wrong, restart and run step 4 again; it is idempotent and only touches rows that aren’t on the current key yet. - Rotate:
sudo docker compose -p surfski exec app surfski admin rotate-token-key. It re-encrypts every row in one SQLite write transaction and reports the counts. If any row can’t be decrypted with the new or the old key, it changes nothing, lists the affected owner / alias pairs and exits 1 (relink oradmin unlinkthose, or supply the right old key, then run it again). - Remove
TOKEN_ENCRYPTION_KEY_OLDand restart again.
Per-owner keys work the same way with TOKEN_ENCRYPTION_KEYS_OLD=owner=oldkey,…. Giving an existing
owner their own TOKEN_ENCRYPTION_KEYS entry is a rotation too: set
TOKEN_ENCRYPTION_KEYS_OLD=owner=<the default key> for it (an owner with a per-owner key never falls
back to the default key on its own). Removing an owner’s entry: set TOKEN_ENCRYPTION_KEYS_OLD to
their former key.
Pending confirmation links (send, calendar and policy confirmations, which live 10 minutes) are encrypted
with the owner’s token key too. They stay valid during a rotation while the old key is configured, and
only break if you remove TOKEN_ENCRYPTION_KEY_OLD (or the owner’s TOKEN_ENCRYPTION_KEYS_OLD entry)
within 10 minutes of the link being issued; the owner then asks for a new link.
Backups after a rotation: older backups still need the old key. Keep the old key with the backups it protects until they expire, or take a fresh backup right after rotating.
STORAGE_ENCRYPTION_KEY (FastMCP’s OAuth store under DATA_DIR/oauth: Claude’s client
registrations and session tokens). Set STORAGE_ENCRYPTION_KEY_OLD to the previous key alongside the
new one and restart: existing entries stay readable and new ones are written with the new key. There
is no rewrite command, because that file store has no locking and a rewrite could race the running
server. When you finally remove STORAGE_ENCRYPTION_KEY_OLD, entries still under the old key read as
missing, so Claude users whose connector registration predates the rotation must reconnect the
connector (Settings → Connectors). Nothing else is lost: linked mailboxes are in SQLite.
Synced from rayhu/surfski/README.md@0165816. The repository is the source of truth.