Harness Engineering 6 months ahead, in a few hours.

Add MCP servers to Claude Code: claude mcp add and .mcp.json

Thomas Poulain ¡ ¡ Updated

An MCP server is a program that gives Claude Code new tools. It can, for example, read your tickets or query your database. You add one with claude mcp add, or in a .mcp.json file at the root of your project. Claude Code starts the server or connects to it, and Claude calls its tools when your request needs them.

The commands and formats below match Claude Code 2.1.330 and the official MCP docs.

How do I add an MCP server with claude mcp add?

The command depends on the transport, meaning how Claude Code talks to the server. A remote server is reached over HTTP at a URL. A local server runs on your machine and talks over stdio, its standard input and output.

# Remote server over HTTP
claude mcp add --transport http notion https://mcp.notion.com/mcp

# Remote server with a token in a header (see below to keep the token out of your history)
claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \
  --header "Authorization: Bearer YOUR_GITHUB_TOKEN"

# Local server that Claude Code starts
claude mcp add --transport stdio db -- npx -y @bytebase/dbhub \
  --dsn "postgresql://readonly:pass@localhost:5432/analytics"

For a local server, the double dash -- separates Claude Code’s options from the server’s command. Without it, Claude Code would read -y or --dsn as its own flags.

Pass environment variables with --env KEY=value. If the server name comes right after --env, the command reads it as one more variable and rejects it. Put another option between them, such as --transport stdio.

The SSE transport is deprecated. For a server that only speaks SSE, keep --transport http. Since v2.1.265, Claude Code falls back to SSE on its own. WebSocket servers ("type": "ws") can only be added as JSON, with claude mcp add-json or in .mcp.json.

claude mcp add saves the configuration without testing the connection. The Added message doesn’t prove your token works. Check with claude mcp get <name>.

Local, project or user: which scope should I pick?

The --scope option, or -s, sets where Claude Code saves the server. Without it, the server goes to local scope.

ScopeLoads inShared with your teamFile
local (default)The current projectNo~/.claude.json, under the project’s path
projectThe current projectYes, through Git.mcp.json at the project root
userAll your projectsNo~/.claude.json

Keep a trial server, or one that holds your personal credentials, in local. Put your team’s tools in project, and the ones you use everywhere in user.

If a name exists in several scopes, local wins over project, which wins over user. Claude Code uses the winning entry as a whole and doesn’t merge fields. claude mcp list flags the conflict when the endpoints differ. To remove one definition, run claude mcp remove <name> --scope <scope>.

What does a .mcp.json file look like?

Each server is an entry under the mcpServers key. This file declares a local server and a remote one, with no secret written in it.

{
  "mcpServers": {
    "db": {
      "command": "npx",
      "args": ["-y", "@bytebase/dbhub", "--dsn", "${DATABASE_URL}"]
    },
    "api": {
      "type": "http",
      "url": "${API_BASE_URL:-https://api.example.com}/mcp",
      "headers": { "Authorization": "Bearer ${API_KEY}" }
    }
  }
}

${VAR} reads a variable from your environment, and ${VAR:-default} adds a fallback value. It works in command, args, env, url and headers. Each developer sets the variables on their own machine, so the file stays safe to share.

A few mistakes come up often with this file.

  • A url with no type. Claude Code reads an entry with no type as a local server, then skips it with an error. Add "type": "http". This often happens with a config copied from another client.
  • A variable that stays empty. In a remote server’s url and headers, some variables always read as empty, such as ANTHROPIC_API_KEY or NPM_TOKEN. That keeps a project file from sending your credentials to a third-party server. Copy the value into a variable with a name of your own.
  • Whitespace pasted with a token. A trailing newline copied with a token stays in the value. Claude Code warns about it in claude mcp list and /mcp, but doesn’t strip it.

In an interactive session, Claude Code asks you to approve the servers in a .mcp.json before it starts them. claude mcp reset-project-choices clears your answers. Note that claude -p and the Agent SDK load those servers without asking. To keep one out anyway, add its name to disabledMcpjsonServers in your settings.

How do I sign in to a remote server?

Many remote servers use OAuth. Add the server without a token, run /mcp in a session and follow the steps in your browser. Claude Code stores the tokens and refreshes them for you. From your shell, claude mcp login does the same.

claude mcp add --transport http sentry https://mcp.sentry.dev/mcp
claude mcp login sentry

# Over SSH, with no local browser
claude mcp login sentry --no-browser

With --no-browser, the command prints the authorization URL. Open it on your own machine, then paste the redirect URL back into the terminal.

For a server with a fixed token, keep the token out of the command, or it lands in your shell history. Since v2.1.327, claude mcp add-json can read the configuration from standard input. Pass - instead of the JSON, and run it outside a Claude Code session.

cat github.json | claude mcp add-json github -

To remove an OAuth server, run claude mcp logout <name> first. claude mcp remove deletes the tokens stored on your machine, but doesn’t revoke them with the service.

How do I check and debug an MCP server?

Start with these commands, run from your shell.

claude mcp list          # every server, with its status
claude mcp get github    # one server in detail, including any error
claude --debug='mcp'     # a session with debug logging limited to MCP

claude mcp list shows a status next to each server.

  • ✔ Connected means the server answers.
  • ! Needs authentication means you need to sign in with /mcp or claude mcp login <name>.
  • ✘ Failed to connect is followed by the cause, such as the HTTP status the server returned. claude mcp get puts it on an Issue: line.
  • ⏸ Pending approval marks a .mcp.json server you haven’t approved yet. Run claude in that folder to answer.

Inside a session, /mcp opens the server panel. It shows how many tools each server exposes. You can also reconnect a server there, or disable it without losing its configuration. Since v2.1.284, /mcp reconnect all retries every server that failed or needs sign-in at once.

If a server is slow to start, raise the startup timeout with MCP_TIMEOUT, in milliseconds. MCP_TIMEOUT=60000 claude gives it 60 seconds, instead of the default 30.

How do I allow or block a server’s tools?

Every MCP tool has a name in the form mcp__<server>__<tool>. Your permission rules use that name, in .claude/settings.json or ~/.claude/settings.json.

{
  "permissions": {
    "allow": ["mcp__github__get_*"],
    "deny": ["mcp__notion__*"]
  }
}

With these rules, Claude calls the github server’s get_ tools without asking. Every tool from notion is denied. In an allow rule, the * wildcard has to follow a full mcp__<server>__ prefix. An allow rule on mcp__* is skipped. As a deny rule, mcp__* blocks every MCP tool.

A hook matcher doesn’t accept the short form that permission rules do. There, mcp__github matches no tool at all, so write the regular expression mcp__github__.*. The guide to hooks covers PreToolUse, the event that can block a call before it runs.

What about long responses and slow calls?

Claude Code shows a warning when an MCP response goes over 10,000 tokens. Past 25,000 tokens by default, it saves the response to a file, and Claude reads that file when needed. The MAX_MCP_OUTPUT_TOKENS variable changes that limit.

export MAX_MCP_OUTPUT_TOKENS=50000
claude

A call still running after two minutes moves to a background task, which you’ll find in /tasks. To cap how long a call can run, add a timeout field in milliseconds to the server’s entry. MCP_TOOL_TIMEOUT sets the same limit for every server.

What changed in recent releases?

  • v2.1.265: --transport http falls back to SSE when the server only speaks SSE.
  • v2.1.284: /mcp reconnect all arrives.
  • v2.1.287: "alwaysLoad": false makes all of a server’s tools load on demand, even ones the author marked to load upfront.
  • v2.1.323: approving a .mcp.json server now requires its exact name. Another spelling asks you again.
  • v2.1.326: /mcp shows why a local server failed to start. A broken .mcp.json reports the line and column of the error.
  • v2.1.327: claude mcp add-json <name> - reads the JSON from standard input.
  • v2.1.329: a “Server message” row in /mcp shows the error from an HTTP server that refuses the connection.
  • v2.1.330: /mcp groups plugin servers under “Plugin MCPs”.

The changelog lists every MCP fix, release by release.


Module 6 of the course covers MCP from the ground up. It also goes into databases, Jira, GitHub, Figma and server security. For /mcp and the other in-session commands, the slash commands reference walks through them.

To see these articles more often on Google, add Harness Engineering to your preferred sources.

You might also like