MCP in Claude Code is how you connect the agent to tools and data it doesn't have out of the box. The Model Context Protocol is an open standard: a server exposes tools, resources and prompts, Claude Code connects to it as a client, and the server's tools show up next to the built-in ones under the same permission rules. Out of the box Claude Code can read files, run commands and search the web. To query your Postgres database, review a GitHub pull request, file a Jira ticket or pull a design from Figma, you add an MCP server, usually with one claude mcp add command. This guide covers adding servers, where their configuration lives, how authentication works, how to keep many servers from filling the context window, and the security settings a team should set before connecting anything real.
Why this matters for CCA-F
MCP integration is a scored domain on Anthropic's Claude Certified Architect exam. If certification is on your roadmap, the concepts here (transports, scopes, tool design) appear in exam scenarios, and our Claude Certified Architect practice tests drill them.
The mental model
An MCP server exposes three kinds of things, and each appears in Claude Code in its own way:
- Tools are actions, such as
query_databaseorcreate_issue. They appear to Claude next to the built-in tools, namedmcp__<server>__<tool>, and your permission rules decide whether a call runs. - Resources are data you can point Claude at. Type
@in a prompt and they appear in the same menu as files, written as@server:protocol://resource/path, for example@github:issue://123. - Prompts are reusable instructions. They become commands: type
/and an MCP prompt shows up as/servername:promptname (MCP), and typing/mcp__servername__promptnameruns it too.
Claude Code is the client. When a server is configured and connected, Claude decides when to call its tools, and the same permission system that governs shell commands decides whether each call is allowed. Because any MCP server works with any MCP client, the ecosystem builds a connector once (GitHub, Notion, Sentry, Stripe, databases, browsers and hundreds more) and every client can use it.
Adding a server
Every server is added with claude mcp add, and the transport decides the shape of the command.
# Remote server over HTTP (the recommended transport for remote servers)
claude mcp add --transport http notion https://mcp.notion.com/mcp
# Remote server with a token in a header
claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \
--header "Authorization: Bearer YOUR_GITHUB_PAT"
# Local server that Claude Code starts as a process (stdio)
claude mcp add --transport stdio db -- npx -y @bytebase/dbhub \
--dsn "postgresql://readonly:[email protected]:5432/analytics"
# Manage what you have
claude mcp list
claude mcp get github
claude mcp remove github
A few rules save time:
- HTTP for remote servers. Anthropic's documentation recommends it as the most widely supported transport for cloud services. Server documentation sometimes calls it
streamable-http, and Claude Code accepts that name as an alias in JSON configuration. - SSE is deprecated. Some services still offer only an SSE endpoint. Add them with
--transport httpanyway: from Claude Code v2.1.265, Claude Code tries HTTP first and switches to SSE when the server doesn't accept it. - The
--matters for stdio servers. Everything after--is the command that starts the server and is passed to it untouched, so a server flag such as--port 8080after--reaches the server instead of being parsed byclaude. Put--env KEY=valuepairs before the server name, with another option such as--transport stdiobetween--envand the name. - WebSocket servers (for servers that push events) are added with
claude mcp add-json, because--transportdoesn't acceptws, and they authenticate with headers only. - A JSON entry with a
urlneeds atype. Claude Code reads an entry withouttypeas a stdio server, so an entry that has aurland notypeis skipped with an error telling you to add"type": "http".
Two more ways to add servers: claude mcp add-json <name> '<json>' takes a configuration copied from a server's documentation, and claude mcp add-from-claude-desktop imports the servers you already set up in Claude Desktop.
Inside a session, /mcp shows every server with its status and tool count, and lets you reconnect, sign in, or switch a server off for the current project without deleting its configuration.
Signing in to remote servers
Remote servers that need a login use OAuth 2.0. Add the server, run /mcp in a session and follow the browser sign-in; Claude Code stores the token and refreshes it. From the shell, claude mcp login <name> runs the same flow without opening a session.
Three details trip people up:
- Headless runs can't sign in. A
claude -prun or an Agent SDK application has no/mcppanel, so complete the sign-in in an interactive session (or withclaude mcp login) before the pipeline needs the server. - A configured header wins. If you set
headers.Authorizationand the server rejects it, Claude Code reports the connection as failed and doesn't fall back to OAuth. Fix the token, or remove the header to use OAuth. - Removing a server deletes its stored tokens locally but doesn't revoke them at the server that issued them. Run
claude mcp logout <name>first if you want them revoked where the server supports it.
The three scopes, and which one to use
Where a server's configuration lives decides which projects load it and whether your team shares it.
Claude Code MCP scopes
| Scope | Loads in | Shared with team | Stored in | Use it for |
|---|---|---|---|---|
| local (default) | The current project only | No | ~/.claude.json, under that project | Personal experiments and servers holding credentials only you should have |
| project | The current project only | Yes, through version control | .mcp.json at the repository root | The team standard: the project database, issue tracker, docs source |
| user | All your projects | No | ~/.claude.json | Personal utilities you want everywhere, such as a browser server |
Pass the scope when you add the server: claude mcp add --transport http shared-server --scope project https://example.com/mcp creates or updates .mcp.json. Note that MCP's "local" scope lives in ~/.claude.json in your home directory, which is a different file from the project's .claude/settings.local.json.
When the same server name is defined in more than one place, Claude Code connects once, using the whole entry from the highest-precedence source, with no merging of fields:
- Local scope
- Project scope
- User scope
- Servers from plugins
- claude.ai connectors
Plugins and connectors are matched by endpoint, so a plugin server that points at the same URL as one you configured counts as a duplicate. A server your organization provides through managed settings ranks above all of these.
Writing .mcp.json by hand
A project file is plain JSON, and you can edit it directly:
{
"mcpServers": {
"db": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@bytebase/dbhub", "--dsn", "${DATABASE_URL}"]
},
"api-server": {
"type": "http",
"url": "${API_BASE_URL:-https://api.example.com}/mcp",
"headers": { "Authorization": "Bearer ${API_KEY}" }
}
}
}
Environment variables expand in command, args, env, url and headers, as ${VAR} or ${VAR:-default}. That keeps secrets out of the checked-in file: each teammate sets API_KEY in their own shell. If a variable is unset and has no default, the server still loads with the literal ${VAR} text, and claude mcp list warns you about it.
One safety rule is built in: in a remote server's url and headers, Claude Code reads credential variables such as ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN and your cloud provider's keys as empty, so a repository's .mcp.json can't send your Claude credentials to a server it names. To pass one of them on purpose, copy it into a variable with a name of your own.
Keeping many servers from filling the context
Every tool definition costs context, and teams with ten or more servers used to feel it. Claude Code now handles this with tool search, which is on by default on current models: only tool names and server instructions load at session start, and Claude searches for a tool's full definition when it needs it. There is no fixed per-server tool cap; the practical limit is your context budget.
The ENABLE_TOOL_SEARCH environment variable changes the behavior:
ENABLE_TOOL_SEARCH values
| Value | What happens |
|---|---|
| unset or true | MCP tools are deferred and loaded on demand (loaded upfront on older models that do not support tool search) |
| auto | Tools load upfront while their definitions total under 10% of the context window, and tool search turns on at 10% or more |
| auto:N | The same threshold mode with your own percentage, such as auto:5 |
| false | All MCP tools load upfront, with no deferral |
When one server's tools are needed on nearly every task, set "alwaysLoad": true in that server's entry. Its tools then load upfront whatever ENABLE_TOOL_SEARCH says, while the rest stay deferred. Use it sparingly, since every upfront tool takes context for the whole session.
Large tool results are managed too. Claude Code warns when an MCP tool returns more than 10,000 tokens, and the default maximum is 25,000 tokens, which you can change with MAX_MCP_OUTPUT_TOKENS. A successful text result over the limit is saved to a file, and Claude gets the file path instead, so it can read only what it needs.
Timeouts
- Startup:
MCP_TIMEOUTsets how long Claude Code waits for a server to start, 30 seconds by default. - Each tool call: set a
timeoutin milliseconds on the server's entry, orMCP_TOOL_TIMEOUTacross all servers. - Silent servers: a call that gets no response and no progress notification for the idle window fails with an error. The window is five minutes for remote servers and 30 minutes for stdio servers, and
CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUTchanges it. - Long calls don't block you: a call in the main conversation that runs past two minutes moves to a background task.
Security, before convenience
An MCP server runs with your privileges and writes text that Claude reads as instructions, so treat adding one like adding a dependency that can act.
Install only servers you trust. A malicious or compromised server can return poisoned results, and its tool names and descriptions are read by the model. Prefer official vendor servers and widely used community ones, and read the source of anything obscure before giving it real credentials.
Scope credentials down. Give the database server a read-only database user, as in the DBHub example above, and give API tokens the minimum scopes. A server can only misuse what you handed it.
Write permission rules for MCP tools. mcp__github__* matches every tool from the github server, and mcp__github__create_issue matches one tool. Rules are checked deny first, then ask, then allow, so a deny rule on a server can't be undone by a narrower allow rule. A server name containing characters such as . or spaces appears with _ in tool names, so a server configured as my.server is written mcp__my_server__*. Our permissions guide covers the full rule syntax and how settings files combine.
Know when project servers load without asking. In an interactive session, Claude Code asks before it uses a server from a project's .mcp.json, so cloning a repository doesn't silently grant it new tools (claude mcp reset-project-choices clears your answers). In claude -p runs, Agent SDK sessions and cloud sessions there is no one to ask, and project servers load without a prompt. For CI and other unattended runs, block servers you don't want with disabledMcpjsonServers, or start with --strict-mcp-config so only the servers you pass with --mcp-config load.
Remember prompt injection. Any server that returns web pages, emails or user-written text can carry instructions in its results. An agent that has both untrusted inputs and powerful write tools deserves tight approval rules on those write tools.
For organizations, managed MCP configuration lets administrators deploy a fixed set of servers with managed-mcp.json, provide servers to everyone with managedMcpServers, and restrict which servers users may add with allowedMcpServers and deniedMcpServers. If you build a server with a consent step, its tool can set _meta["anthropic/requiresUserInteraction"] to true, and Claude Code then prompts on every call, even in auto and bypass permission modes.
Other ways servers arrive
- Plugins can bundle MCP servers that start when you enable the plugin. Their tools are named with the plugin as well as the server,
mcp__plugin_<plugin-name>_<server-name>__<tool-name>, and permission rules have to use that form. - claude.ai connectors you added at claude.ai are available automatically when you sign in to Claude Code with that claude.ai account. On Team and Enterprise plans, only admins can add them.
- Claude Code itself can be a server.
claude mcp servestarts Claude Code as a stdio MCP server that another client, such as Claude Desktop, can connect to.
When a server doesn't work
claude mcp list prints a status for each server, and the status usually names the fix:
claude mcp list statuses
| Status | What it means | What to do |
|---|---|---|
| Connected | The server is up | Nothing |
| Needs authentication | The server answered 401 or 403 and you have not signed in | Run /mcp in a session, or claude mcp login <name> |
| Failed to connect | Claude Code could not reach or start the server | Read the detail on the same line or in claude mcp get <name> |
| Pending approval | A .mcp.json server you have not approved yet | Run claude in the project and approve it |
| Disabled for this project | You switched it off in /mcp | Switch it back on in /mcp |
| Blocked by enterprise managed policy | Your organization does not allow it | Ask your administrator |
Other warnings appear in claude mcp list and /mcp: hidden whitespace pasted into a token, the same server name defined in two scopes with different endpoints, a ${VAR} that isn't set, and reserved names such as workspace or computer-use, which Claude Code skips.
The connections worth making first
Start with the server that removes your most frequent context switch:
- Your database, through a server such as DBHub with a read-only user: Claude answers schema questions and writes queries against the real tables instead of guessing.
- GitHub: issues, pull requests and reviews become things Claude reads and files itself.
- A browser automation server: Claude drives a real browser, which turns "check that the form still submits" into a task you can delegate.
- Your docs or knowledge base: a documentation server keeps library knowledge current instead of fixed at the model's training date.
- Your team's system of record: wrapping an internal API in a small MCP server is often a short build that pays off every day, and tool design practices covers how to shape its tools well.
Where MCP fits in the bigger picture
MCP is one layer of Claude Code, alongside CLAUDE.md memory, permissions, hooks, skills and subagents. The MCP architecture guide goes deeper on the protocol itself, and the free Claude Code course teaches the full stack level by level, with MCP arriving once the fundamentals are in place. Connect one server today, put its write tools behind an approval rule, and Claude Code starts working with your actual systems.
Frequently asked questions
Sources:
- Connect Claude Code to tools via MCP
- Claude Code permissions: MCP rules
- Claude Code environment variables
- Managed MCP configuration
- Claude Certified Architect - Foundations
![Claude Code MCP: Add, Configure and Secure MCP Servers [2026 Guide]](/blog/claude-code-mcp-guide.webp)