Guide · MCP servers

Keep API keys out of MCP server configs

MCP clients start servers from a JSON config, and the usual way to give a server its key is to type the key into that file. Latchkey lets the config hold a reference instead.

In shortSave the key in Latchkey, then change the server's command to latchkey run --no-masking -- … and put latchkey://NAME in its env. The client starts the server as before; Latchkey fills the key in for that process.

Why the config is a problem

A config such as .mcp.json or Claude Desktop's settings file holds every server's keys in plain text. It gets shared to set up a teammate, checked into a repository for a project's tools, or synced between Macs, and every key in it goes along.

Wrap the server

  1. Save the key in Latchkey

    Terminal
    lk set SOME_API_KEY --kind token

    The value is read from a hidden prompt or standard input, so it never appears in your shell history.

  2. Start the server through latchkey run

    MCP server config
    {
      "command": "latchkey",
      "args": ["run", "--no-masking", "--", "npx", "-y", "some-mcp-server"],
      "env": { "SOME_API_KEY": "latchkey://SOME_API_KEY" }
    }

    --no-masking matters here: MCP speaks over standard output, which must pass through untouched.

  3. Decide how it may read the key

    The server is started by your agent, so its reads come from the agent's process chain. Either mark the item agent-safe, or grant it for the time you'll be working; otherwise each start asks you.

    Terminal
    lk update SOME_API_KEY --agent-safe yes

Latchkey's own MCP server

Terminal
claude mcp add latchkey -- ~/.local/bin/latchkey mcp

For clients without a shell, Latchkey's server offers status, listing, checking, running commands with references filled in, and asking you for a grant. It has no tool that reads a value, and the output it returns is masked.

What this doesn't do

Only servers started as a command can be wrapped. A server reached over HTTP with a header key can't get it this way. And like any command, a wrapped server holds the key in memory once it starts.

Related