# Add an MCP Server to Claude Code: Scopes and Permissions

> Add an MCP server to Claude Code with claude mcp add: http vs stdio, local, project and user scope, .mcp.json, MCP permission rules, and the risks.

URL: https://www.matthewswong.com/en/learn/claude-code-tips/add-mcp-server-claude-code/

Claude Code tips · Lesson 7 of 13 · Reviewed on 17 October 2026 · Checked against Claude Code v2.1.301 · By Matthews Wong (https://www.matthewswong.com/en/about/)

> An MCP server is a separate program or web service that gives Claude Code extra tools, such as a database query or a ticket lookup, over the Model Context Protocol. You add one with claude mcp add, choose where its config lives with a scope, and control what Claude may call with permission rules named mcp__server__tool.

## You will be able to

- Add an http or stdio MCP server with the right flags, and pick local, project or user scope on purpose.
- Write permission rules that name MCP tools, and know why deny rules win.
- Spot the security risks of a server you did not write.

## From claude mcp add to one tool call

claude mcp add writes a server entry to a config file; Claude Code connects to the server, lists its mcp__server__tool names, and checks permission rules before each call.

1. **Meet the parts.** An MCP server is a separate process or web service that offers tools. Claude Code is the client: it reads a config entry, connects, and exposes the server's tools to Claude.
2. **Add it with a scope.** claude mcp add writes the entry. Scope decides where: local is the default and private to you, project writes .mcp.json in the repo for everyone, user covers all your projects.

   ```
   claude mcp add --transport http docs https://example.com/mcp --scope project
   ```

   *Predict:* A teammate pulls your repo, which has a project-scoped server. They start Claude Code. What happens? (It connects silently / It asks them to approve it first / It ignores the file until they run /mcp)
3. **Approve, then connect.** In an interactive session Claude Code asks before using a project server from .mcp.json. Claude Code then connects, and claude mcp list shows each server's health.

   ```
   claude mcp list
   ```
4. **Tools get names.** The server lists its tools. Each appears to Claude as mcp__server__tool. With tool search, only the names load at the start; full definitions are fetched when needed.

   ```
   mcp__docs__search
   ```
5. **Rules decide the call.** Before the call runs, permission rules are checked in order: deny, then ask, then allow. The first match wins, however specific a later rule is. No match means a prompt.

   ```
   mcp__docs__*  (allow)
   mcp__docs__search  (deny)
   ```

   *Predict:* An allow rule and a deny rule both match one MCP tool call. Which one applies? (Allow, because it is more specific / Deny, because deny is checked first / Whichever is listed first in the file)
6. **Result and risk.** The result enters the context window. Output over 10,000 tokens triggers a warning and the default cap is 25,000. A server that fetches outside content can carry prompt injection.

   ```
   MAX_MCP_OUTPUT_TOKENS=50000
   ```

## What is an MCP server, and how do you add one to Claude Code?

The Model Context Protocol is an open standard for connecting AI tools to outside tools and data. In Claude Code, an MCP server is the other end of that connection: a program or web service that offers tools, and sometimes resources and prompts, which Claude can then call. Typical examples are an issue tracker, a database or a monitoring system.

You add a server with claude mcp add. There are two transports you will use. For a remote server, pass --transport http and a URL; the docs recommend http for remote servers and mark the older sse transport as deprecated. For a local process, use stdio and put the server's own command after a double dash: claude mcp add my-server -- my-command --some-flag. Everything after the -- goes to the server untouched, so its flags are not mistaken for Claude's.

Manage servers with claude mcp list, claude mcp get and claude mcp remove. Inside a session, /mcp shows each server's status and lets you authenticate, reconnect or toggle it. For a remote server that needs OAuth, claude mcp login starts the browser flow from the shell. Environment variables for a stdio server go in --env, headers for an http server in --header.

## Which scope should an MCP server use, and what is .mcp.json?

Scope is chosen with --scope (or -s) and answers two questions: who sees the server, and where is it stored. Local is the default: the server loads only in the current project and is not shared. Project stores it in a .mcp.json file at the repository root, so version control shares it with everyone who clones. User loads it in all of your projects but shares it with no one.

When the same server name is defined in several places, local beats project, project beats user, and then come plugin servers and claude.ai connectors. The whole entry from the winning source is used; fields are not merged across scopes. A .mcp.json entry can read environment variables with a dollar-brace VAR syntax, optionally with a default after :-, in command, args, env, url and headers, so a shared file can avoid holding secrets.

Because a project file can start a process on your machine, Claude Code prompts for approval in interactive sessions before using a server from .mcp.json. claude mcp reset-project-choices clears those answers. The caveat is non-interactive use: a claude -p run cannot show the prompt, so it loads project servers without asking.

## How do permissions and security work for MCP tools?

Every MCP tool is named mcp__server__tool, and permission rules use that name. A rule of mcp__puppeteer matches any tool from the puppeteer server, mcp__puppeteer__* matches them with a wildcard, and mcp__puppeteer__puppeteer_navigate matches one tool. Rules run in the order deny, ask, allow, and the first match wins, so a deny in any scope beats an allow. In Manual mode, a tool with no matching rule prompts you.

Two guard rails keep broad rules safe. An allow rule may use a wildcard only after a literal mcp__server__ prefix, so an allow of mcp__* is skipped with a warning and approves nothing. And a mcp__ rule with parentheses is skipped when settings load; to match a parameter on an MCP tool, pass a deny rule with --disallowedTools. A deny of mcp__* is valid and removes every MCP tool from Claude's context.

The security stance in the docs is short: verify you trust each server before connecting it, because servers that fetch external content can expose you to prompt injection. An MCP tool result is text that goes straight into Claude's context, so a hostile web page or ticket can try to steer it. Prefer servers you can read, scope allow rules to specific tools, and keep secrets in environment variables rather than in a committed file.

## The real config behind this lesson

`app/components/blogs/McpTransportsStdioVsHttp.tsx:8-24`

```tsx
const STDIO_CONFIG = `{
  "mcpServers": {
    "local-fs": {
      "command": "node",
      "args": ["./dist/server.js"]
    }
  }
}`;

const HTTP_CONFIG = `{
  "mcpServers": {
    "remote-api": {
      "type": "http",
      "url": "https://mcp.example.com/mcp"
    }
  }
}`;
```

This repository has no .mcp.json of its own, so this is the config shape from the site's article on MCP transports. Both files use the same mcpServers key. A stdio entry names a command and its args; an http entry sets type and a url. The server names, local-fs and remote-api, become the middle part of every tool name, for example mcp__remote-api__tool.

## What breaks

- **Forgetting the double dash on a stdio server.** Without --, a flag meant for the server, such as --port, is read as one of Claude's own options. Write claude mcp add my-server -- my-command --port 3000. A second trap: --env takes several KEY=value pairs, so a server name placed right after it is read as another pair. Put --transport stdio between them.
- **An allow rule that silently does nothing.** An allow rule of mcp__* is skipped with a warning, and an mcp__ rule with parentheses is skipped on load. Name the server first: mcp__github__get_* allows only that server's get_ tools. Run claude doctor to see skipped rules.
- **Expecting scopes to merge.** If a server named docs exists in local and in project scope, the local entry is used whole. Its fields are not merged with the project entry, so a missing header in the local copy is not filled in from .mcp.json.
- **An unset variable becomes literal text.** In .mcp.json, an unset variable with no default produces a warning and the config loads with the literal dollar-brace text. Add a default after :- or export the variable first. In remote url and headers, some credential variables are read as empty on purpose, so a project file cannot leak them.
- **A committed .mcp.json in unattended runs.** claude -p shows no approval prompt, so every server in a repository's .mcp.json connects. Before running it in a repo you did not write, start with --bare or pass --strict-mcp-config with your own --mcp-config, or list the server in disabledMcpjsonServers.

### The three MCP scopes

| Scope | Loads in | Shared with the team | Stored in |
| --- | --- | --- | --- |
| local (default) | This project only | No | ~/.claude.json |
| project | This project only | Yes, through version control | .mcp.json in the repo root |
| user | All your projects | No | ~/.claude.json |

## Try it yourself

You need Claude Code and a scratch git repository. This adds a server, inspects it, and then limits what Claude may call. The URL below is a placeholder, so swap in a real server you trust.

1. Add an http server in project scope, so it is written to .mcp.json in the repo.

   ```bash
   claude mcp add --transport http docs https://example.com/mcp --scope project
   ```
2. Open the file it wrote, and look at the entry. Then list servers and read one in detail.

   ```bash
   cat .mcp.json
   claude mcp list
   claude mcp get docs
   ```
3. Add a stdio server in the default local scope. Note the double dash before the server's own command.

   ```bash
   claude mcp add --env API_KEY=YOUR_KEY --transport stdio airtable -- npx -y airtable-mcp-server
   ```
4. Start Claude Code, approve the project server when asked, and run /mcp to see each server's status.

   ```bash
   claude
   > /mcp
   ```
5. Pre-approve one server's tools and block a risky one in .claude/settings.json. Deny wins over allow whatever the order.

   ```bash
   {
     "permissions": {
       "allow": ["mcp__docs__*"],
       "deny": ["mcp__airtable"]
     }
   }
   ```

## Quick quiz

1. **You want every teammate who clones the repo to get the same MCP server. Which scope do you use?**
   A. local, the default
   B. project, which writes .mcp.json
   C. user, which covers all your projects
   Answer: B. Project scope stores the entry in .mcp.json at the repo root, so version control shares it. Local and user scopes live in your own configuration and are shared with no one.

2. **What does the double dash do in claude mcp add my-server -- my-command --port 3000?**
   A. It marks the server as deprecated
   B. It switches the transport to http
   C. It passes everything after it to the server untouched
   Answer: C. Everything after -- is the server's own command line. Without it, --port would be parsed as a Claude Code option.

3. **Which rule pre-approves every tool from a server named puppeteer?**
   A. mcp__puppeteer (or mcp__puppeteer__*)
   B. mcp__* in the allow list
   C. mcp__puppeteer(*)
   Answer: A. A server name alone matches all of its tools. An unanchored mcp__* allow is skipped with a warning, and a mcp__ rule with parentheses is skipped when settings load.

## Think it through

- **Your .mcp.json uses an environment variable for a token, and it is not set on a colleague's machine. What do they get?** A warning, and the config loads with the literal variable text in place of a value, so the server most likely fails to authenticate. Give the variable a default after :- where a default makes sense, or document that it must be exported.
- **Why can a deny rule in user settings block a tool that project settings allow?** Rules are evaluated in the order deny, ask, allow, and the first match decides. Deny rules from any scope are checked before allow rules, so specificity and file order do not matter.
- **Why is an MCP server that fetches web pages riskier than one that only reads a local file you wrote?** Its results are text from someone else, placed straight into Claude's context. That text can contain instructions meant to steer Claude, which is prompt injection. The docs advise trusting each server before connecting it.

## Go deeper

- [Claude Code MCP Server Setup: Scopes, Auth, Tool Budget](https://www.matthewswong.com/en/blog/claude-code-mcp-server-setup-governance/)
- [MCP Transports: stdio vs Streamable HTTP](https://www.matthewswong.com/en/blog/mcp-transports-stdio-vs-http/)
- [MCP Server Security Checklist for Developers](https://www.matthewswong.com/en/blog/mcp-server-security-checklist/)

## Sources

- [Claude Code docs: Connect Claude Code to tools via MCP](https://code.claude.com/docs/en/mcp)
- [Claude Code docs: project server approvals and workspace trust](https://code.claude.com/docs/en/mcp#project-server-approvals-and-workspace-trust)
- [Claude Code docs: Configure permissions (MCP rule syntax)](https://code.claude.com/docs/en/permissions)
- [Claude Code docs: what runs before you trust a folder](https://code.claude.com/docs/en/permissions#what-runs-before-you-trust-a-folder)
- [Claude Code docs: CLI reference](https://code.claude.com/docs/en/cli-reference)

---

- HTML version: https://www.matthewswong.com/en/learn/claude-code-tips/add-mcp-server-claude-code/
- Bahasa Indonesia: https://www.matthewswong.com/id/learn/claude-code-tips/add-mcp-server-claude-code/
- Site index for agents: https://www.matthewswong.com/llms.txt
- Sitemap: https://www.matthewswong.com/sitemap.xml
- API description (OpenAPI): https://www.matthewswong.com/openapi.json
