TL;DR If you add an MCP server with
claude mcp add-jsonand the token sits inside the command, your shell saves it in its history: it stays there in plain text, one up arrow away. Save the JSON to a file and pass it with a-:claude mcp add-json <name> - < server.json, from your own terminal (not from inside Claude Code). If the server goes in the project's.mcp.json, write${TOKEN}in the JSON instead of the token.
Many MCP servers, GitHub's among them, ask for a token: a key that opens your account. The usual way to add them, claude mcp add-json <name> '<json>', puts the server's JSON, token included, inside the command itself. And your shell saves every command you type in its history, in plain text: the token stays there, readable by anyone who opens that file or any script that reads it, and it shows up in ps while the command runs. Since v2.1.327, a - in place of the JSON reads it from a file or a pipe instead, and history keeps only the file name. With no JSON block involved, the quick setup tip covers claude mcp add.
Where the token ends up with each form
| Form | Shell history | ps while it runs |
~/.claude.json |
|---|---|---|---|
add-json github '{...Bearer ghp_...}' |
Yes | Yes | Yes, in plain text |
| Heredoc typed at the prompt | Yes, bash saves the body with the command | No | Yes, in plain text |
add-json github - < github.json |
Only the file name | No | Yes, in plain text |
JSON with Bearer ${GITHUB_MCP_TOKEN} |
Only the reference | No | Only the reference |
The last row is the only one that keeps the token off disk too. It's covered further down.
The steps
1. Save only the server object
Many servers document the block for Claude Desktop or Cursor, wrapped in mcpServers. add-json wants what's inside, without the wrapper or the server name. In github.json:
{"type":"http","url":"https://api.githubcopilot.com/mcp/","headers":{"Authorization":"Bearer ghp_..."}}
Paste the whole block and v2.1.336 tells you exactly what to drop:
Invalid configuration: leave out the "mcpServers" wrapper and the server name. Pass only the settings inside them.
And if the block has a url but no type, as blocks written for other clients often do:
Invalid configuration: it has a "url" but no "type". Add "type": "http" (or "sse" / "ws").
2. Add it from your terminal
claude mcp add-json github - < github.json
rm github.json
It prints the same line as the argument form, Added http MCP server github to local config. Without --scope it goes to local: only you, only in this folder. For every project, --scope user. Both are stored in ~/.claude.json, which is not your settings.json.
3. Skip the file altogether
If you don't want the token on disk even for a second, build the JSON in the pipe. read -rs doesn't echo it as you paste and doesn't save it to history:
read -rs GITHUB_MCP_TOKEN && export GITHUB_MCP_TOKEN
jq -n '{type:"http",url:"https://api.githubcopilot.com/mcp/",headers:{Authorization:("Bearer "+$ENV.GITHUB_MCP_TOKEN)}}' \
| claude mcp add-json github -
unset GITHUB_MCP_TOKEN
jq reads $ENV.GITHUB_MCP_TOKEN from the environment, so the token never shows up in jq's arguments either. The output of your password manager's CLI works the same in place of read.
It doesn't work inside Claude Code
Ask Claude to run it and v2.1.336 answers:
Reading the JSON from stdin is refused inside a Claude Code session, because its permission prompt would not show the server. Run the command outside the session.
The reason is in the message: the permission prompt you approve would show claude mcp add-json github - < github.json, not the server you're adding. In the binary, the refusal fires when CLAUDE_CODE_CHILD_SESSION is set, the variable Claude Code puts in every shell a session opens. The argument form does work inside, but then the token is in the command Claude writes, and in the conversation. Keys go in from a terminal of your own.
What - doesn't fix
The token is still stored in plain text in ~/.claude.json, and claude mcp get prints it in full. With a test server (output trimmed):
demo:
Scope: Local config (private to you in this project)
Type: http
URL: https://mcp.example.com/mcp
Headers:
Authorization: Bearer sk-demo-123
If that bothers you, don't store the token: store a reference. Claude Code expands ${VAR} in ~/.claude.json servers the same way it does in .mcp.json:
claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp/","headers":{"Authorization":"Bearer ${GITHUB_MCP_TOKEN}"}}'
Single quotes keep the shell off ${GITHUB_MCP_TOKEN}, so here the argument is fine: nothing in it is secret. claude mcp get shows Bearer ${GITHUB_MCP_TOKEN}, and against a local server that logs headers, the request arrived with the variable's real value. If the variable isn't set when you start, claude mcp list warns Missing environment variables: GITHUB_MCP_TOKEN.
Give the variable a name of your own. Claude Code reads well-known credential variables (ANTHROPIC_API_KEY, NPM_TOKEN, your cloud provider's) as empty, so a stranger's .mcp.json can't ship them to its server. Tried with Bearer ${NPM_TOKEN}: the server got Bearer with nothing after it and answered 401.
With --scope project it's the only sane option: the server goes to .mcp.json, which gets committed with the token in it if you write it literally. Each teammate sets GITHUB_MCP_TOKEN in their own environment, and the server sits at ⏸ Pending approval until each of them approves it when they open claude.
Other errors you'll hit
| Message | What happened |
|---|---|
There is no JSON on stdin. Pipe it in, or pass it as the argument. |
You ran add-json github - with no pipe or <. It doesn't wait for you to type: with stdin on the terminal, it reads it as empty |
MCP server github already exists in local config |
To change the token, claude mcp remove github -s local, then add it again |
Invalid configuration: not a JSON object. Check its quotes, commas and braces. |
The JSON is broken, usually a stray comma or quote |
The JSON on stdin is over the limit of 1 MiB. |
Only if you feed it the wrong file: stdin takes up to 1 MiB |
Servers with OAuth need none of this: there's no token to paste, and you sign in from the shell.
Official docs: Add MCP servers from JSON configuration
Requirements
- Claude Code v2.1.327 or later for
add-json -. Tested on v2.1.336 on Linux: the argument form, the errors, the scopes,${VAR}and the refusal inside a session, for real. Reading stdin outside a session can't run in the test container; that path (stdin on a terminal, the 1 MiB cap) is read from the binary, and the JSON it reads goes through the same code as the argument.