How to Add a Claude Code MCP Server
Connect Claude Code to an external system through MCP, choose where the configuration lives, and keep it working across parallel worktrees.
Goal
Give Claude Code access to a system it cannot read from the repository, such as an issue tracker or an error dashboard, through a Model Context Protocol server. Then make the same server available in every worktree an agent runs in.
As of December 2026, every command and file path below comes from the Claude Code MCP docs. Check that page for the current flag list.
Prerequisites
- Claude Code installed and available as
claudeon yourPATH - The URL of a remote MCP server, or the command that starts a local one
- An account with the service the server connects to, if it needs sign-in
Decide whether you need MCP
Use a CLI first when the system has one. The Claude Code best practices page notes that Claude opens pull requests and reads review comments through gh with no extra setup. MCP is for systems without a CLI.
Every connected server adds its tool names and instructions to the context, even in sessions that never call it. Connect the servers a task needs, and turn the rest off from /mcp.
Add a remote server
Remote servers use the HTTP transport. Pass a name and the server URL:
claude mcp add --transport http notion https://mcp.notion.com/mcp
For a server that takes a static token, add a header:
claude mcp add --transport http secure-api https://api.example.com/mcp \
--header "Authorization: Bearer your-token"
For a server that uses OAuth, add it, start Claude Code, and run /mcp. Claude Code opens the sign-in flow in your browser.
The SSE transport still works with --transport sse, but the docs mark it deprecated. Use HTTP when the server offers it.
Add a local server
A stdio server runs as a local process. Everything after -- is the command that starts it, passed through untouched:
claude mcp add --env AIRTABLE_API_KEY=YOUR_KEY --transport stdio airtable \
-- npx -y airtable-mcp-server
Without --, Claude Code tries to parse the server's own flags as its options. Keep at least one option between --env and the server name, because the CLI reads a name that follows --env as another KEY=value pair and rejects it.
Choose a scope
The --scope flag decides who sees the server and where Claude Code writes it.
| Scope | Loads in | Shared with team | Stored in |
|---|---|---|---|
local, the default | Current project only | No | ~/.claude.json |
project | Current project only | Yes, through version control | .mcp.json in the project root |
user | All your projects | No | ~/.claude.json |
When the same server name exists in several scopes, local wins over project, and project wins over user. Claude Code uses the whole entry from the winning scope and does not merge fields across scopes.
Share servers through .mcp.json
A project-scoped server lands in .mcp.json, which you commit:
claude mcp add --transport http --scope project notion https://mcp.notion.com/mcp
Keep tokens out of the committed file with environment variable expansion. Claude Code expands ${VAR} and ${VAR:-default} in command, args, env, url, and headers:
{
"mcpServers": {
"api-server": {
"type": "http",
"url": "${API_BASE_URL:-https://api.example.com}/mcp",
"headers": {
"Authorization": "Bearer ${API_KEY}"
}
}
}
}
In an interactive session, Claude Code asks for approval before it uses a server from .mcp.json. Run claude mcp reset-project-choices to clear those answers. In claude -p runs it cannot show the prompt and loads project servers without asking, so review .mcp.json changes in pull requests as carefully as code.
Use MCP with parallel worktrees
A git worktree is a fresh checkout. Committed files such as .mcp.json appear in every worktree. Gitignored files do not, so a server that reads its token from a local .env file fails in the new directory.
Put shared servers in .mcp.json and read secrets from environment variables set in your shell. Each parallel Claude Code session then starts with the same tool set. For worktrees that Claude Code creates itself, list the gitignored files to copy in a .worktreeinclude file at the repository root, as the worktrees docs describe.
In Treq, each workspace is its own working copy under .treq/workspaces/, so the same rule applies. A committed .mcp.json is there when the agent starts. For a gitignored file the agent needs, add it to the repository's list of files copied into new workspaces. See Workspaces for the setting.
Check and remove servers
claude mcp list # every configured server and its status
claude mcp get notion # details for one server
claude mcp remove notion
Inside a session, /mcp shows server status, handles OAuth, and lists each tool. MCP tools are named mcp__<server>__<tool>, which is the name you use in permission rules and hook matchers.
Common failure cases
Server takes too long to start. Raise the startup timeout with the MCP_TIMEOUT environment variable in milliseconds, for example MCP_TIMEOUT=10000 claude.
Tool output gets cut off. The default limit is 25,000 tokens per MCP tool result. Set MAX_MCP_OUTPUT_TOKENS before starting Claude Code to change it.
Missing variable in .mcp.json. The config still loads. claude mcp list shows a missing-variable warning for that server, and the unexpanded ${VAR} text is used as is.
Same server in two scopes. The local entry hides the project entry completely, so edits to .mcp.json seem to do nothing. Remove the local entry with claude mcp remove <name> --scope local.
Related
- How to Use Claude Code Hooks: run your own commands at fixed points in the agent loop
- How to Run Multiple Claude Code Sessions: give each session its own worktree
- Setting Up Claude Code: install Claude Code and add project instructions
- What are Coding Agents?: how agents choose and call tools