Claude Code MCP: how to add and manage MCP servers
Claude Code adds MCP servers with one command, claude mcp add. This guide covers remote and local servers, headers and env vars, the three scopes and which wins, OAuth with /mcp, tool permissions, timeouts, tool search and common errors, tested on Claude Code 2.1.332.

Claude Code adds MCP servers with one command: claude mcp add --transport http <name> <url> for a remote server, or claude mcp add <name> -- <command> for one that runs on your machine. After that, claude mcp list checks each server's connection and /mcp inside a session handles OAuth sign-in.
We ran every command below on November 28, 2026, with Claude Code 2.1.332 in a throwaway project, and copied the output from the terminal. Flags were checked against claude mcp add --help and Anthropic's Claude Code MCP docs that day. This part of Claude Code changes often, so compare claude --version with ours if something differs.
Add an MCP server to Claude Code
claude mcp add takes a name and either a URL or a command. The --transport flag says which: http, sse or stdio, with stdio as the default.
A remote server by URL
Most hosted servers, such as Notion, Sentry or Linear, use Streamable HTTP:
$ claude mcp add --transport http corsair https://mcp.corsair.dev/mcp
Added HTTP MCP server corsair with URL: https://mcp.corsair.dev/mcp to local configIf the server takes an API key instead of OAuth, send it as a header. -H works too, and you can repeat it:
claude mcp add --transport http example-api https://mcp.example.com/mcp \
--header 'Authorization: Bearer ${EXAMPLE_API_KEY}'The single quotes keep ${EXAMPLE_API_KEY} as text, so the config stores the variable's name and Claude Code fills in the value when it connects. With double quotes, your shell expands it and the key lands in the config file in plain text.
SSE is deprecated. Anthropic's docs say that since 2.1.265, --transport http tries HTTP first and switches to SSE on its own when a server only speaks SSE, so you rarely need --transport sse. It still works:
$ claude mcp add --scope project --transport sse legacy-sse https://mcp.example.com/sse
Added SSE MCP server legacy-sse with URL: https://mcp.example.com/sse to project configA local (stdio) server
Put the command after --. Everything after it goes to the server untouched, so flags like -y reach npx instead of Claude Code:
$ claude mcp add --scope project filesystem -- npx -y @modelcontextprotocol/server-filesystem /path/to/project
Added stdio MCP server filesystem with command: npx -y @modelcontextprotocol/server-filesystem /path/to/project to project configEnvironment variables go in with -e or --env. Put them after the server name. -e accepts several values in a row, so when the name follows it, Claude Code reads the name as another variable. We hit this:
$ claude mcp add --scope project --transport stdio -e LOG_LEVEL=debug -e API_KEY=your-key envdemo -- node server.js
Invalid environment variable format: envdemo, environment variables should be added as: -e KEY1=value1 -e KEY2=value2
$ claude mcp add --scope project envdemo -e LOG_LEVEL=debug -e API_KEY=your-key -- node server.js
Added stdio MCP server envdemo with command: node server.js to project configChoose a scope: local, project or user
Every add writes to one of three scopes, set with --scope or -s:
- Local, the default. Only you, only this project. Stored in
~/.claude.jsonunder the project's path. Use it for experiments and servers with personal keys. - Project. Everyone who clones the repo. Stored in
.mcp.jsonat the project root, which you commit. - User. Only you, in every project. Also stored in
~/.claude.json. Use it for servers you want everywhere, such as a docs server or Corsair.
Here is the .mcp.json our project-scope commands wrote:
{
"mcpServers": {
"filesystem": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"],
"env": {}
},
"example-api": {
"type": "http",
"url": "https://mcp.example.com/mcp",
"headers": { "Authorization": "Bearer ${EXAMPLE_API_KEY}" }
}
}
}.mcp.json expands ${VAR} and ${VAR:-default} in command, args, env, url and headers, so teammates share one file and keep their own keys in their shell. A missing variable doesn't stop the server from loading. claude mcp list warned us instead: Missing environment variables: EXAMPLE_API_KEY.
Project servers also need your approval before Claude Code connects to them. Until you run claude in the folder and accept, they show as pending:
filesystem: npx -y @modelcontextprotocol/server-filesystem /path/to/project - ⏸ Pending approval (run `claude` to approve)Which scope wins
When one name exists in more than one scope, Claude Code uses local first, then project, then user, then servers from plugins, then claude.ai connectors. It takes the whole entry from the winning scope and merges no fields. We added corsair at both project and local scope, and claude mcp get showed only the local one:
$ claude mcp get corsair
corsair:
Scope: Local config (private to you in this project)
Status: ! Needs authentication
Type: http
URL: https://mcp.corsair.dev/mcp
To remove this server, run: claude mcp remove corsair -s localAdd a server from JSON or Claude Desktop
Setup instructions written for Claude Desktop or Cursor usually give an mcpServers block. Pass the object inside it to claude mcp add-json:
$ claude mcp add-json --scope project weather '{"type":"http","url":"https://mcp.example.com/weather","timeout":120000}'
Added http MCP server weather to project configTwo catches from our run. A block with a url and no type is refused, because Claude Code treats an entry without a type as stdio:
$ claude mcp add-json --scope project broken '{"url":"https://mcp.example.com/mcp"}'
Invalid configuration: it has a "url" but no "type". Add "type": "http" (or "sse" / "ws").And piping JSON in with - worked from a plain terminal but was refused when Claude Code itself ran the command: "Reading the JSON from stdin is refused inside a Claude Code session, because its permission prompt would not show the server."
claude mcp add-from-claude-desktop copies servers from Claude Desktop's config and lets you pick which ones. It only runs on macOS and WSL. On our Linux box it answered Unsupported platform - Claude Desktop integration only works on macOS and WSL. Our Claude Desktop MCP guide covers where that config file lives.
List, check, sign in and remove
claude mcp list # every server, with a live health check
claude mcp get <name> # one server's scope, status, type and URL
claude mcp login <name> # OAuth sign-in from your shell
claude mcp logout <name> # clear stored OAuth credentials
claude mcp remove <name> # remove it (add -s to pick a scope)claude mcp list connects to each server and prints a status: ✔ Connected, ! Needs authentication, ✘ Failed to connect or ⏸ Pending approval. A failed line includes the HTTP status or error the server returned.
For OAuth servers, run /mcp inside Claude Code. It lists every server with its status and tool count, opens the browser to sign in, and has Re-authenticate, Clear authentication, Reconnect and a toggle to disable a server for this project. Tokens are stored and refreshed for you. Over SSH, claude mcp login <name> --no-browser prints the URL instead:
$ claude mcp login corsair --no-browser
Starting authentication for "corsair"…
Visit this URL to authorize:
https://hub.corsair.dev/mcp-auth/authorize?…
Waiting for authorization… (^C to cancel)
Or paste the redirect URL here:remove refuses to guess when a name exists in two scopes:
$ claude mcp remove corsair
MCP server "corsair" exists in multiple scopes:
- Local config (private to you in this project) (~/.claude.json [project: /path/to/project])
- Project config (shared via .mcp.json) (/path/to/project/.mcp.json)
To remove from a specific scope, use:
claude mcp remove corsair -s local
claude mcp remove corsair -s projectRemoving a remote server deletes its stored tokens on your machine but doesn't revoke them at the provider. Run claude mcp logout <name> first if you want them revoked.
Allow MCP tools without a prompt
Claude Code names MCP tools mcp__<server>__<tool>, and permission rules use those names. mcp__github__* or mcp__github matches every tool on the github server, and mcp__github__create_issue matches one. Put rules in .claude/settings.json to share them, or ~/.claude/settings.json for yourself:
{
"permissions": {
"allow": ["mcp__fs__list_directory", "mcp__fs__read_text_file"],
"deny": ["mcp__fs__write_file"]
}
}For one run, --allowedTools does the same. We gave a headless run the filesystem server and allowed only list_directory, then asked it to list the folder and write a file:
claude -p --permission-mode default --strict-mcp-config \
--mcp-config '{"mcpServers":{"fs":{"type":"stdio","command":"npx","args":["-y","@modelcontextprotocol/server-filesystem","/path/to/project"]}}}' \
--allowedTools "mcp__fs__list_directory" \
"List this folder with list_directory, then create notes.txt with write_file."The list ran. The write came back in permission_denials as mcp__fs__write_file, and no file appeared. One thing tripped us first: our machine's settings start Claude Code in bypassPermissions, and in that mode the same run wrote the file. Allow lists only matter in a mode that asks.
Timeouts and output limits
MCP_TIMEOUT: how long a server gets to start, in milliseconds. Default 30,000.MCP_TOOL_TIMEOUT: the limit for one tool call. Default about 28 hours. For HTTP and SSE servers, each request also waits at most 60 seconds for the first byte of the reply, unless this or the server's owntimeoutis higher.timeoutin a server's JSON entry sets the tool-call limit for that server only, as in theweatherexample above.MAX_MCP_OUTPUT_TOKENS: the most a tool result can put into the conversation. Default 25,000, with a warning above 10,000. A text result over 50,000 characters is saved to a file and Claude gets the path, whatever this is set to.
Set them in your shell, as in MCP_TIMEOUT=60000 claude, or in the env block of settings.json.
Tool search: why adding servers costs less context now
Every MCP server sends Claude Code its tools with descriptions and input schemas. Tool search, on by default, loads only the tool names and server instructions up front, and Claude fetches a tool's full definition when it needs it. In our permission test, Claude ran ToolSearch once to load the two filesystem tools before calling them.
We measured what that saves. Three common stdio servers, filesystem 2.4.1, Context7 4.9.1 and Playwright MCP 0.0.86, list 43 tools. Their full definitions come to 46,087 characters, about 11,500 tokens. The 43 mcp__… names Claude Code loads instead come to 1,449 characters, about 32 times less, plus each server's instructions (measured 2026-11-28).
To change it, set ENABLE_TOOL_SEARCH: false loads everything up front, and auto loads tools up front until they pass 10% of the context window. To keep one server's tools always loaded, add "alwaysLoad": true to its entry. Our best MCP servers post measures 15 popular servers by context cost and risk if you're choosing what to install.
Troubleshooting Claude Code MCP
✘ Failed to connect. Run the server's command yourself in a terminal: its error there is the one Claude Code hit. For remote servers, read the status codeclaude mcp listprints. A firstnpxrun downloads the package, so raiseMCP_TIMEOUTif startup times out.⏸ Pending approval. It's a project server you haven't approved. Runclaudein the folder and accept it. If you dismissed the prompt,claude mcp reset-project-choicesbrings it back.! Needs authentication. Run/mcpand sign in, orclaude mcp login <name>. Aclaude -prun can't open a browser, so sign in from an interactive session first.- 401 with a header you set. Claude Code doesn't fall back to OAuth when your
Authorizationheader is rejected. Fix the token, or remove the header to use OAuth. - You added a server and Claude can't see it. A server added from inside a running session loads after a restart.
claude --continuerestarts and keeps the conversation. - Connected, zero tools. Choose Reconnect in
/mcp. If it stays at zero, startclaude --debug=mcpand read the server's stderr in the debug log. - Works in one folder, fails in another. Relative paths in
commandorargsresolve from where you started Claude Code. Use absolute paths. npxservers on native Windows. Earlier versions of Anthropic's docs said to start them throughcmd /c, as inclaude mcp add my-server -- cmd /c npx -y @some/package. The current page no longer says so, and we didn't test on Windows. If annpxserver fails to start there, try the wrapper first.
What this setup doesn't solve
Three things stay on you:
- One config per tool. Claude Code reads
~/.claude.jsonand.mcp.json. Codex reads~/.codex/config.toml, which our Codex MCP guide covers, and Cursor reads~/.cursor/mcp.json. Each server gets added again in each one. - Keys in plain text. A key passed with
-eor--headersits in~/.claude.json.${VAR}references in.mcp.jsonkeep it out of the repo, not off the disk. - Each server runs on its own terms. Claude Code decides whether to ask before a call. It can't hold a delete for approval on the server's side, or tell a read from a write unless the server says which is which.
Add Corsair's MCP gateway to Claude Code
Corsair is a hosted MCP gateway: one URL in front of the apps you connect to it, such as Gmail, Slack, GitHub, Linear and Notion. Corsair's catalog had 817 apps and 37,534 operations on November 27, 2026.
claude mcp add --scope user --transport http corsair https://mcp.corsair.dev/mcpThen run /mcp in Claude Code and sign in. Corsair opens in your browser, you pick which of your links Claude Code uses, and you allow it. If you've claimed a handle, use your own path instead, such as https://yourname.lug.dev/work. There's no API key to paste, so nothing secret goes into ~/.claude.json.
What changes against the list above:
- One entry for every app. Connect or remove an app in Corsair and Claude Code sees the change. The same URL works in Codex, Cursor and Claude Desktop. Local servers such as filesystem stay in Claude Code.
- A short tool list. Claude Code gets one fixed set of Corsair tools, such as search, list_operations and run_script, however many apps you connect.
- Rules on Corsair's side. Each path has a mode: Read, Cautious, where deletes wait for your approval, Strict, where every write waits, or Open. That holds whatever permission mode Claude Code runs in, bypass included.
- Tokens stay in Corsair. They're encrypted with a key per connected account, and Claude Code never sees them.
Get your MCP URL at corsair.dev, or read how Corsair's MCP server works.
FAQs
How do I add an MCP server to Claude Code?
Run claude mcp add --transport http <name> <url> for a remote server, or claude mcp add <name> -- <command> for a local one. Add --scope project to share it through .mcp.json or --scope user to have it in every project. Then check it with claude mcp list.
Where does Claude Code store MCP server config?
Local and user servers are in ~/.claude.json, local ones under the project's path. Project servers are in .mcp.json at the repository root. Claude Code doesn't read an mcpServers key in settings.json.
What is the difference between local, project and user scope?
Local is the default and applies only to you in the current project. Project writes .mcp.json so everyone on the repo gets the server after approving it. User applies to you in every project. When a name exists in several scopes, local wins, then project, then user.
How do I sign in to an MCP server that uses OAuth?
Run /mcp in a Claude Code session, pick the server and follow the browser sign-in, or run claude mcp login <name> in your shell. Add --no-browser over SSH to get a URL you open on another machine.
How do I let Claude Code use an MCP tool without asking?
Add the tool's full name, such as mcp__github__create_issue, or mcp__github__* for the whole server, to permissions.allow in your settings, or pass it to --allowedTools for one run. Allow rules don't matter in bypassPermissions mode, where nothing asks.
Does Claude Code support SSE MCP servers?
Yes, with --transport sse, but SSE is deprecated. Since version 2.1.265, --transport http switches to SSE on its own when a server only supports it.