# Claude Code MCP Servers: Scopes, Security and Context Cost

> How to add MCP servers to Claude Code: pick a scope, share a .mcp.json, keep secrets out of it, block servers in scripts and limit context cost.

Canonical: https://bridge-terminal.com/atlas/blog/claude-code-mcp-servers-setup-scopes-security/
Last updated: 2026-11-24

Published 24 November 2026 · Technical · How-to · 7 min read

## The short version

- Add an MCP server to Claude Code with claude mcp add, and choose a scope: local (default, private to you), project (a .mcp.json shared through git) or user (all your projects).
- Keep credentials out of .mcp.json by using ${VAR} expansion, so the file is safe to commit and each engineer supplies their own secret.
- Project servers need approval in interactive sessions, but claude -p loads them without asking, so scripts and CI need an explicit block list or strict config.
- Tool search defers MCP tool definitions by default, so more servers cost little context, but tool output is still capped at 25,000 tokens by default.
- Anthropic does not security-audit or manage MCP servers; treat any server that fetches outside content as a prompt injection risk, and use allowlists or a managed config if a team needs control.

To add an MCP server to Claude Code, run `claude mcp add` with a transport, a name and a URL or command, then choose where the setting lives: local, project or user scope. Put shared servers in a `.mcp.json` file at the project root, keep secrets in environment variables, and let tool search keep the context cost low. This guide covers the commands, the scopes, the security checks and the limits, as documented in [Anthropic's Claude Code MCP reference](https://code.claude.com/docs/en/mcp).

MCP (Model Context Protocol) servers give the agent tools it does not have by default: an issue tracker, a database, a docs search. They also add risk and context cost, so it is worth setting them up deliberately instead of pasting commands from a README.

## How do I add an MCP server to Claude Code?

There are three common transports. HTTP is the recommended one for remote services, SSE is deprecated, and stdio runs a local process.

```bash
# Remote HTTP server
claude mcp add --transport http notion https://mcp.notion.com/mcp

# Remote server with a header
claude mcp add --transport http secure-api https://api.example.com/mcp \
  --header "Authorization: Bearer your-token"

# Local stdio server, with an environment variable
claude mcp add --env AIRTABLE_API_KEY=YOUR_KEY --transport stdio airtable \
  -- npx -y airtable-mcp-server
```

Two details trip people up. For stdio, the `--` separates Claude's own options from the server command, and everything after it is passed to the server untouched. And `--env` takes `KEY=value` pairs, so if the server name comes straight after `--env`, the CLI reads the name as another pair and rejects it. Put another option, such as `--transport stdio`, between `--env` and the name.

WebSocket servers cannot be added with `--transport`. Use `claude mcp add-json <name> '{"type":"ws","url":"wss://..."}'` instead.

Manage what you have added with these commands:

```bash
claude mcp list
claude mcp get notion
claude mcp remove notion
claude mcp login sentry     # OAuth from the shell
claude mcp logout sentry    # clear stored credentials
```

Inside a session, `/mcp` shows server status and lets you turn a server off without removing it.

## Which scope should an MCP server use?

Scope decides who gets the server. The default is local.

| Scope | Loads in | Shared | Stored in |
|---|---|---|---|
| Local (default) | Current project only | No | `~/.claude.json` |
| Project | Current project | Yes, via git | `.mcp.json` in the project root |
| User | All your projects | No | `~/.claude.json` |

```bash
claude mcp add --transport http stripe --scope local https://mcp.stripe.com
claude mcp add --transport http shared-server --scope project https://example.com/mcp
claude mcp add --transport http hubspot --scope user https://mcp.hubspot.com/anthropic
```

A practical split: servers the whole team needs to do the job (the issue tracker, the staging database reader) go in project scope. Anything experimental or tied to your own account stays local or user.

When the same server name is defined in more than one place, the order is local, then project, then user, then plugin-provided servers, then claude.ai connectors. The whole entry from the winning source is used. Fields are not merged, so a local override replaces the project entry completely.

## What goes in a shared .mcp.json?

A project-scope server is written to `.mcp.json`:

```json
{
  "mcpServers": {
    "shared-server": {
      "type": "http",
      "url": "https://example.com/mcp"
    }
  }
}
```

Always include `type` for a remote server. A `url` entry with no `type` is read as stdio and skipped.

### Keep secrets out with variable expansion

`.mcp.json` is committed, so never put a token in it. Claude Code expands `${VAR}` and `${VAR:-default}` in `command`, `args`, `env`, `url` and `headers`:

```json
{
  "mcpServers": {
    "api-server": {
      "type": "http",
      "url": "${API_BASE_URL:-https://api.example.com}/mcp",
      "headers": { "Authorization": "Bearer ${API_KEY}" }
    }
  }
}
```

Each engineer sets `API_KEY` in their own shell. Some behaviours to know:

- An unset variable with no default leaves the literal `${VAR}` text in place and shows a warning in `claude mcp list`.
- A variable set to an empty string counts as set, so `:-default` does not apply.
- In remote `url` and `headers`, credential variables such as `ANTHROPIC_API_KEY`, `ANTHROPIC_AUTH_TOKEN`, `AWS_BEARER_TOKEN_BEDROCK`, `HTTPS_PROXY` and `NPM_TOKEN` read as empty. A cloned project therefore cannot send your own credentials to a server it names. To pass one on purpose, copy it into a variable with your own name and reference that.

## Is a project MCP server safe to trust?

Not automatically. Anthropic reviews connectors before listing them in its directory, but does not security-audit or manage any MCP server. A server that returns a ticket body or a web page is handing untrusted text to the agent, which is how prompt injection reaches it.

Claude Code has some guardrails:

- Interactive sessions ask for approval before using servers from a project's `.mcp.json`. Reset your choices with `claude mcp reset-project-choices`.
- A cloned repository cannot approve its own servers. `enableAllProjectMcpServers` and `enabledMcpjsonServers` in a project's `.claude/settings.json` are ignored in an untrusted folder, and the server stays at "Pending approval".

The gap is automation. `claude -p`, Agent SDK and cloud sessions load project servers without an approval prompt. If you run the agent in scripts or CI, block servers explicitly in one of three ways:

1. Add the server to `disabledMcpjsonServers`, which blocks it in every permission mode.
2. Exclude project settings with `--setting-sources` (or `settingSources` in the SDK).
3. Start with `--strict-mcp-config`.

Pair this with permission rules for the tools themselves, since MCP tools go through the same allow and deny system as built-in ones.

### Controls for a team or organisation

By default anyone can connect any server. Administrators can change that with [managed MCP configuration](https://code.claude.com/docs/en/managed-mcp). The main patterns:

- `managed-mcp.json` deploys a fixed set and takes exclusive control. On Linux it lives at `/etc/claude-code/managed-mcp.json`. An empty `mcpServers` map disables MCP, apart from a few servers that still load under exclusive control.
- `managedMcpServers` in managed settings gives everyone a set of remote servers while users keep their own. It needs Claude Code v2.1.259 or later.
- `allowedMcpServers` and `deniedMcpServers` filter what users configure. Add `allowManagedMcpServersOnly: true` to make the managed allowlist the only one that counts.

```json
{
  "allowManagedMcpServersOnly": true,
  "allowedMcpServers": [
    { "serverUrl": "https://api.githubcopilot.com/*" },
    { "serverUrl": "https://*.internal.example.com/*" }
  ]
}
```

Match by `serverUrl` or `serverCommand`, not `serverName`. The docs state that a name is the label a user assigns, so a user can call any server `github`; it is not a security control. The denylist is checked first and nothing overrides a match.

## How much context do MCP servers cost?

Every tool definition a server exposes can take space in the context window. Claude Code handles this with tool search, which is on by default: only tool names and server instructions load at session start, and definitions are fetched when the agent needs them. There is no fixed per-server tool cap; the practical limit is your context budget.

You can tune it with `ENABLE_TOOL_SEARCH`:

| Value | Behaviour |
|---|---|
| unset or `true` | All MCP tools deferred and loaded on demand |
| `auto` | Tools load upfront while their definitions total under 10% of the context window; tool search turns on at 10% or more |
| `auto:N` | Same, with your own percentage, 0 to 100 |
| `false` | All MCP tools loaded upfront |

```bash
ENABLE_TOOL_SEARCH=auto:5 claude
```

Tool search applies on Opus 4, Sonnet 4, Haiku 4.5 and later models; on earlier models everything loads upfront. If a server has a few tools the agent needs on every turn, set `"alwaysLoad": true` on that server in `.mcp.json` so they skip the search step. Use it sparingly, since each upfront tool uses context. Run `/context` in a session to see which tools are loaded and which are deferred.

If you write servers, keep descriptions short and put the important words first. Server instructions and the description of an upfront tool are cut at 4,096 characters; a tool loaded through search is cut at 16,384.

## What happens when a tool returns a huge result?

Output is capped separately from definitions:

- The transcript viewer warns when any MCP tool output exceeds 10,000 tokens.
- The default maximum is 25,000 tokens, adjustable with `MAX_MCP_OUTPUT_TOKENS`.
- A successful text result over the limit is saved to a file in the session's `tool-results` directory under `~/.claude/projects/`, and the conversation gets the file path instead.
- Independent of tokens, a text result over 50,000 characters is also saved to a file unless the tool sets `anthropic/maxResultSizeChars`.

```bash
export MAX_MCP_OUTPUT_TOKENS=50000
claude
```

Raising the limit puts more text into the conversation on every call. Before you do, ask whether the server can paginate or filter. For slow servers, `MCP_TIMEOUT` sets the startup timeout, `MCP_TOOL_TIMEOUT` the tool timeout, and a per-server `"timeout"` in milliseconds works in `.mcp.json`.

## A short setup checklist

1. Decide the scope: project for team tools, local or user for the rest.
2. Add the server with `claude mcp add`, and confirm with `claude mcp list`.
3. Replace any literal token with `${VAR}` and document the variable in the README.
4. Commit `.mcp.json`; tell the team to expect an approval prompt.
5. In scripts and CI, block project servers you do not want loaded.
6. Check `/context` and keep only what the agent uses on most tasks.
7. Treat servers that read outside text as untrusted input.

## How Atlas relates

[Atlas](https://bridge-terminal.com/atlas/) is a team of AI engineers built on Claude Code, and it keeps context lean in a related way: each engineer loads only the tools its role uses, and the project's instructions once. On the makers' measurements a builder's first turn went from about 31k tokens to 11k. Choosing which MCP servers each role loads, with approval handled for you, is coming to Atlas, built in, so it needs no setup. Until then, follow the scope and approval steps above in the project's own Claude Code setup.

## Conclusion

MCP servers are useful, but they are code and text from outside your repo. Pick the narrowest scope that works, keep secrets in variables, remember that `-p` skips the approval prompt, and let tool search carry the context cost. Review `/mcp` and `/context` now and then, and remove servers nobody uses.

## Questions people ask

### How do I add an MCP server to Claude Code?

Run claude mcp add with a transport, a name and a URL, for example claude mcp add --transport http notion https://mcp.notion.com/mcp. For a local server use --transport stdio and put the server command after a -- separator.

### What is the difference between local, project and user scope for MCP?

Local, the default, applies to the current project only and is private to you. Project scope writes to .mcp.json so the team shares it through git. User scope loads in all your projects but is not shared.

### How do I keep API keys out of .mcp.json?

Use ${VAR} expansion in url, headers, args, env or command, and have each engineer set the variable in their own shell. An unset variable with no default stays as literal text and shows a warning in claude mcp list.

### Do MCP servers use up Claude Code's context window?

Little, by default. Tool search is on by default, so only tool names and server instructions load at start and definitions are fetched on demand. Tool output is capped at 25,000 tokens by default, adjustable with MAX_MCP_OUTPUT_TOKENS.

### Does claude -p ask before loading project MCP servers?

No. Print mode and Agent SDK sessions load project servers without a prompt. To block one, add it to disabledMcpjsonServers, exclude project settings with --setting-sources, or use --strict-mcp-config.

## About Atlas: Atlas keeps each engineer's tool list short

Atlas engineers each load only the tools their role uses, and the project's instructions once, which is the same context discipline this guide recommends. Choosing which MCP servers each role loads is coming to Atlas, built in, so it needs no setup. Until then, set it up in the project's Claude Code configuration. — https://bridge-terminal.com/atlas/

## Sources

- [Connect Claude Code to tools via MCP](https://code.claude.com/docs/en/mcp)
- [Control MCP server access for your organization](https://code.claude.com/docs/en/managed-mcp)

_Researched and drafted with Claude, then checked against the sources above. Atlas is an independent product, not affiliated with Anthropic or OpenAI._

## Related

- [MCP Servers in Claude Code: Connect Databases and Tools](https://bridge-terminal.com/atlas/blog/mcp-servers-claude-code-explained/)
- [Claude Code Status Line: Show Context, Cost and Limits](https://bridge-terminal.com/atlas/blog/claude-code-status-line-context-cost-limits/)
- [API Keys and Secrets in AI-Built Software: A Plain Guide](https://bridge-terminal.com/atlas/blog/api-keys-secrets-ai-built-software-plain-guide/)
