Claude Code MCP: add servers, pick scopes, sign in and fix errors

Claude Code MCP: add servers, pick scopes, sign in and fix errors

Claude Code connects to outside tools through MCP servers, which you add with claude mcp add and manage with /mcp. This guide covers the three transports, the three scopes and where each is stored, OAuth and token sign-in, permission rules for MCP tools, context limits, unattended runs and a troubleshooting table keyed to the exact error messages.

In shortTL;DR
  • Add a remote server with claude mcp add --transport http <name> <url> and a local one with claude mcp add <name> -- <command>; everything after -- is the server's own command.
  • Scopes decide who gets a server: local (default, you, this project) and user (you, all projects) live in ~/.claude.json; project scope is a committed .mcp.json in the repo root.
  • Sign in to OAuth servers with /mcp or claude mcp login <name>; pass static tokens with --header, and never commit secrets, use ${VAR} expansion instead.
  • Control what MCP tools may do with permission rules such as mcp__github__get_*, and use read-only credentials for databases.
  • In claude -p runs, project .mcp.json servers load without asking, so pin the server list with --strict-mcp-config for unattended work.

What does MCP do in Claude Code?

MCP (Model Context Protocol) lets Claude Code call tools that live outside your repository: an issue tracker, a browser, a database, your error monitor. Each connected MCP server adds tools, and Claude decides when to call them, the same way it decides when to run a shell command or edit a file.

With a few servers connected you can write prompts like these, taken from the Claude Code MCP docs:

  • "Add the feature described in JIRA issue ENG-4521 and create a PR on GitHub."
  • "Check Sentry and Statsig to check the usage of the feature described in ENG-4521."
  • "Find emails of 10 random users who used feature ENG-4521, based on our PostgreSQL database."

Inside Claude Code, every MCP tool gets a name of the form mcp__<server>__<tool>, for example mcp__github__create_issue. You will see that name in permission prompts, in permission rules and in hook matchers. Servers can also expose resources you reference with @, like files, and prompts that show up as slash commands named /mcp__<server>__<prompt>. If the protocol itself is new to you, start with our explainer on what MCP is.

How do you add an MCP server to Claude Code?

You add a server from your shell (not inside a session) with claude mcp add, then check it with claude mcp list. The command form depends on where the server runs.

TransportWhere the server runsAdd it with
http (recommended for remote)A URL hosted by the vendorclaude mcp add --transport http <name> <url>
stdio (default)A local process Claude Code startsclaude mcp add <name> -- <command> [args]
sse (deprecated)An older remote endpointclaude mcp add --transport sse <name> <url>
wsA remote server that pushes eventsclaude mcp add-json only

Follow these steps for your first server. The official Claude Code docs server needs no account, so it is a clean test:

  1. Add it: claude mcp add --transport http claude-code-docs https://code.claude.com/docs/mcp
  2. Check it: claude mcp list should show ✔ Connected.
  3. Start a session with claude and ask: "Use the claude-code-docs server to look up what MCP_TIMEOUT does".
  4. Approve the first tool call when Claude Code asks.
  5. Remove it later with claude mcp remove claude-code-docs if you don't need it.

A local stdio server works the same way, with the launch command after a double dash:

terminal
# A browser Claude can drive (needs Node.js 18+)claude mcp add playwright -- npx -y @playwright/mcp@latest# A server that needs an API key in its environmentclaude mcp add --transport stdio --env AIRTABLE_API_KEY=YOUR_KEY airtable \  -- npx -y airtable-mcp-server

The -- matters. Without it, Claude Code tries to parse the server's flags (such as -y or --port) as its own options. Also keep --env away from the server name: if the name comes directly after --env, the CLI reads it as another KEY=value pair and rejects it, so put another option like --transport stdio in between.

Setup instructions written for Cursor or Claude Desktop still work. A URL means an HTTP server, an npx or uvx line means a stdio server, and an mcpServers JSON block goes to claude mcp add-json <name> '<json>' (pass the inner object, not the mcpServers wrapper). If you already configured servers in Claude Desktop, claude mcp add-from-claude-desktop imports them on macOS and WSL.

Local, project or user scope: where does Claude Code store MCP config?

The scope you pick when adding a server decides which projects load it and whether teammates get it. Local is the default.

ScopeFlagLoads inShared?Stored in
Local--scope local (default)This project onlyNo~/.claude.json, under the project's path
Project--scope projectThis project onlyYes, via git.mcp.json in the project root
User--scope userAll your projectsNo~/.claude.json, top-level mcpServers

Two facts clear up most confusion online. First, local and user scope both live in ~/.claude.json in your home directory, not in .claude/settings.local.json. Second, Claude Code does not read ~/.claude/mcp.json, ~/.claude/.mcp.json or %APPDATA%\Claude\mcp.json; the quickstart's troubleshooting section lists these as common wrong paths.

When the same server name exists in several places, Claude Code uses the whole entry from the highest one and does not merge fields: local beats project, project beats user, and user beats plugin servers and claude.ai connectors. A scope is fixed once set, so to move a server, remove it (claude mcp remove <name> --scope local) and add it again with the new --scope.

Writing .mcp.json for a team

A committed .mcp.json is configuration as code for everyone on the project. Use ${VAR} or ${VAR:-default} so secrets stay in each person's environment:

.mcp.json
{  "mcpServers": {    "sentry": {      "type": "http",      "url": "https://mcp.sentry.dev/mcp"    },    "internal-api": {      "type": "http",      "url": "${API_BASE_URL:-https://api.example.com}/mcp",      "headers": { "Authorization": "Bearer ${INTERNAL_API_TOKEN}" }    },    "playwright": {      "type": "stdio",      "command": "npx",      "args": ["-y", "@playwright/mcp@latest"]    }  }}

Every remote entry needs a type. An entry with a url but no type is read as a stdio server, so Claude Code skips it with an error telling you to add "type": "http". Variables work in command, args, env, url and headers. Claude Code reads .mcp.json at session start, so restart after editing it.

Code editor open on a laptop screen in a dark room
Project-scoped servers live in a .mcp.json file that sits in the repository next to your code.

How do you sign in to MCP servers that need authentication?

Remote servers authenticate in one of two ways: an OAuth sign-in in your browser, or a token you pass as a header. Claude Code handles OAuth itself and stores and refreshes the tokens.

For OAuth servers such as Sentry, Linear or Notion:

  1. Add the server: claude mcp add --transport http sentry https://mcp.sentry.dev/mcp. claude mcp list now shows ! Needs authentication, which is expected.
  2. Start claude, run /mcp, select the server and choose Authenticate.
  3. Approve access in the browser window. The status changes to connected.

On a remote machine over SSH there is no browser. Run claude mcp login sentry --no-browser from an interactive shell (connect with ssh -t), open the printed URL on your own computer, then paste the full redirect URL back at the prompt. claude mcp logout <name> clears the stored credentials.

For token-based servers, pass the header when you add them. GitHub's remote server takes a fine-grained personal access token:

terminal
claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \  --header "Authorization: Bearer $GITHUB_PAT"

claude mcp add saves the entry without testing the token, so a wrong token only shows up later as a failed connection with a 401 in the detail. For short-lived tokens or company SSO, a headersHelper command in the server entry generates headers at connect time.

Warning

Claude Code deliberately expands its own and your cloud provider's credential variables, such as ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN and NPM_TOKEN, to an empty string inside a remote server's url and headers. That stops a repository's .mcp.json from sending your keys to a server it names. If you need one of those values, copy it into a variable with your own name.

How do you control what MCP tools are allowed to do?

MCP tools go through the same permission system as Bash and file edits: Claude Code asks before the first call, and rules in your settings can allow, ask or deny by tool name. The permissions docs define the syntax.

.claude/settings.json
{  "permissions": {    "allow": ["mcp__claude-code-docs__*", "mcp__sentry__*"],    "ask": ["mcp__github__*"],    "deny": ["mcp__airtable__*"]  }}

Rules to know:

  • mcp__github and mcp__github__* both match every tool on the github server; mcp__github__get_* matches only its get_ tools.
  • Allow globs work only after a literal mcp__<server>__ prefix. An allow rule of mcp__* is skipped and approves nothing, while mcp__* as a deny rule blocks every MCP tool.
  • Characters such as . or spaces in a server name become _ in rules.
  • To turn a server off without deleting it, toggle it in /mcp. To reject a .mcp.json server by name in every session, add it to disabledMcpjsonServers in your settings.

Project servers have one extra gate. The first time Claude Code sees a server in a project's .mcp.json, it asks you to approve it, because a stdio entry launches a program on your machine. A cloned repository cannot pre-approve its own servers: approval settings committed in its .claude/settings.json are ignored until you trust the folder. If you rejected one by mistake, claude mcp reset-project-choices resets the choices.

The bigger risk is what servers read. A server that fetches web pages, issues or emails can bring in text written by someone else, and that text can contain instructions aimed at the agent. Our guide to prompt injection in coding agents covers the defenses; the short version is to install servers from the vendor of the service, give database servers a read-only user, and use deny rules for write tools you never want called unattended.

How much context do MCP servers use?

On current models, Claude Code loads MCP tools on demand with tool search, so connecting more servers costs little context. Only tool names and server instructions go in at startup; full tool definitions load when Claude needs them.

You can change that with the ENABLE_TOOL_SEARCH environment variable: false loads every tool upfront, auto loads tools upfront until they would take 10% of the context window, and auto:5 sets that threshold to 5%. Leave it unset unless you have a reason.

Tool results are the other cost. Claude Code applies these limits by default:

10,000tokens: output size that triggers a warning
25,000tokens: default maximum MCP output
30 sdefault server startup timeout
Source: Claude Code docs, MCP and MCP quickstart (November 2026)

Raise the output cap with MAX_MCP_OUTPUT_TOKENS=50000 claude when a server legitimately returns large results. Results over the limit are saved to a file and Claude reads it when needed. A tool call that runs past two minutes in the main conversation moves to a background task, and a per-server timeout field in milliseconds caps how long one call may run.

Which MCP servers are worth adding first?

Start with two or three servers that match work you already do every day, and add more when a task needs them. These examples come from the official docs and have known, working commands:

JobServerCommand
Look up Claude Code featuresClaude Code docsclaude mcp add --transport http claude-code-docs https://code.claude.com/docs/mcp
Test pages in a real browserPlaywrightclaude mcp add playwright -- npx -y @playwright/mcp@latest
Issues, PRs, code searchGitHubclaude mcp add --transport http github https://api.githubcopilot.com/mcp/ --header "Authorization: Bearer $GITHUB_PAT"
Production errorsSentryclaude mcp add --transport http sentry https://mcp.sentry.dev/mcp
Notes and specsNotionclaude mcp add --transport http notion https://mcp.notion.com/mcp
Query a databaseDBHubclaude mcp add db -- npx -y @bytebase/dbhub --dsn "postgresql://readonly:pass@host:5432/db"

For a longer list grouped by job, with safety notes per server, see our roundup of the best MCP servers. Reviewed remote servers are also listed in the Anthropic Directory, and the MCP server guide explains how to write your own when nothing fits.

Claude Code MCP troubleshooting: what do the errors mean?

Most MCP failures show up as a status in claude mcp list or /mcp, and each status points to a different fix. Start with claude mcp get <name>, which shows the configured command or URL and the error detail.

SymptomLikely causeFix
/mcp says no servers configuredServer added in another project at local scope, or config at a wrong pathRe-add from this project, or use --scope user
✘ Failed to connect (stdio)The command fails or -- was missingRun the command by hand, e.g. npx -y @playwright/mcp@latest; re-add with --
✘ Failed to connect (HTTP)Wrong URL or rejected tokencurl -I <url>: 404 or 405 means it is up, 401 or 403 means auth
! Needs authenticationOAuth not done yet/mcp, select the server, Authenticate
⏸ Pending approvalProject server not approvedRun claude in the project and approve
Times out at startupFirst npx download is slowMCP_TIMEOUT=60000 claude
Connected but no toolsMissing environment variableAdd --env KEY=value or the env field
.mcp.json edits ignoredFile read at startup onlyRestart the session; check claude mcp list for parse warnings
"already exists"Same name at the same scopeclaude mcp remove <name> first

For anything else, start Claude Code with claude --debug='mcp' to log only MCP activity. In PowerShell, set a variable before the command on one line ($env:MCP_TIMEOUT = "60000"; claude) and use curl.exe rather than the curl alias.

How do MCP servers work in headless and unattended runs?

Headless runs with claude -p have no /mcp panel and no approval prompt, so you need to sign in and decide on the server list before the run starts. Our guide to Claude Code headless mode covers the rest of the setup.

Three rules from the docs:

  • Sign in first. OAuth cannot run inside claude -p. Complete sign-in once with /mcp or claude mcp login <name> in an interactive shell.
  • Project servers load without asking. In claude -p runs, servers from the project's .mcp.json connect without the approval prompt. For untrusted repositories, pass --strict-mcp-config --mcp-config ./mcp.json so only the servers you list load, or use --setting-sources user to skip project settings entirely.
  • Deny write tools you never want called alone. A deny rule holds in every permission mode, which makes it the right tool for a database write or a "merge" action.
terminal
claude -p "Triage the newest Sentry issue and open a draft PR with a fix" \  --strict-mcp-config --mcp-config ./mcp.ci.json \  --disallowedTools "mcp__github__merge_pull_request"

Long agent runs that call MCP servers need a machine that stays awake. Orkio rents an always-on, isolated cloud box where Claude Code keeps working after you close your laptop, using your own Claude account, and a .mcp.json committed to your repository comes along when the agent clones it.

Claude Code MCP setup checklist

Use this list to go from zero to a server you trust in about ten minutes:

  1. Pick one server that matches a daily task (issues, errors, a browser or docs).
  2. Add it with claude mcp add, using --transport http for URLs and -- before local commands.
  3. Choose the scope on purpose: local to try it, user for personal tools, project to share.
  4. Run claude mcp list and fix anything that is not ✔ Connected.
  5. Sign in with /mcp or claude mcp login, and keep tokens in environment variables.
  6. Add allow, ask and deny rules for the server's tools in .claude/settings.json.
  7. Commit .mcp.json only with ${VAR} placeholders, never real secrets.
  8. Before any unattended run, pin servers with --strict-mcp-config and deny write tools. For automatic checks around tool calls, add Claude Code hooks with an mcp__<server>__.* matcher.

Frequently asked questions

Where is the Claude Code MCP config file?

Local and user scoped servers are stored in ~/.claude.json in your home directory, and project scoped servers in a .mcp.json file at the project root. Claude Code does not read files such as ~/.claude/mcp.json or ~/.claude/.mcp.json, which some older guides mention. Run claude mcp get with the server name to see which scope holds it.

Do I need to restart Claude Code after adding an MCP server?

Servers added with claude mcp add are picked up when you start a new session. If you edit .mcp.json by hand, exit and restart the session, because Claude Code reads that file at startup. Inside a session, the /mcp panel lets you reconnect or re-authenticate a server without restarting.

Can I use my Claude Desktop MCP servers in Claude Code?

Yes. Run claude mcp add-from-claude-desktop on macOS or WSL and pick the servers to import. Server names may contain only letters, numbers, hyphens and underscores, so a Desktop server with a space in its name is skipped and needs a new name.

Do claude.ai connectors work in Claude Code?

If you sign in to Claude Code with a claude.ai account, connectors you added at claude.ai appear automatically in the /mcp list, marked as coming from claude.ai. On Team and Enterprise plans only admins can add connectors. You can disable them per project from the /mcp panel.

How many MCP servers can Claude Code use at once?

There is no fixed per-server tool cap. With tool search, which is on by default, only tool names and server instructions load at startup, so extra servers cost little context. The practical limit is your context window and the time servers take to start.

Is it safe to approve a .mcp.json from a cloned repository?

Treat it like running code from that repository, because a stdio entry launches a program on your machine. Read the file first, check that each server comes from the vendor it claims, and reject anything you do not recognize. A cloned repository cannot approve its own servers until you trust the folder.

SOURCES

  1. Claude Code docs: Connect Claude Code to tools via MCP
  2. Claude Code docs: Connect to MCP servers (quickstart)
  3. Claude Code docs: Configure permissions
  4. Claude Code docs: CLI reference
  5. Model Context Protocol: Build an MCP server
  • #claude code
  • #mcp
  • #ai coding
  • #developer tools
Orkio team

The team building Orkio. We write about putting AI to work: coding agents that run overnight, always-on boxes and pull requests ready by morning.

Keep reading

All posts

07:06 · YOU MERGED #128

Go to sleep. Wake up to pull requests.

Start for $19 a month
© 2026 Orkio · Hosted in Europe TürkçeStatus