Claude Code MCP servers: claude mcp add, scopes and /mcp
Add MCP servers to Claude Code with claude mcp add: which file each scope writes, approving .mcp.json, OAuth over SSH, env variables, timeouts and fixes.
Add servers from your shell with claude mcp add: claude mcp add --transport http <name> <url> for a remote server, and claude mcp add <name> -- <command> for a local one that Claude Code starts itself, with everything after -- passed to the server untouched. With no --scope the server is saved at local scope, in ~/.claude.json under the current project and for you alone; --scope user saves it in the same file for all your projects, and --scope project writes .mcp.json at the project root, which you commit and each person approves once. claude mcp list connects to each server and prints ✔ Connected, ! Needs authentication or ✘ Failed to connect with the server’s error. Inside a session, /mcp shows each server’s tools, signs in to servers that use OAuth, and turns servers off or reconnects them; claude mcp login <name> does the sign-in from the shell, over SSH too. This is Claude Code 2.1.330, the npm release of 20 November 2026.
Adding a server from a URL, a command or a JSON block
A server’s setup instructions are often written for Claude Desktop, Cursor or another client and give no claude mcp add line. Anthropic’s MCP reference says to look in them for a URL, a launch command or an mcpServers block, and each has its command. Run them in your shell, not inside a claude session.
# a URL: a remote server over HTTP (this one needs no sign-in)
claude mcp add --transport http claude-code-docs https://code.claude.com/docs/mcp
# a launch command: a local server, started by Claude Code over stdio
claude mcp add airtable --env AIRTABLE_API_KEY=YOUR_KEY -- npx -y airtable-mcp-server
# an mcpServers block from another client: the object inside it, not the wrapper
claude mcp add-json example '{"command":"npx","args":["-y","@example/mcp-server"]}'Copied- A URL means a remote server.
--transport http(or-t http) is streamable HTTP, and a JSON entry accepts the specification’s name,streamable-http, as well. A service that still offers only the deprecated SSE transport takes the same command: since 2.1.265 Claude Code tries HTTP first and switches to SSE when the server doesn’t accept it, and--transport sseforces SSE. Awss://WebSocket endpoint can’t be added with--transportat all; it goes in throughadd-jsonwith"type": "ws". A server that takes an API key gets it with--header "Authorization: Bearer …"(-H); where that key then sits, and how to keep it out of the file, is in connecting Claude Code to a remote MCP server with an API key. - A launch command means a local server, which is stdio by default and needs no
--transport. Everything after--is the server’s command; leave the--out and Claude Code reads the server’s flags, such as-yor--port, as its own.--env KEY=value(-e) takes several pairs after one flag, which is the trap: a name directly after--envis read as another pair and rejected, so put the name first, as above, or another option between them. - An
mcpServersblock goes toclaude mcp add-jsonwithout its wrapper. Two things need fixing first. An entry with aurland notypeneeds"type": "http"(orsse,ws), because Claude Code reads an entry with no type as stdio and skips it withMCP server "<name>" has a "url" but no "type"; add "type": "http" (or "sse" / "ws") to this entry. And a name may hold only letters, numbers, hyphens and underscores. Since 2.1.327 a-in place of the JSON reads it from standard input,cat server.json | claude mcp add-json name -, which keeps a token off the command line; on 23 November 2026 that version was newer than npm’sstabletag, 2.1.323. - Servers already set up in Claude Desktop come across with
claude mcp add-from-claude-desktop, which offers a picker, on macOS and WSL only. A server whose name has a space or another character outside that set is reported and skipped, and the rest import.
Success prints Added HTTP MCP server claude-code-docs with URL: https://code.claude.com/docs/mcp to local config and a File modified: line naming the file. That means the entry was saved, not that the server works: add doesn’t check credentials, so a placeholder key is accepted and fails at the first connection.
Which file each scope writes
| Scope | How to pick it | Saved in | Loads |
|---|---|---|---|
local, the default | no flag, or --scope local | ~/.claude.json, under projects and this project’s path | In this project, for you |
user | --scope user (-s user) | ~/.claude.json, in the top-level mcpServers | In every project, for you |
project | --scope project | .mcp.json at the project root | For everyone with the repository, once each approves it |
- “This project” is the repository root, or the exact directory when you aren’t in a git repository. Adding a server in one folder and starting Claude Code in another is the first cause the quickstart’s troubleshooting gives for
/mcpshowing no servers. - Only those two files count. Claude Code doesn’t read
~/.claude/.mcp.json,~/.claude/mcp.json,~/.claude/config/mcp.jsonor%APPDATA%\Claude\mcp.json. On Windows the file is%USERPROFILE%\.claude.json, and withCLAUDE_CONFIG_DIRset it is the.claude.jsoninside that directory. MCP’s local scope has nothing to do with.claude/settings.local.json. - A scope is fixed when you add the server. To move one, remove it and add it again:
claude mcp remove name --scope local, then the sameaddwith--scope user.claude mcp get nameshows which scope holds it. - One name in several places: Claude Code connects once, taking local over project over user, and uses that whole entry; “fields are not merged across scopes.” Below the three come servers from plugins, which arrive and leave with the plugin under names like
plugin:my-plugin:database-tools, and then claude.ai connectors, both matched to your own servers by endpoint rather than by name (inclaude -p, Agent SDK and VS Code sessions, connectors rank above plugins).claude mcp listwarns when one name points at different endpoints in different scopes.
Of the two files, .mcp.json is the one worth writing by hand, since it is committed. Every scope uses the same entry shape:
{
"mcpServers": {
"claude-code-docs": {
"type": "http",
"url": "https://code.claude.com/docs/mcp"
},
"playwright": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@playwright/mcp@latest"]
}
}
}CopiedClaude Code reads it when a session starts, so restart after editing it. Before 2.1.327, claude mcp add and remove at project scope deleted other top-level keys from the file, such as $schema.
Checking that it connected
claude mcp list connects to each server and prints one of these beside it; the last three are read from your settings without connecting:
| Status | What it means |
|---|---|
✔ Connected | Ready to use |
! Connected · tools fetch failed | It connected but couldn’t list its tools; claude mcp get name gives the error |
! Needs authentication | It answered and wants a sign-in, or a token you haven’t given it |
✘ Failed to connect | Followed by the HTTP status or error code and whatever text the server sent back |
✘ Connection error | The attempt threw an error; no detail is shown |
⏸ Pending approval (run `claude` to approve) | A .mcp.json server you haven’t approved yet |
⊘ Disabled for this project (re-enable via /mcp) | Turned off for this project |
✘ Blocked by enterprise managed policy | Your organization’s policy refuses it |
A failure there is the server’s, not the command’s. The first check of an npx server can fail while the package downloads, so run it again before digging. Inside a session, /mcp lists the same servers with a tool count beside each connected one; select a server to see its tools and to authenticate, reconnect or disable it. /mcp reconnect name, or /mcp reconnect all since 2.1.284, retries without opening the panel. An interactive session doesn’t restart a stdio server whose process died; it marks it failed until you reconnect it there.
Using a connected server needs nothing more: Claude picks its tools when a task calls for them, and may ask your permission the first time it calls one. A server’s resources are mentioned like files, as @server:protocol://resource/path, and its prompts appear in the / menu as /servername:promptname (MCP).
Signing in to a server that uses OAuth
Services such as Sentry, Linear and Notion put their MCP servers behind OAuth. Add the URL with no header, and claude mcp list shows ! Needs authentication; then, in a session, open /mcp, select the server, choose Authenticate, and approve in the browser that opens. If the browser’s redirect fails after you sign in, paste the full callback URL from its address bar into the prompt Claude Code shows.
From the shell, claude mcp login name runs the same flow, and on a server it is the easier route. Per the command-line sign-in docs, it notices when there is no local browser, over SSH or on Linux with no display, and prints the authorization URL instead. Open it on your own computer, sign in, and paste the full redirect URL from the address bar back at the prompt. The paste needs an interactive terminal, so connect with ssh -t; --no-browser forces the printed URL even where a browser is found.
- Tokens are stored and refreshed automatically;
claude mcp logout nameclears them.claude mcp removedeletes them too but doesn’t revoke them where they were issued, so runlogoutfirst if you want them revoked, which works where the service supports revocation. - A pre-registered redirect URI:
--callback-port 8080onaddfixes the callback athttp://localhost:8080/callbackin place of a random port. - No automatic client registration (“Incompatible auth server: does not support dynamic client registration”): register an app with the service, then add the server with
--client-idand--client-secret, which asks for the secret with masked input or readsMCP_CLIENT_SECRET. The secret can be set only when adding; to change it, remove and add again. - Gmail, Google Calendar and Microsoft 365 at Anthropic’s own connector addresses don’t accept a sign-in from Claude Code; remove the entry you added with
claude mcp remove name, which would otherwise hide the connector at the same address, then connect the service at claude.ai’s connectors page. It appears in Claude Code on its own when Claude Code is signed in to that claude.ai account with a subscription login.
A key in a header and OAuth don’t mix: when a server rejects an Authorization header you configured, Claude Code reports the connection as failed, not as needing authentication, and doesn’t fall back to OAuth. Remove the header to sign in with OAuth instead.
What a local server sees, and variables in the config
A stdio server inherits the environment Claude Code was started from. The environment variables reference describes CLAUDE_CODE_MCP_ALLOWLIST_ENV=1 as the switch that gives it “only a safe baseline environment plus the server’s configured env, instead of inheriting your shell environment,” and CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1 strips credentials from it, from Bash commands and from hooks. So by default a key exported in your shell, or in the tmux session you run Claude Code in on a server, reaches every local server you add, and a key a server can’t find has to be in the environment that started claude, or in the entry’s env. Codex works the other way round and passes a local server only a short list, as the Codex MCP guide shows. Claude Code also sets CLAUDE_PROJECT_DIR to the project root in the server’s environment.
An entry can read variables in its command, args, env, url and headers, as ${VAR} or ${VAR:-default}, which is how a committed .mcp.json carries no secrets:
{
"mcpServers": {
"api-server": {
"type": "http",
"url": "${API_BASE_URL:-https://api.example.com}/mcp",
"headers": {
"Authorization": "Bearer ${API_KEY}"
}
}
}
}Copied- Unset, with no default: the server still loads, with the literal
${VAR}text in place, andclaude mcp listand/mcpwarn, naming the variable. - Set to an empty string: it counts as set, so the default is not used; in the example,
API_BASE_URL=""leaves aurlof/mcpand the list reports'url' is not a valid URL. - Claude Code’s and your cloud provider’s credentials, such as
ANTHROPIC_API_KEY, and other credentials such asHTTPS_PROXYandNPM_TOKEN, read as empty in a remote server’surlandheaders, with no warning, and a:-defaulton one is ignored. Copy the value into a variable with a name of your own. CLAUDE_PROJECT_DIRisn’t in Claude Code’s own environment, so using it in acommandorargsneeds a default:${CLAUDE_PROJECT_DIR:-.}.- Pasted values: a token pasted with a trailing newline shows as
Leading or trailing whitespace in: headers.Authorization. Claude Code doesn’t trim it, so fix the entry.
claude mcp list, get and the /mcp detail view print a reference by its name, never its value.
Approving a project’s .mcp.json servers
A .mcp.json in a repository asks every clone to run its servers, so an interactive session asks before using them. Your answer is written to .claude/settings.local.json as one of three settings: enabledMcpjsonServers lists the servers you approved, enableAllProjectMcpServers: true approves every one, and disabledMcpjsonServers lists the ones you rejected. A rejection wins over both approvals, in any settings file, a committed .claude/settings.json included. To be asked again, run claude mcp reset-project-choices and restart.
Approvals committed to the repository count only once you trust the folder. Until you have run claude there and accepted the trust dialog, an approval committed to the project’s .claude/settings.json is ignored, and the server stays at ⏸ Pending approval: “A cloned repository can’t approve its own servers.” Approvals in your own ~/.claude/settings.json, in managed settings or in a --settings file still apply there.
Some sessions never ask. claude -p runs, Agent SDK sessions and cloud sessions (other than the threads of a Project on Claude Code on the web) load project servers without asking, and so does a session started in bypassPermissions with skipDangerousModePermissionPrompt in your user or managed settings. To keep a server out of those, the project scope docs give three ways: name it in disabledMcpjsonServers, leave project settings out with --setting-sources, or start with --strict-mcp-config, which loads only what --mcp-config names.
Turning servers and tools off
- A whole server, kept configured: toggle it in
/mcp, or/mcp disable name(enablebrings it back, and both takeall). The choice is stored per project in~/.claude.jsonasdisabledMcpServers, and a tool call to it returnsMCP server "<name>" is disabled — re-enable it via /mcp to use its tools. - Some tools: a permission rule names a server’s tools as
mcp__github__*, or one tool asmcp__github__create_issue; put it underpermissions.denyto block it, orallowto stop the prompts. Characters such as.or spaces in a server’s name become_in the rule, and a plugin’s server ismcp__plugin_<plugin>_<server>__*(permission rules for MCP). - Every MCP tool, for one run:
--disallowedTools "mcp__*".--toolsrestricts built-in tools only and leaves MCP tools alone. - claude.ai connectors: signed in with a claude.ai account, the connectors you added on claude.ai appear in
/mcpon their own, with tools namedmcp__claude_ai_<server>__<tool>."disableClaudeAiConnectors": truein any settings file turns them all off, andENABLE_CLAUDEAI_MCP_SERVERS=falsedoes it for one session. - Everything, to find what broke:
claude --safe-modestarts with no MCP servers, plugins orCLAUDE.mdand none of your own hooks; your organization’s managed hooks still run.
Time, output and context limits
Values from the time limits and output limits sections. Times are in milliseconds, and the variables go in the shell that starts Claude Code.
| Limit | Default | To change it |
|---|---|---|
A server’s startup | 30 seconds | MCP_TIMEOUT=60000 claude |
One tool call, start to finish | About 28 hours | MCP_TOOL_TIMEOUT, or "timeout" in milliseconds on the server’s entry (below 1000 is ignored) |
Each request to an HTTP or SSE server, until its first byte | 60 seconds | Raised by a per-server timeout, MCP_TOOL_TIMEOUT or MCP_TIMEOUT above 60000; never lowered |
A call with no response and no progress | 5 minutes remote, 30 minutes stdio | CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUT (0 turns it off); a per-server timeout also sets a floor |
A long call moved to the background | After 2 minutes, main conversation only | CLAUDE_CODE_MCP_AUTO_BACKGROUND_MS (0 turns it off) |
A result kept in the conversation | 25,000 tokens, with a warning past 10,000 | MAX_MCP_OUTPUT_TOKENS |
A text result kept in the conversation | 50,000 characters | Only the server, per tool, up to 500,000 |
One HTTP or SSE response | 16 MiB, then the request fails | Only the server, by returning less |
A result over the token or character limit isn’t lost: it is saved to a file in the session’s tool-results folder under ~/.claude/projects/, and Claude is given the path to read it. Error text from a tool is cut differently: past about 11,000 characters, Claude gets the first 5,000 and the last 5,000. For a slow tool on a remote server, the per-server timeout is the one setting that lifts the 60-second request timer and the idle window together; it is also that server’s hard limit per call.
Many servers cost little context. Tool search is on by default, so a session starts with only each tool’s name and each server’s instructions, and a tool’s full definition loads when Claude looks for it; Anthropic says there is no fixed cap on tools per server. A server whose tools Claude needs on every turn can skip the search with "alwaysLoad": true on its entry, which loads all its tools up front and also makes startup wait for that server for up to five seconds. ENABLE_TOOL_SEARCH=false loads every tool up front instead, and ENABLE_TOOL_SEARCH=auto does so until the definitions reach 10% of the context window.
In claude -p, on a server and in scheduled jobs
- Sign in first. A
-prun has no/mcppanel and can’t run an OAuth sign-in, so do it once withclaude mcp login nameas the user the job runs as. With tool search on, Claude is told that a server still waiting for a sign-in has its tools unavailable until you authorize it. - Startup waits. An interactive session starts while servers connect in the background; a
-prun (unless its input isstream-json) waits for servers still connecting before its first turn, and for servers passed with--mcp-configup toMCP_TIMEOUT. - A failure doesn’t stop the run. If a stdio server fails to start, the run carries on without its tools; if one exits later, Claude Code starts it again at the next call to one of its tools. A remote server that drops gets five reconnection attempts before the run carries on without it.
- Pinning a job’s servers:
claude -p "…" --strict-mcp-config --mcp-config ./job-mcp.jsonloads only the servers in that file and skips.mcp.json,~/.claude.jsonand plugins. That also keeps a cloned repository’s.mcp.jsonfrom loading unasked.--bareskips your configured servers as well, but keeps those from--mcp-config. - claude.ai connectors need a claude.ai login. They load only when Claude Code is signed in with a claude.ai subscription, not with
ANTHROPIC_API_KEY, anapiKeyHelper, a cloud provider, or the token fromclaude setup-token. Servers configured on the machine work with any of them.
The rest of running Claude Code on a timer, including what a -p run trusts without asking, is in Claude Code headless on a schedule.
When a server won’t work
| What you see | Usual cause, and the fix |
|---|---|
/mcp lists no servers | Added from another project at local scope, written to a file Claude Code doesn’t read, or a malformed entry, which is skipped: claude mcp list names the field in a parse warning |
✘ Failed to connect with 401 or 403 | The key in your header is wrong or isn’t valid for that endpoint, or the header reads a variable Claude Code empties, such as ANTHROPIC_API_KEY |
MCP endpoint not found at <origin>. Check the URL in your MCP config. | A 404: the path is wrong. claude mcp get name shows the full URL; remove the server and add it with the documented path |
✘ Connection error, or no detail | For a remote server, curl -I <url>: a 404 or 405 means it is up (many endpoints accept only POST), 401 or 403 means it wants a sign-in, nothing means the URL or the network |
A stdio server fails | Run its command yourself. If it starts and waits, compare it with claude mcp get name; a different command means the -- was left out |
Connection timed out at startup | Often npx downloading on first run: MCP_TIMEOUT=60000 claude |
Connected, but no tools | Usually a missing variable such as an API key; add it with --env or the entry’s env |
MCP server sentry already exists in local config | Remove it first, or pick another name; with exists in multiple scopes, add --scope to the remove |
Edits to .mcp.json don’t show | Restart the session; if you rejected the server before, claude mcp reset-project-choices |
A tool in /mcp that Claude never calls | Its full name, mcp__<server>__<tool>, is over 128 characters and is left out; give the server a shorter name |
"workspace" is a reserved MCP server name and was not loaded | Rename it; Claude Code reserves its built-in servers’ names, among them claude-in-chrome, computer-use, Claude Preview and Claude Browser |
MCP server "example" was not saved to /home/user/.claude.json | Another Claude Code process may have kept the file locked past the 10 to 20 seconds the command waits: run the add again with CLAUDE_CODE_CONFIG_LOCK_WAIT_MS=60000 (2.1.318 or later). Or the file is read-only or inside a sandbox: make it writable, or run the command outside the sandbox |
MCP server "<name>" needs you to sign in again (run /mcp to re-authenticate) | The sign-in expired or was revoked: Authenticate again from /mcp |
Claude Code as an MCP server
The other direction exists too. claude mcp serve runs Claude Code as a stdio MCP server that another client, such as Claude Desktop, connects to with "command": "claude" and "args": ["mcp", "serve"]. It prints nothing when it starts, because it is waiting on standard input. If claude isn’t on the client’s PATH, give the full path from which claude or the client fails with spawn claude ENOENT. It exposes only Claude Code’s tools, and asking you to confirm each tool call is left to your client. What a server is on either side of the protocol, and what to check before trusting one, is in what an MCP server is.