MCP Servers & Security

Claude Code + MCP: Connect Servers Safely with .mcp.json, Scopes and Approvals

15 October 2026 · Updated 28 November 2026 · 12 min read · by Yang Kai

Wire MCP servers into Claude Code the safe way: local, project and user scopes explained, the approval flow, secrets kept out of .mcp.json, and an annotated config with three starter servers.

Annotated .mcp.json with three starter servers

Contents
  1. What you need before you start
  2. Step 1: Decide the scope before you add anything
  3. Step 2: Add your first server with the CLI
  4. Step 3: Or write .mcp.json directly
  5. Step 4: Approve project servers like you mean it
  6. Step 5: Keep secrets out of the committed file
  7. Step 6: Verify, authenticate, and manage
  8. Common mistakes
  9. How we researched this

Adding an MCP server to Claude Code takes one command. That speed is the risk: a single line can hand your agent filesystem access, database queries or browser control, and the command will not ask whether you meant the scope it chose by default.

This is the deliberate version of the setup. It follows Anthropic’s own MCP documentation for Claude Code, checked November 2026: the three configuration scopes and where each one lives, the approval flow for shared configs, how to keep secrets out of the committed file, and an annotated .mcp.json with three starter servers chosen for small blast radius. By the end you will have a working setup you can explain line by line — which is the correct standard for anything that runs code on your machine.

The whole setup in five lines: default to local scope for experiments, project scope (.mcp.json) for servers the team shares, user scope for personal utilities. Approve project servers only after reading the diff. Reference secrets as environment variables, never literals. Verify with /mcp before you trust a session.

What you need before you start

Step 1: Decide the scope before you add anything

Claude Code stores MCP servers at three scopes, across two files. Choosing the scope is the first safety decision, and it happens before any command runs.

Scope Stored in Who gets it Approval needed
Local (the default) ~/.claude.json, under this project’s entry Only you, only this project No — it is your own config
Project .mcp.json in the project root Everyone who clones the repo Yes — each person is prompted before first use
User ~/.claude.json, top-level mcpServers Only you, in every project No — it is your own config

When the same server name exists at several scopes, local wins over project, and project wins over user. That precedence is a tool, not a footnote. It means you can override a shared project server with a local entry of the same name — point the team’s staging database server at your own sandbox, say — without touching the file everyone else uses. It also means a stale local entry can silently shadow the team’s updated server, which is the first thing to check when a colleague’s setup behaves differently from yours.

Two consequences follow. Local scope is the right home for experiments and for anything carrying a personal credential, because it never leaves your machine. User scope is for personal utilities you want everywhere — a documentation lookup, for instance — and nothing project-specific or credential-bearing belongs there, because it will silently follow you into every repo you open, including one you cloned an hour ago.

Project scope is the team mechanism, and its defining feature is the approval prompt covered in Step 4. If a server would surprise a teammate, it is in the wrong scope.

Step 2: Add your first server with the CLI

The claude mcp add command writes the config for you. Without a --scope flag it registers the server at local scope — private, this project only. That default is the safe one for a first server.

# Local stdio server (runs on your machine): Playwright for browser work
claude mcp add playwright -- npx -y @playwright/mcp@latest

# Remote HTTP server: Context7 for current library documentation
claude mcp add --transport http context7 https://mcp.context7.com/mcp

# The same server, shared with your team instead (writes .mcp.json)
claude mcp add --transport http --scope project context7 https://mcp.context7.com/mcp

Two server shapes appear here, and the distinction matters for risk. A stdio server is a program Claude Code launches on your machine — the command after -- runs with your permissions. An HTTP server is a remote endpoint; nothing executes locally, and access is usually controlled by an account sign-in instead. Prefer hosted HTTP servers from the vendor where one exists; reserve stdio for tools that genuinely need your machine, like a browser or your files.

Two variations worth knowing. Servers that need a key at launch take it through --env, as in claude mcp add --env DOCS_API_KEY=... -- npx -y acme-docs-mcp — the value lands in your private local config, not in anything shared. And when a vendor hands you a ready-made JSON snippet instead of a command, claude mcp add-json <name> '<json>' installs it at local scope by default, with the same --scope flag available. The snippet deserves the same read-before-you-run scrutiny as any config in Step 3.

You should see an “Added” confirmation for each command. That only means the configuration was written — verification is Step 6.

Step 3: Or write .mcp.json directly

For project scope, writing the file by hand is often better than the CLI: the file is reviewed in pull requests, and reading it is the security habit this whole guide is building. Create .mcp.json in the project root. Annotations follow the config, since JSON has no comments.

{
  "mcpServers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/"
    },
    "context7": {
      "type": "http",
      "url": "https://mcp.context7.com/mcp"
    },
    "playwright": {
      "command": "npx",
      "args": ["-y", "@playwright/mcp@latest"]
    }
  }
}

Why these three, and how to think about each:

GitHub, hosted and remote. Issues, pull requests and repo context, served by GitHub itself over HTTP. No local process runs, and access rides on your GitHub sign-in (Step 6 covers the authentication flow). This is the lowest-risk shape a server can take.

Context7 for documentation. Library docs are the safest category of server: outbound lookups, no local write power, and they replace the error-prone habit of letting the agent code from memory of an outdated API version. Low risk, immediate payoff.

Playwright, local and deliberate. The one stdio server in the set, because driving a real browser requires your machine. It is also the one with real power — it can click, type and submit — so point it at staging or a local dev server, never at a production admin panel. MCP for browsers and clients covers browser-server guardrails in full.

One note for Claude Code specifically: it already reads and writes files with built-in tools, so a filesystem server adds little here — it earns its place in clients without built-in file access. If you do add one anywhere, pin its final argument to a single project directory. Granting a filesystem server your home directory “for convenience” is the most common MCP mistake, and it is a mistake in every client. For the wider catalogue beyond these three, see MCP servers worth installing and the job-by-job picks in best MCP servers by job.

Step 4: Approve project servers like you mean it

When Claude Code opens a project whose .mcp.json contains servers you have not approved, it lists them as pending approval and asks before using them. Read that prompt the way you would read a phone permissions screen: what command will run, with what arguments, from what source? A server entry is, at bottom, “run this executable with these arguments, and trust what it says.” An entry pointing at a well-known package run via npx is a different risk from an entry pointing at a script inside the repo itself — the latter means the repo can execute code on your machine under the banner of a tool call.

Two habits make the flow work as designed:

One documented caveat: in non-interactive runs (claude -p, Agent SDK and cloud sessions) there is no one to prompt, so project servers can load without the interactive approval step. That is a reason to keep .mcp.json clean enough that you would accept it unattended — and to keep credential-bearing servers out of it entirely, which is Step 5. The permission layer underneath all of this — what the agent may do with the tools once connected — is covered in Claude Code permissions and sandboxing.

Teams that manage many machines get two settings-level controls on top of individual approvals. enableAllProjectMcpServers pre-approves every server in a project’s .mcp.json, which trades the per-person checkpoint for smoother onboarding — reasonable only where repository access itself is tightly controlled. disabledMcpjsonServers does the opposite, blocking named project servers outright in every permission mode. Most small teams need neither. Knowing they exist matters the first time a contractor’s laptop or a CI runner enters the picture, because both settings are how an organisation turns a per-person habit into policy.

Step 5: Keep secrets out of the committed file

.mcp.json is committed to version control. Anything written literally into it is, for practical purposes, published to everyone with repo access — and to the repo’s entire future history. So secrets travel by reference, not by value.

Claude Code expands environment variables inside .mcp.json, including in url, command, args, env and headers, and supports a fallback form:

{
  "mcpServers": {
    "internal-docs": {
      "command": "npx",
      "args": ["-y", "acme-docs-mcp"],
      "env": {
        "DOCS_API_KEY": "${DOCS_API_KEY}",
        "DOCS_REGION": "${DOCS_REGION:-eu}"
      }
    }
  }
}

${DOCS_API_KEY} is read from your shell environment at launch; ${DOCS_REGION:-eu} falls back to eu when unset. Each teammate supplies their own values, and nothing sensitive enters git. Servers that authenticate by account sign-in (OAuth) avoid the problem entirely — prefer them when a vendor offers both routes. Where tokens should live, how they should be scoped, and how rotation works is the whole subject of MCP auth explained.

Step 6: Verify, authenticate, and manage

Configuration written is not configuration working. Start Claude Code in the project and run /mcp. Each server shows a status — connected, failed, or needing authentication. For an OAuth server such as GitHub, select it in that panel and complete the browser sign-in; from the shell, claude mcp login <name> does the same job.

The management commands you will actually reuse:

Command What it does
claude mcp list Show configured servers and their status
claude mcp get <name> Show one server’s full definition
claude mcp remove <name> Delete a server from its scope
claude mcp login <name> / logout <name> Sign in to a server, or clear stored OAuth credentials
claude mcp reset-project-choices Reset project-server approvals so the prompt returns

You should now have three connected servers, at scopes you chose on purpose, with no secret in any committed file. That — not the size of the server list — is what a mature setup looks like. Your second MCP server covers how to judge the fourth and fifth additions, and testing MCP servers shows how to check a server’s behaviour before it joins a real project.

Common mistakes

How we researched this

The scope table, file locations, approval behaviour and variable-expansion syntax follow Anthropic’s MCP documentation for Claude Code (the MCP quickstart and reference at code.claude.com), checked November 2026. Server endpoints are the vendors’ published ones: GitHub’s hosted MCP server, Upstash’s Context7 endpoint, and Microsoft’s Playwright MCP package. No server was installed for the writing of this article; the steps reproduce the documented flow, and the /mcp verification step exists precisely so you can confirm each claim on your own machine.

FAQ

What is .mcp.json? The project-level config file that declares which MCP servers Claude Code should start for this repo: the command or URL, its arguments, and its environment. Committed to the repo, it gives a teammate the same setup — which is why secrets must never live in it as literals.

What is the difference between local, project and user scope? Local (the default) is private to you and active only in the current project. Project scope is shared through .mcp.json and triggers an approval prompt for each person. User scope is private to you but active in every project you open. All three are explained with their file locations in Step 1.

Which servers should a beginner start with? Three, maximum: one for documentation lookup, one hosted server for a service you use daily, one local tool you genuinely need. The annotated config in Step 3 uses exactly that shape. For the reasoning behind the picks, what MCP does for builders maps servers to the tasks they change.

Why did Claude Code ask me to approve a server? Because a project .mcp.json is code from the repo, and running it means running that repo’s commands. Read what you are approving — the approval prompt is a security feature, not friction.

A server shows as failed or pending in /mcp. What now? Pending approval means a project server is waiting on your decision — approve it, or reset the choices with claude mcp reset-project-choices. Failed usually means the command could not run (check Node.js is installed for npx servers) or a remote server needs sign-in via claude mcp login.

Category: MCP Servers & Security · Tags: #claude-code #mcp #tutorial #security #starters

Next step: this article is part of MCP guides, which covers the full topic from first setup to advanced use.

Related guides