Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Keep tokens out of config files

For anyone whose MCP servers need API keys or tokens and who doesn't want them sitting in plain text in ~/.claude.json, mcp.json or Surjection's store. At the end, each server refers to its secret by an alias, and the value lives in the OS keyring, in 1Password, or in an environment variable you control.

How it works

A server never holds the value. It holds a reference such as ${secret:GITHUB_TOKEN}, and the alias points at one of three places:

Where the value livesReferenceGood for
OS keyring (Windows Credential Manager, macOS Keychain, Secret Service on Linux)keyring://surjection/GITHUB_TOKENOne machine, no extra tools; the default
1Passwordop://vault/item/fieldValues you already keep in 1Password, shared across machines
Environment variableenv:GITHUB_TOKENValues another tool already sets, CI, or a shell profile

When a client starts the server, the value is fetched at that moment (for example by surject exec or a command the client runs) and never written into the client's file. A server whose secret can't be found on this machine is blocked for its clients instead of being written without it.

Before you start

Steps

Tokens usually come in through one of these, and all of them already keep the value out of the files:

To set or change where a secret lives, and to fill in one that is missing:

  1. Open Settings and scroll to Secrets. It lists the providers this machine has, and the aliases with their reference and the servers that use them. Used but not defined names aliases a server needs that have no reference yet.

    Settings, Secrets: environment variables, the OS keyring and the 1Password CLI available, three aliases with their references, and LINEAR_API_KEY used but not defined.

  2. Choose Check all. The Secrets checklist resolves every alias (it never shows a value) and marks each one Resolved, Missing, Locked: sign in or approve or another status; Blocks apply marks those an enabled server needs.

  3. For a missing alias, pick where its value goes:

    • Enter value into keyring: type or paste the value in Value.
    • Choose a 1Password item: an op://vault/item/field reference.
    • Use environment variable: the variable's name.

    This machine only keeps the choice on this machine, so another machine can use 1Password for the same alias while this one uses the keyring. Choose Save.

    The Secrets checklist: GITHUB_TOKEN and SENTRY_TOKEN resolved, LINEAR_API_KEY missing and blocking the apply, with Enter value into keyring selected and an empty Value field.

  4. Choose Review and apply to write the servers that were blocked.

To move an existing alias to another provider, use the same fix on its row, or the command line below. Map a 1Password Environment... maps every variable of a 1Password Environment to aliases at once.

On the command line

# PowerShell 7: keyring (the value is read from stdin, not typed on the command line)
Read-Host -MaskInput | surject secrets set GITHUB_TOKEN --keyring
# 1Password
surject secrets set GITHUB_TOKEN --ref 'op://Developer/GitHub PAT/credential'
# An environment variable
surject secrets set GITHUB_TOKEN --ref env:GITHUB_TOKEN
# Only on this machine
surject secrets set GITHUB_TOKEN --ref env:GITHUB_TOKEN --this-machine
# bash or zsh: keyring
read -rs VALUE && printf %s "$VALUE" | surject secrets set GITHUB_TOKEN --keyring; unset VALUE

A server uses the alias in a field: --env 'GITHUB_PERSONAL_ACCESS_TOKEN=${secret:GITHUB_TOKEN}' or --header 'Authorization=Bearer ${secret:GITHUB_TOKEN}' (single quotes, so the shell leaves ${...} alone). A literal value there is refused with leak_detected.

Check that it worked

  • surject secrets check reports every alias as resolved (exit code 5 when one isn't); it may ask for 1Password approval.
  • surject secrets ls shows each alias, this machine's reference and the servers using it.
  • Open a client file Surjection wrote, for example ~/.claude.json: it holds a reference or a surject exec command, not the value.

Undo

  • A reference change is a store commit: History, select it, Restore this version on the commit before it, or surject restore <REV> --path secrets (see Undo a change or restore a client file).
  • surject secrets clear GITHUB_TOKEN deletes the keyring value on this machine (the reference stays).
  • After an import moved tokens out of a client file, the backup taken before that write still holds the old values: Remove those backups now in the import result, or surject import --remove-old-backups=<APPLY-ID>.

More detail