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.
- Add a remote server with
claude mcp add --transport http <name> <url>and a local one withclaude 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.jsonin the repo root. - Sign in to OAuth servers with
/mcporclaude 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 -pruns, project.mcp.jsonservers load without asking, so pin the server list with--strict-mcp-configfor 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.
| Transport | Where the server runs | Add it with |
|---|---|---|
http (recommended for remote) | A URL hosted by the vendor | claude mcp add --transport http <name> <url> |
stdio (default) | A local process Claude Code starts | claude mcp add <name> -- <command> [args] |
sse (deprecated) | An older remote endpoint | claude mcp add --transport sse <name> <url> |
ws | A remote server that pushes events | claude 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:
- Add it:
claude mcp add --transport http claude-code-docs https://code.claude.com/docs/mcp - Check it:
claude mcp listshould show✔ Connected. - Start a session with
claudeand ask: "Use the claude-code-docs server to look up what MCP_TIMEOUT does". - Approve the first tool call when Claude Code asks.
- Remove it later with
claude mcp remove claude-code-docsif you don't need it.
A local stdio server works the same way, with the launch command after a double dash:
# 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-serverThe -- 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.
| Scope | Flag | Loads in | Shared? | Stored in |
|---|---|---|---|---|
| Local | --scope local (default) | This project only | No | ~/.claude.json, under the project's path |
| Project | --scope project | This project only | Yes, via git | .mcp.json in the project root |
| User | --scope user | All your projects | No | ~/.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:
{ "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.

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:
- Add the server:
claude mcp add --transport http sentry https://mcp.sentry.dev/mcp.claude mcp listnow shows! Needs authentication, which is expected. - Start
claude, run/mcp, select the server and choose Authenticate. - 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:
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.
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.
{ "permissions": { "allow": ["mcp__claude-code-docs__*", "mcp__sentry__*"], "ask": ["mcp__github__*"], "deny": ["mcp__airtable__*"] }}Rules to know:
mcp__githubandmcp__github__*both match every tool on thegithubserver;mcp__github__get_*matches only itsget_tools.- Allow globs work only after a literal
mcp__<server>__prefix. An allow rule ofmcp__*is skipped and approves nothing, whilemcp__*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.jsonserver by name in every session, add it todisabledMcpjsonServersin 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:
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:
| Job | Server | Command |
|---|---|---|
| Look up Claude Code features | Claude Code docs | claude mcp add --transport http claude-code-docs https://code.claude.com/docs/mcp |
| Test pages in a real browser | Playwright | claude mcp add playwright -- npx -y @playwright/mcp@latest |
| Issues, PRs, code search | GitHub | claude mcp add --transport http github https://api.githubcopilot.com/mcp/ --header "Authorization: Bearer $GITHUB_PAT" |
| Production errors | Sentry | claude mcp add --transport http sentry https://mcp.sentry.dev/mcp |
| Notes and specs | Notion | claude mcp add --transport http notion https://mcp.notion.com/mcp |
| Query a database | DBHub | claude 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.
| Symptom | Likely cause | Fix |
|---|---|---|
/mcp says no servers configured | Server added in another project at local scope, or config at a wrong path | Re-add from this project, or use --scope user |
✘ Failed to connect (stdio) | The command fails or -- was missing | Run the command by hand, e.g. npx -y @playwright/mcp@latest; re-add with -- |
✘ Failed to connect (HTTP) | Wrong URL or rejected token | curl -I <url>: 404 or 405 means it is up, 401 or 403 means auth |
! Needs authentication | OAuth not done yet | /mcp, select the server, Authenticate |
⏸ Pending approval | Project server not approved | Run claude in the project and approve |
| Times out at startup | First npx download is slow | MCP_TIMEOUT=60000 claude |
| Connected but no tools | Missing environment variable | Add --env KEY=value or the env field |
.mcp.json edits ignored | File read at startup only | Restart the session; check claude mcp list for parse warnings |
| "already exists" | Same name at the same scope | claude 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/mcporclaude mcp login <name>in an interactive shell. - Project servers load without asking. In
claude -pruns, servers from the project's.mcp.jsonconnect without the approval prompt. For untrusted repositories, pass--strict-mcp-config --mcp-config ./mcp.jsonso only the servers you list load, or use--setting-sources userto 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.
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:
- Pick one server that matches a daily task (issues, errors, a browser or docs).
- Add it with
claude mcp add, using--transport httpfor URLs and--before local commands. - Choose the scope on purpose: local to try it, user for personal tools, project to share.
- Run
claude mcp listand fix anything that is not✔ Connected. - Sign in with
/mcporclaude mcp login, and keep tokens in environment variables. - Add
allow,askanddenyrules for the server's tools in.claude/settings.json. - Commit
.mcp.jsononly with${VAR}placeholders, never real secrets. - Before any unattended run, pin servers with
--strict-mcp-configand deny write tools. For automatic checks around tool calls, add Claude Code hooks with anmcp__<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.


