> ## Content Index
> Fetch the complete content index at: https://claudefox.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to add MCP servers to Claude Code: scopes, .mcp.json, OAuth and fixes
- URL: https://claudefox.com/claude-code-mcp-setup/
- Published: 2026-11-22T08:22:59.000Z
- Updated: 2026-11-22T08:24:10.000Z
- Description: How to add MCP servers to Claude Code, checked against Anthropic's docs on Nov 20, 2026: claude mcp add transports, local, project and user scopes, .mcp.json, keeping keys in environment variables, OAuth sign-in, approving project servers, fixing failed connections, and two worked examples.
- Author: hupicake
- Tags: Tips

Last checked: 2026-11-20, against Anthropic's Claude Code docs: Connect Claude Code to tools via MCP, the Connect to MCP servers quickstart and the environment variables reference. The newest Claude Code release that day was 2.1.329\. The two worked examples are ours, built from each server's own README; neither puts a key in your repository.

Short answer: run claude mcp add in your shell, not inside a session. For a remote server it is claude mcp add --transport http <name> <url>; for a local one it is claude mcp add <name> -- <command>. Then check it with claude mcp list, or /mcp inside Claude Code.

Before adding any server, check that you trust it: Anthropic's docs warn that servers which fetch external content can expose you to prompt injection.

## What does claude mcp add do?

It writes a server entry to a config file and prints an Added line; it does not check your credentials, so a wrong token only shows up later as a failed connection.

```
# Remote server over HTTP (recommended for remote servers)
claude mcp add --transport http <name> <url>

# Remote server with a static header
claude mcp add --transport http <name> <url> --header "Authorization: Bearer <token>"

# Local stdio server: everything after -- is the server's own command
claude mcp add <name> --env KEY=value -- npx -y <package>
```

- http: the docs' recommended transport for remote servers. In JSON, "type": "streamable-http" is accepted as an alias for http.
- sse: deprecated. Since v2.1.265, adding an SSE-only server with --transport http falls back to SSE automatically; --transport sse still forces it.
- stdio: a local process. The -- separates Claude Code's own options from the server command, so flags like -y reach npx. If you put the name right after --env KEY=value, the CLI reads it as another pair, so name the server first.
- ws (WebSocket): only through .mcp.json or claude mcp add-json, because --transport does not accept ws, and it supports no OAuth.
- Short forms: -t for --transport, -H for --header, -e for --env, -s for --scope.

For a server whose instructions only give an mcpServers JSON block, pass the object inside mcpServers to claude mcp add-json <name> '<json>'. Since v2.1.327 you can pipe the JSON in with - in its place, which keeps a token off the command line. On macOS or WSL, claude mcp add-from-claude-desktop copies servers from Claude Desktop.

## Local, project or user scope: which should you use?

Use local (the default) for a server only you need in this project, project to share it with your team through git, and user for a server you want in every project. Pick the scope with --scope or -s.

__MCP installation scopes, from Anthropic's MCP docs, Nov 20, 2026__
| Scope           | Loads in             | Shared with team         | Stored in                                  |
| --------------- | -------------------- | ------------------------ | ------------------------------------------ |
| local (default) | Current project only | No                       | \~/.claude.json, under that project's path |
| project         | Current project only | Yes, via version control | .mcp.json in the project root              |
| user            | All your projects    | No                       | \~/.claude.json                            |

When one name is defined in several places, Claude Code connects once, using the whole entry from the highest source: local, then project, then user, then plugin servers, then claude.ai connectors. Fields are not merged. A server your organization supplies through managed settings ranks above all of these (v2.1.259 or later).

## What does a .mcp.json file look like?

It is one mcpServers object. Each entry has a type plus a url for remote servers, or a command and args for stdio servers. This two-server file is the one in Anthropic's quickstart:

```
{
  "mcpServers": {
    "claude-code-docs": {
      "type": "http",
      "url": "https://code.claude.com/docs/mcp"
    },
    "playwright": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@playwright/mcp@latest"]
    }
  }
}
```

- Claude Code reads .mcp.json when a session starts, so restart after editing it.
- An entry with a url but no type is an error: with no type, Claude Code treats the entry as stdio. Add "type": "http", "sse" or "ws".
- Server names may use letters, numbers, hyphens and underscores. Built-in names such as workspace and computer-use are reserved.
- Claude Code does not read \~/.claude/mcp.json, \~/.claude/.mcp.json or similar paths. User servers belong in \~/.claude.json; add them with claude mcp add --scope user.
- A malformed entry is skipped while the others load; claude mcp list shows the parse warning.

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

Reference environment variables instead of pasting values: ${VAR}, or ${VAR:-default} for a fallback, works in a server's command, args, env, url and headers. Each person sets the real value in their own shell, and the committed file holds only the name.

- An unset variable with no default does not stop the server loading: Claude Code warns in claude mcp list and /mcp and uses the literal ${VAR} text.
- A variable set to an empty string counts as set, so ${VAR:-default} expands to empty, not to the default.
- In a remote server's url and headers, credential variables such as ANTHROPIC\_API\_KEY, ANTHROPIC\_AUTH\_TOKEN, AWS\_BEARER\_TOKEN\_BEDROCK and NPM\_TOKEN always read as empty, so a repository cannot forward your Claude credentials. Copy a value into a variable with your own name if a server really needs it.
- claude mcp list, claude mcp get and the /mcp detail view show ${VAR} references by name, not the resolved value.
- Claude Code warns about hidden leading or trailing whitespace in values such as headers.Authorization, a common result of pasting a token.

## How does OAuth sign-in work for remote MCP servers?

Add the server without an auth header, then run /mcp in a session and sign in when your browser opens, or run claude mcp login <name> from your shell. Claude Code stores the tokens and refreshes them. A server you have not signed in to that answers 401 or 403 is flagged in /mcp as needing authentication.

- If you configured an Authorization header and the server rejects it, Claude Code reports a failed connection and does not fall back to OAuth. Remove the header to use OAuth.
- Over SSH or without a display, claude mcp login prints the URL instead; paste the redirect URL back at the prompt. --no-browser forces this.
- claude -p and Agent SDK runs cannot open the OAuth flow. Sign in once from an interactive session first.
- Servers that need a pre-registered redirect take --callback-port. Servers without dynamic client registration take --client-id plus --client-secret, which prompts with masked input and stores the secret in the macOS keychain or a credentials file.
- claude mcp remove deletes the stored tokens but does not revoke them. Run claude mcp logout <name> first to revoke them where the server supports it.

## How do you check that a server is connected?

Run claude mcp list from your shell, or /mcp inside a session. Each server shows a status such as Connected, Needs authentication or Failed to connect, and /mcp also lets you reconnect, sign in or disable a server.

- claude mcp get <name> shows one server's details and, on a failure, an Issue line with the HTTP status or error code.
- Pending approval means a .mcp.json server you have not approved yet. Disabled for this project means you switched it off in /mcp, which records it in \~/.claude.json without deleting the config.
- /mcp reconnect all retries every failed server (v2.1.284 or later).

## How do you approve project servers from .mcp.json?

Start claude interactively in the project and approve the servers when asked. Until then they show as Pending approval. If you dismissed the prompt, run claude mcp reset-project-choices and restart to see it again.

- A cloned repository cannot approve its own servers: enableAllProjectMcpServers or enabledMcpjsonServers committed to .claude/settings.json is ignored until you accept the folder's workspace trust dialog.
- Approvals in your user \~/.claude/settings.json, managed settings or a file passed with --settings still apply in an untrusted folder.
- claude -p runs and Agent SDK sessions load project servers without asking. To keep one out anyway, list it in disabledMcpjsonServers, or start with --strict-mcp-config and pass only the servers you want with --mcp-config.

## Why won't my MCP server connect?

Start with the failure detail that claude mcp list and claude mcp get print, then test the server outside Claude Code. The detail often names the problem directly, such as a rejected token or a wrong path.

- /mcp shows no servers: you added a local-scope server from a different project, edited a file Claude Code does not read, or wrote a malformed entry.
- Failed to connect on an HTTP server: run curl -I <url>. A 404 or 405 means the server is up (many endpoints accept only POST); 401 or 403 means you need to authenticate; no answer points at the URL or your network. A 404 inside Claude Code usually means a wrong path: compare claude mcp get with the server's documented endpoint.
- Failed on a stdio server: run its command yourself, for example npx -y @playwright/mcp@latest. If it starts and waits, compare it with the command claude mcp get shows; a mismatch usually means a missing --.
- Timed out at startup: the default is 30 seconds, and a first npx download can be slow. Start with MCP\_TIMEOUT=60000 claude. MCP\_TIMEOUT covers startup only; slow tool calls fall under MCP\_TOOL\_TIMEOUT or a per-server timeout field in .mcp.json.
- Connects but lists no tools: usually a missing environment variable such as an API key. Add it with --env or in the entry's env field.
- Already exists: remove the old entry, or pass --scope to say which copy to remove.

## Example 1 (ours): Playwright MCP as a local server

Playwright MCP (microsoft/playwright-mcp) lets Claude drive a browser through accessibility snapshots. Its README gives claude mcp add playwright npx @playwright/mcp@latest. Our version adds the -- separator Anthropic's docs ask for, -y as in Anthropic's quickstart, and two flags from the README's option table:

```
# Our example: headless browser, profile kept in memory only
claude mcp add playwright -- npx -y @playwright/mcp@latest --headless --isolated

# Check it
claude mcp get playwright
```

Its README asks for Node.js 20 or newer (Anthropic's quickstart says 18 or later; use 20). --headless runs the browser without a window (it is headed by default), and --isolated keeps the browser profile in memory and does not save it to disk. The browser can reach any site by default; the README's --allowed-origins option narrows that, but the README says it is not a security boundary. In a session, ask Claude to open a page and report its title, then check /mcp for a tool count.

## Example 2 (ours): Context7 shared with your team

Context7 (upstash/context7) feeds current library docs into Claude's context. Its README gives the endpoint https://mcp.context7.com/mcp and an Authorization: Bearer header, and recommends a free API key for higher rate limits. Committing this .mcp.json gives the server to everyone while each person keeps their own key:

```
{
  "mcpServers": {
    "context7": {
      "type": "http",
      "url": "https://mcp.context7.com/mcp",
      "headers": {
        "Authorization": "Bearer ${CONTEXT7_API_KEY}"
      }
    }
  }
}
```

```
# CONTEXT7_API_KEY is our name, matching the JSON above, not one from the README.
# Each teammate adds it to ~/.zshrc or ~/.bashrc:
export CONTEXT7_API_KEY=<your key from the Context7 dashboard>
claude   # approve the project server when prompted, then run /mcp
```

If you would rather not handle the key yourself, the README's npx ctx7 setup --claude signs you in with OAuth, generates the key, and installs either a CLI-plus-skill setup or the MCP server; the ctx7 CLI needs Node.js 22.13 or newer.

## Frequently asked questions

- Where are my MCP servers stored? Local and user servers are in \~/.claude.json; project servers are in .mcp.json at the project root.
- Do I need to restart after adding a server? After editing .mcp.json by hand, yes: the file is read at session start. Anthropic's quickstart runs claude mcp add from the shell and then starts a session to use the server.
- Can I use an MCP server in claude -p? Yes. Project servers load without the approval prompt there, but OAuth sign-in must be done in an interactive session first.
- How do I turn a server off without deleting it? Toggle it off in /mcp. Claude Code records that per project in \~/.claude.json and keeps the configuration.

## Related on claudefox

- [Best Claude Code MCP servers and skills (Nov 2026): 25 picks by job](https://claudefox.com/best-claude-code-mcp-servers-and-skills/)
- [How to install Claude Code on Mac, Windows and Linux](https://claudefox.com/install-claude-code/)
- [Claude Code not working? Fixes for common errors](https://claudefox.com/claude-code-troubleshooting/)
- [Claude Code hooks and subagents: a practical guide](https://claudefox.com/claude-code-hooks-and-subagents/)
- [CLAUDE.md: what to put in it, where it lives, and examples](https://claudefox.com/claude-md-guide/)
- [Claude Code version history: all 47 releases since Sep 18, 2026](https://claudefox.com/claude-code-version-history/)

Source: [Connect Claude Code to tools via MCP (Claude Code docs)](https://code.claude.com/docs/en/mcp?ref=claudefox.com), [Connect to MCP servers: quickstart (Claude Code docs)](https://code.claude.com/docs/en/mcp-quickstart?ref=claudefox.com), [Environment variables (Claude Code docs)](https://code.claude.com/docs/en/env-vars?ref=claudefox.com), [Claude Code changelog](https://code.claude.com/docs/en/changelog?ref=claudefox.com), [Playwright MCP README (microsoft/playwright-mcp)](https://github.com/microsoft/playwright-mcp?ref=claudefox.com), [Context7 README (upstash/context7)](https://github.com/upstash/context7?ref=claudefox.com)