One MCP config in the repo, no token in git: sharing a server across Claude Code, Codex and Cursor
A committed MCP config either carries someone's token or names a variable that half the team never set. What Claude Code, Codex and Cursor document about project config files, variable expansion, trust and approval, what we measured against a local probe server when the variable is set, unset, empty or has a default, and the files, the preflight and the gate that keep the token out of git and make a missing one loud.
You add the team's memory server to the repository so every clone gets it:
claude mcp add --transport http --scope project memory https://memory.example.com/mcp \
--header "Authorization: Bearer <your token>"The terminal answers with the header shown as [REDACTED], so it looks handled. The file it wrote, .mcp.json, holds the value in plain text. You commit it. From that push on, your token is in the history of every clone, and every teammate's agent reads and writes the team memory as you.
The careful version fails differently. You replace the value with ${TEAM_MEMORY_TOKEN} and commit that. A new teammate clones the repository and never exports the variable. Their sessions start, the server is marked failed in a status list nobody opens, and the agent answers from the repository alone for a week. Every run exits 0.
This guide puts side by side what Claude Code, Codex and Cursor document about a server config that lives in the repository, shows what we measured when the variable was set, unset, empty or given a default, and ends with the three files, a preflight and a gate you can copy.
What each harness documents
| Claude Code | Codex | Cursor | |
|---|---|---|---|
| The file the repository carries | .mcp.json at the project root. "Check .mcp.json into version control so everyone on your team gets the same MCP tools and services" | .codex/config.toml in the project, "(trusted projects only)". The default is ~/.codex/config.toml | .cursor/mcp.json "for project-specific tools". ~/.cursor/mcp.json is the global one |
| How the file names a secret | ${VAR} and ${VAR:-default} in command, args, env, url and headers | The file never holds a placeholder. bearer_token_env_var names the variable that carries the bearer token, and env_http_headers maps a header name to a variable name. http_headers is for static values | ${env:NAME} in command, args, env, url and headers |
| The variable is not set | "the config still loads": a warning in claude mcp list and /mcp, and Claude Code "uses the unexpanded ${VAR} text as-is" | "If no credential source resolves, Codex can connect to the server without authentication." required = true makes "startup fail if this enabled server isn't ready" | Not stated on the pages we read |
| Before a server from the repository loads | An interactive session asks for approval. claude -p cannot show the prompt: "it loads project-scoped servers without asking" | The project has to be trusted | The CLI keeps a "local approved list" (agent mcp enable); --approve-mcps skips the prompts |
| What the listing shows | claude mcp list and claude mcp get show a ${VAR} reference "by name rather than as its resolved value" | codex mcp list has a column with the variable name | agent mcp list shows status, source (project or global) and transport |
| A script instead of a variable | headersHelper: a command that prints the headers as JSON. For a server from .mcp.json it runs only after the folder's trust dialog was accepted, and without the credential variables of your environment | http_headers_helper: a "local command that prints a JSON object of header names and string values" | Not documented on the pages we read |
A .env file | Not mentioned for .mcp.json on the page we read | env_vars forwards variables to a stdio server. No .env option on the page we read | envFile exists for stdio servers only: "Remote servers (HTTP/SSE) do not support envFile" |
Two rows deserve a second read.
The variable is not set. None of the three stops. Claude Code loads the entry and sends the placeholder text. Codex, by its own page, can go on without authentication. A config that names a variable moves the failure from "token in git" to "server quietly missing", and the second one has no alert.
Before a server from the repository loads. A committed config is a file somebody else wrote that makes your agent open a connection and send a header. All three put a gate in front of it, and all three have a mode with nobody at the keyboard where the gate behaves differently. Check the one your CI uses.
What we measured
A lab on one machine, on November 30, 2026: Claude Code 2.1.329 and codex-cli 0.156.1, against a probe MCP server on 127.0.0.1 that logs the Authorization header it receives and answers 401 unless the header is Bearer lab-token-…. All values are dummies. The committed file for Claude Code:
{
"mcpServers": {
"probe": {
"type": "http",
"url": "http://127.0.0.1:8765/mcp",
"headers": { "Authorization": "Bearer ${TEAM_MEMORY_TOKEN}" }
}
}
}Each row is one claude -p "Reply with the single word ok." --output-format stream-json --verbose --max-turns 1 in that folder. The status comes from mcp_servers in the system/init event, and the last column from the probe's log.
| Case | Exit code | Status of the server | What the server received |
|---|---|---|---|
TEAM_MEMORY_TOKEN=lab-token-ana | 0 | connected | Bearer lab-token-ana |
| Variable not set | 0 | failed | Bearer ${TEAM_MEMORY_TOKEN}, the placeholder itself |
| Variable set to an empty string | 0 | failed | Bearer and nothing after it |
File says ${TEAM_MEMORY_TOKEN:-lab-token-fallback}, variable not set | 0 | connected | Bearer lab-token-fallback |
File says ${NPM_TOKEN}, NPM_TOKEN set | 0 | failed | Bearer and nothing after it |
File says ${GITHUB_TOKEN}, GITHUB_TOKEN set | 0 | connected | the value |
The same server in Codex, as a user config with bearer_token_env_var = "TEAM_MEMORY_TOKEN", one codex exec per row:
| Case | What Codex printed about the server | What the server received |
|---|---|---|
| Variable set | nothing | Bearer lab-token-ana |
| Variable not set, or set to empty | nothing | no request at all |
Variable not set, required = true | required MCP servers failed to initialize: probe: Environment variable TEAM_MEMORY_TOKEN for MCP server 'probe' is not set, and the run ends there | no request |
Variable empty, required = true | the same error, ending in is empty | no request |
env_http_headers = { "Authorization" = "TEAM_MEMORY_AUTH" }, variable not set | worker quit with fatal: Transport channel closed, when UnexpectedServerResponse("HTTP 401: …"), and the session goes on | one request with no Authorization header |
The same config in .codex/config.toml of a project that is not trusted, variable set | nothing | no request |
| The same, project trusted | nothing | Bearer lab-token-ana |
codex mcp list in the untrusted project printed No MCP servers configured yet. With the variable missing and the project trusted, it printed the server as enabled with Bearer token in the Auth column. Neither line tells you the server will not be there.
Five things the lab shows
1. An unset variable sends the placeholder as the credential. Claude Code did what its page says: it sent Bearer ${TEAM_MEMORY_TOKEN}, the server refused it, the status was failed and the run exited 0. Nothing secret leaked, but your server's access log now has a rejected request per session, and the person at the keyboard saw nothing unless they opened /mcp.
2. A default in a committed file is a committed credential. ${VAR:-default} is useful for a URL or a region. On a token it puts the fallback value in git, and the lab connected with it. Keep defaults off anything that authenticates.
3. The name of the variable matters in Claude Code. In a remote server's url and headers, Claude Code reads a documented set of credential variables as empty, set or not, "with no warning": its own (ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN), your cloud provider's, and others "such as HTTPS_PROXY and NPM_TOKEN". With ${NPM_TOKEN} the server received an empty bearer, and the only trace was a line in the debug log:
[WARN] MCP server config references credential variable(s) that are never expanded toward a remote server: NPM_TOKEN (read as empty)The docs give examples, not the whole list. On this version GITHUB_TOKEN and VALORBRAIN_MCP_TOKEN expanded. Pick a name of your own for the server and do not reuse a variable that already means something to another tool. That protection exists for a reason: a .mcp.json in a repository you cloned should not be able to send your registry token to a URL it chose.
4. Codex is quiet by default. With the variable missing and no required = true, codex exec printed nothing about the server and made no request. Our Codex was not signed in, so the run stopped at the model call; a signed-in run would have gone on without the server. With required = true the same situation is a failed start with the variable's name in the error. That one line is the difference between a missing memory and a visible one.
5. The listing is not the session. claude mcp list in the lab folder printed the server as ⏸ Pending approval (run claude to approve), because nobody had approved it interactively, while claude -p in the same folder connected to it, as documented. It did print the useful part when the variable was missing:
[Has warnings] Project config (shared via .mcp.json)
└ [Warning] [probe] mcpServers.probe: Missing environment variables: TEAM_MEMORY_TOKENclaude mcp get probe printed Headers: Authorization: Bearer ${TEAM_MEMORY_TOKEN} with the variable set and unset: the name, never the value. That makes both commands safe to paste into an issue.
The three files
One variable name, three harnesses. Each file is safe to commit because it holds a name, not a value.
.mcp.json for Claude Code:
{
"mcpServers": {
"memory": {
"type": "http",
"url": "https://memory.example.com/mcp",
"headers": { "Authorization": "Bearer ${TEAM_MEMORY_TOKEN}" }
}
}
}.codex/config.toml for Codex:
[mcp_servers.memory]
url = "https://memory.example.com/mcp"
bearer_token_env_var = "TEAM_MEMORY_TOKEN"
required = true.cursor/mcp.json for Cursor:
{
"mcpServers": {
"memory": {
"url": "https://memory.example.com/mcp",
"headers": { "Authorization": "Bearer ${env:TEAM_MEMORY_TOKEN}" }
}
}
}If you create the Claude Code entry from the command line, quote the placeholder with single quotes so your shell does not expand it first. In the lab, --header 'Authorization: Bearer ${TEAM_MEMORY_TOKEN}' wrote the placeholder to .mcp.json, and the same command with a pasted value wrote the value while printing [REDACTED] on screen. codex mcp add memory --url … --bearer-token-env-var TEAM_MEMORY_TOKEN wrote the entry to the user config, not to the repository: the project file is one you write by hand.
Three notes on living with these files.
- Where the value lives. In each person's environment, outside the repository: an export in the shell profile that reads from the operating system's keychain or a password manager's CLI, or a plain export if your team accepts a token in a file under the home directory. A
.envin the repository is not read by any of the three for a remote server's headers, by what we read, and it is onegit add .away from the history. Cursor's page says to set the variable "in your shell profile or system environment"; we did not test which of the two an editor started from the dock sees. - The same name in two scopes. In Claude Code a project entry outranks a user entry with the same name, and "fields are not merged across scopes". A teammate who already has a user-level
memoryserver with a working token gets the repository's entry instead on their next session, and if they never exported the variable, the server that worked yesterday isfailedtoday. Say it in the pull request that adds the file. - The approval. A teammate's first interactive Claude Code session in the repository asks whether to use the server from
.mcp.json. In Codex the project config is ignored until the project is trusted, andcodex mcp listthen says nothing is configured. Put both in the setup notes, next to the export line.
Make a missing token loud
Three checks, cheapest first.
A preflight in the repository. One line of shell, run by whatever your team already runs first (a make setup, a pre-commit hook, the job's first step):
#!/bin/sh
# scripts/check-mcp-env.sh
: "${TEAM_MEMORY_TOKEN:?is not set. The memory server will not connect. See docs/memory-setup.md}"In the lab it exited 2 with that message when the variable was unset and when it was empty, and 0 when it was set. It checks that a value exists, not that the server accepts it.
The harness's own report. claude mcp list names the missing variable, as shown above. In Codex, required = true in the committed file makes every session without the variable fail at start with the reason. That is strict on purpose: a teammate who has not set the token cannot use Codex in that repository until they do. If your team prefers a soft start, leave required out and rely on the preflight.
A gate for runs nobody watches. For claude -p, read the first event of the stream and fail the job unless every server connected:
claude -p "$(cat prompt.md)" --output-format stream-json --verbose > run.jsonl
jq -e 'select(.type=="system" and .subtype=="init") | .mcp_servers | all(.status=="connected")' run.jsonlOn the lab's run without the variable the jq line printed false and exited 1; on the run with it, true and 0. In CI the variable comes from the runner's secret store under the same name, with a token issued for the runner and not borrowed from a person:
env:
TEAM_MEMORY_TOKEN: ${{ secrets.TEAM_MEMORY_TOKEN }}We did not run this on a CI runner. The guide on headless and scheduled runs covers what else such a run starts without.
When a variable is not enough
Some teams do not want a long-lived token in an environment variable at all, or the token is short-lived and has to be fetched. Claude Code's headersHelper runs a command and uses the JSON it prints as headers:
{
"mcpServers": {
"memory": {
"type": "http",
"url": "https://memory.example.com/mcp",
"headersHelper": "./scripts/memory-headers.sh"
}
}
}Two behaviors decide how you write that script, and we measured both.
- It does not run in a folder that was not trusted. In a fresh folder,
claude -pexited 0 with the serverfailedand this on stderr:MCP server 'probe': headersHelper not run — this workspace has no persisted trust; accept the trust dialog here once interactively. The server received a request with noAuthorizationheader. A CI runner is exactly that folder. - It cannot read your token from the environment. For a helper that comes from
.mcp.json, Claude Code removes every variable "whose name looks like a credential", such as a name withTOKEN,SECRET,PASSWORD,KEYorAUTHin it. In the trusted lab folder, the helper ran withTEAM_MEMORY_TOKENexported and logged it as absent, while a variable namedMEMORY_WHOarrived. The docs say what to do: "have the script read its credential from a file or a credential store". The lab's helper read a file outside the repository and the server received that value.
A helper committed to the repository is a command every teammate runs on their machine. Keep it short enough to read in one screen. Codex documents http_headers_helper for the same job; we did not run it.
One token per person
The committed file makes it easy to hand everybody the same value. Do not. With one token for the team:
- Every write to the shared server has the same author, so "who saved this" has one answer for all of you.
- Revoking it, because a laptop was lost or someone left, disconnects everybody until each person updates their environment.
- Any copy that leaks is the team's whole access, and you cannot tell from the server's side whose copy it was.
One token per person costs each person one export line. The CI runner gets its own.
If a token is already in the history
In this order:
- Revoke the token on the server. This is the only step that ends the exposure. Deleting the line, force-pushing or rewriting history does not reach the clones and forks that already have it.
- Issue a new one and put it in the environment, not in the file. Replace the value in the file with the placeholder and commit.
- Read the server's log for the old token between the commit date and the revocation, if the server keeps one.
- Then decide about the history. Rewriting it is optional once the token is dead, and it costs every teammate a re-clone. Turn on your host's secret scanning or a pre-commit scanner so the next one is stopped before the push.
The same setup with ValorBrain
ValorBrain is a memory server for teams of agents, reached over MCP at one URL. The three files with it:
{
"mcpServers": {
"valorbrain": {
"type": "http",
"url": "https://mcpbrain.valor.digital/mcp",
"headers": { "Authorization": "Bearer ${VALORBRAIN_MCP_TOKEN}" }
}
}
}[mcp_servers.valorbrain]
url = "https://mcpbrain.valor.digital/mcp"
bearer_token_env_var = "VALORBRAIN_MCP_TOKEN"
required = true{
"mcpServers": {
"valorbrain": {
"url": "https://mcpbrain.valor.digital/mcp",
"headers": { "Authorization": "Bearer ${env:VALORBRAIN_MCP_TOKEN}" }
}
}
}What the product does about the rest of this guide:
- One token per person is the model, not a recommendation. Each person creates a
vbm_token under Settings → MCP tokens. The workspace comes from the token, so the committed file is the same for every team and carries no tenant id. See Tokens. - Agents are told apart by headers, not by tokens. One person running Claude Code, Codex and Cursor uses one token; the harness and the agent identify themselves with
X-ValorBrain-HarnessandX-Source-Agent. Those are not secrets, and the harness header is the same for everybody who uses a given file, so it can be committed with it. A CI runner or a nightly job is not a person: which credential a job should carry is in Tokens, where a personal token identifies a person, and gateway and integration credentials exist for systems without one. - Revocation is per token. The Revoke button in the app or
DELETE /api/v1/mcp/tokens/:idends one person's token and nobody else's. Rotation is: create a new one, swap it in your environment, revoke the old one. The server stores a sha256 of the token, not the token. See Token lifecycle. - There is a path with no token to paste. The server speaks OAuth 2.1 with dynamic client registration, so a client that supports it needs only the URL in the file and a sign-in per person. The Cursor page describes it.
- The first call says who you are.
memory_preparereturns your identity in the workspace, which is the quickest check that a teammate's export is theirs and not a value copied from a colleague.
Our own install pages paste the token on the command line for the user scope (claude mcp add --scope user … writes to ~/.claude.json) and into ~/.cursor/mcp.json. Both files are in your home directory, not in the repository. The placeholder form above is for when the entry moves into the repository. Both pages name the entry valorbrain, the same name as the project entry above, so in Claude Code the repository's entry replaces the one that already works: whoever installed from those pages exports VALORBRAIN_MCP_TOKEN before pulling the commit that adds .mcp.json.
What ValorBrain does not do
- It does not scan your repository. A
vbm_token committed by mistake is found by your git host's secret scanning or by you. Revoke it in the app. - It does not set the variable on anyone's machine. The preflight and
required = trueare what catch the teammate who skipped the export. - It does not expire a token created in the app. Such a token is valid until someone revokes it. Offboarding has to include the revocation.
- It does not decide trust or approval. Whether a cloned repository's server loads is the harness's decision, as in the first table.
- What we ran and what we did not. Every row in the two lab tables, the
claude mcp listandclaude mcp getoutput, the preflight, thejqgate, the twoheadersHelperruns and the threemcp addcommands, on one Linux machine, against a local probe server with dummy values. Our Codex was not signed in: its rows show what happened to the MCP connection at start, and no model turn ran. We did not run Cursor, in the editor or the CLI; its column is documentation only. We did not run a CI runner, the interactive approval prompt of Claude Code, Codex'shttp_headers_helper, a keychain command, or the three ValorBrain files with a real token: those follow from the lab (the variable name expands) and from the product's token pages.
Checklist
- No file in the repository holds a token value, and no placeholder for a token has a
:-default. - The variable has a name of your own, not one another tool already uses.
- Each person has their own token. The CI runner has its own.
- The setup notes say where to create the token, the export line, and the one-time approval or trust step for each harness.
- A preflight fails when the variable is missing or empty.
- Unattended runs fail when a server did not connect.
- If a token ever reached the history, it was revoked on the server before anything else.
Sources, read on November 30, 2026: Claude Code, MCP (project scope, scope precedence, environment variable expansion, credential variables that read as empty, headersHelper) and Run Claude Code programmatically; Codex, Model Context Protocol; Cursor, MCP and MCP in the CLI.
Next: Headless and scheduled agent runs for what a run with nobody watching starts with, CLAUDE.md, AGENTS.md and .cursor/rules in one repo for the instruction files that travel with the same checkout, and What a memory MCP server costs in context for what the server adds to every session once it does connect.
Headless and scheduled agent runs: what a cron or CI agent starts with, and where last night's result has to live
A run with nobody watching starts from what is on that machine: no terminal to ask, often no home directory, no memory of the run before. What Claude Code, Codex and Cursor document about instruction files, MCP servers, approvals, harness memory and sessions in non-interactive and scheduled runs, two small tests we ran, a 15-minute drill and where a nightly job has to keep what it found.
The run exited 0 and nothing was saved: what Claude Code and Codex do when an MCP server is slow or fails mid-run
A scheduled agent calls a memory server that answers 500, hangs or drops the connection, and the job is still green. What Claude Code, Codex and Cursor document about startup timeouts, tool-call timeouts and retries, what we measured against a local fault-injection server in 23 runs, and the timeout, the gate and the three lines of instruction that turn a silent miss into a failed job or a recovered write.