Skip to content

Menu

Tutorials

How to Add MCP Servers to Claude Code: Scopes, OAuth and Fixes

AIDToolStack EditorialNovember 27, 20267 min read
MCPClaude CodeGitHubPlaywright
Share:Twitter

Claude Code is a terminal tool, so it makes sense that its MCP setup is mostly a CLI job. You can hand-edit JSON if you want to, but most of the time you'll run claude mcp add, pick a scope, and check the result with /mcp. This walkthrough covers that whole loop with two real servers: GitHub's official MCP server (remote, with a token) and Microsoft's Playwright MCP (local, over stdio). Every command below comes from the Claude Code MCP docs or from each server's own README and install guide, as they read in November 2026.

If you use more than one client, our overview post on configuring MCP servers in Claude Code, Cursor and VS Code compares the three. This one goes deeper on Claude Code alone.

How claude mcp add picks a scope and where each scope stores its config
How claude mcp add picks a scope and where each scope stores its config

The shape of claude mcp add

There are two forms, one per transport. A local server is a process Claude Code launches and talks to over stdin/stdout:

claude mcp add [options] <name> -- <command> [args...]

A remote server is a URL:

claude mcp add --transport http <name> <url>

The -- in the stdio form matters more than it looks. Everything before it belongs to Claude Code (--transport, --env, --scope). Everything after it is passed to the server untouched. If you forget it, flags meant for the server, like Playwright's --headless, get parsed by Claude Code instead and the command fails or does something you didn't ask for.

There's one more ordering trap the docs call out: --env accepts several KEY=value pairs, so if your server name comes straight after --env, the CLI reads the name as another pair and rejects it. Put another option, such as --transport stdio, between them.

Scopes: local, project and user

Every server you add lands in one of three scopes. The docs summarise them like this:

ScopeLoads inShared with the teamStored in
local (default)current project onlyno~/.claude.json
projectcurrent project onlyyes, through git.mcp.json in the project root
userall your projectsno~/.claude.json

Pick with --scope local|project|user. My rule of thumb: personal experiments stay local, anything the whole repo needs (a Playwright server for end-to-end work, say) goes in project scope so it's checked in, and general-purpose servers you want everywhere, like GitHub, go in user scope.

Project scope has a safety step. Because a .mcp.json in a cloned repo can launch arbitrary commands, Claude Code asks for approval in interactive sessions before it uses project-scoped servers. If you clicked the wrong answer, claude mcp reset-project-choices clears those decisions so you get asked again.

Worked example 1: GitHub's remote server

GitHub runs a hosted MCP server at https://api.githubcopilot.com/mcp/. The GitHub MCP server install guide for Claude Code gives this command for the remote endpoint, authenticated with a personal access token:

claude mcp add --transport http github https://api.githubcopilot.com/mcp \
  -H "Authorization: Bearer YOUR_GITHUB_PAT"

The guide also offers an add-json form for Claude Code 2.1.1 and newer, and says to fall back to the command above if add-json returns "Invalid input", which it mentions happening on Windows. Run these in your normal shell, not inside a Claude Code session.

Pasting a raw token into a command leaves it in your shell history. A cleaner option is to keep the token in an environment variable and reference it from .mcp.json, which supports ${VAR} and ${VAR:-default} expansion:

{
  "mcpServers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp",
      "headers": {
        "Authorization": "Bearer ${GITHUB_PAT}"
      }
    }
  }
}

That file can be committed safely because it holds a reference, not the secret. If you would rather not write it by hand, our MCP config generator produces the JSON. Each developer exports GITHUB_PAT in their own shell.

If you'd rather run GitHub's server locally, the same guide shows the Docker route:

claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=YOUR_GITHUB_PAT -- \
  docker run -i --rm -e GITHUB_PERSONAL_ACCESS_TOKEN ghcr.io/github/github-mcp-server

Note the -e appears twice for different reasons. The first is Claude Code's flag and sets the variable for the process it launches. The second is Docker's flag and forwards that variable into the container. The README adds that you can limit which tool groups load with GITHUB_TOOLSETS; the defaults are context, repos, issues, pull_requests and users.

Worked example 2: Playwright over stdio

The Playwright MCP server README gives a one-liner for Claude Code:

claude mcp add playwright npx @playwright/mcp@latest

To share it with the team and run the browser without a window, use project scope and pass the server's own flag after the separator:

claude mcp add --scope project playwright -- npx @playwright/mcp@latest --headless

That writes an entry into .mcp.json at the repo root. Commit it, and the next person who opens Claude Code in that repo gets the approval prompt and then the server. The README lists other flags worth knowing: --browser picks chrome, firefox, webkit or msedge, and --isolated keeps the browser profile in memory instead of on disk.

Remote servers with OAuth

Plenty of hosted servers skip tokens and use OAuth instead. Add the server by URL with no header, then authenticate. Inside a session, run /mcp, pick the server, and follow the browser login. From the shell there are matching commands:

claude mcp login sentry
claude mcp logout sentry

The shell form is handy over SSH: it prints the authorization URL rather than trying to open a browser, and --no-browser forces that behaviour. One caveat from the docs: if you set an Authorization header and the server rejects it, Claude Code reports the connection as failed. It does not quietly fall back to OAuth. Pick one method per server. For the protocol side of this, see our post on remote MCP servers and OAuth.

Managing what you've added

The everyday commands:

claude mcp list            # every server and its status
claude mcp get github      # details for one server
claude mcp remove github   # delete it

Inside a session, /mcp shows the same status list and is where you go to log in. If you're hand-writing .mcp.json, run it past our MCP config validator before you restart, since a stray comma takes the whole file down.

Five errors and how to fix them

1. "Failed to connect" with a 401. The docs say a server with bad credentials shows a ✘ in /mcp, and the failure detail includes the HTTP status. A 401 from GitHub almost always means the PAT expired or lacks the scopes you need. GitHub's guide suggests checking for the repo scope. Make a new token, update the header or variable, and restart.

2. Server flags swallowed by Claude Code. You wrote claude mcp add playwright npx @playwright/mcp@latest --headless and got an unknown-option error. Add the -- before npx so --headless reaches the server.

3. A ${VAR} that never expanded. If a variable in .mcp.json has no value and no default, Claude Code warns and loads the server with the literal ${VAR} text, which then fails as a bad URL or bad token. Export the variable in the shell you launch claude from. Watch out for empty strings: the docs note an empty variable counts as set, so ${VAR:-default} expands to nothing rather than the default.

4. Slow servers timing out at startup. Docker images on a cold pull, or npx downloading a package for the first time, can take a while. Raise the startup timeout with MCP_TIMEOUT, for example MCP_TIMEOUT=10000 claude for ten seconds. For long-running tool calls there's MCP_TOOL_TIMEOUT, or a per-server "timeout" value in milliseconds inside .mcp.json.

5. The server is in .mcp.json but never loads. Either you declined the project approval prompt, or you're running Claude Code from a different directory than the one holding the file. Run claude from the repo root, and if needed claude mcp reset-project-choices to get the prompt back. For local and user scopes, remember the config lives in ~/.claude.json, not the repo, so a teammate won't see it.

For deeper protocol-level debugging, our guide to debugging MCP servers with MCP Inspector shows how to talk to a server directly, outside any client.

Where to go next

Once GitHub and Playwright are working, browse the MCP server directory for others, check our Claude Code profile for pricing and plans, and read up on tool poisoning and prompt injection before you approve servers from repos you didn't write. If you're weighing Claude Code against the editor-based options, Claude Code vs GitHub Copilot is a good starting point.

AE

Written by AIDToolStack Editorial

Researched from official documentation, specifications and vendor pages, listed under Sources below. Last checked November 2026.

Sources

  1. code.claude.com /docs/en/mcp
  2. github.com /github/github-mcp-server/blob/main/docs/installation-guides/install-claude.md
  3. github.com /github/github-mcp-server
  4. github.com /microsoft/playwright-mcp

Related Posts

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…