Simple definition#
The Model Context Protocol (MCP) is an open standard for connecting AI applications to tools and data. Claude Code is an MCP client: each MCP server you add — a local process or a remote URL — contributes tools (and optionally resources and prompts) that Claude can call, such as “query the database”, “read the Jira ticket” or “fetch the Sentry error”. For the protocol itself, see Model Context Protocol.
Adding servers#
| Transport | Use for | Command |
|---|---|---|
| HTTP (recommended remote) | Cloud services | claude mcp add --transport http notion https://mcp.notion.com/mcp |
| HTTP with a token | Private APIs | … --header "Authorization: Bearer $TOKEN" |
| stdio | Local processes, scripts, direct system access | claude mcp add --transport stdio --env KEY=v db -- npx -y @bytebase/dbhub --dsn "$DSN" |
| SSE (deprecated) | Services with only an SSE endpoint | --transport sse (HTTP falls back to SSE automatically) |
| WebSocket | Servers that push events | claude mcp add-json events '{"type":"ws","url":"wss://…"}' |
- For stdio,
--separates Claude’s options from the server command; everything after it is passed untouched. - A JSON entry with a
urlbut notypeis an error (no type means stdio). - Stdio servers get
CLAUDE_PROJECT_DIRin their environment.
Managing servers#
claude mcp list # all servers with health: ✔ Connected, ! Needs authentication, ✘ Failed
claude mcp get notion # details for one
claude mcp remove notion # also deletes stored OAuth tokens (doesn't revoke them)
claude mcp add-json name '<json>' # add from a JSON config
claude mcp add-from-claude-desktop # import servers from Claude Desktop
claude mcp login sentry # run OAuth without the /mcp panel (--no-browser over SSH)
claude mcp reset-project-choices # forget .mcp.json approvals
Inside a session: /mcp shows status, authenticates, and enables or disables servers (/mcp disable <server> keeps it configured but off).
Scopes#
| Scope | Loads in | Shared | Stored in |
|---|---|---|---|
| local (default) | This project, only you | No | ~/.claude.json under the project path |
| project | This project | Yes, via Git | .mcp.json at the repo root |
| user | All your projects | No | ~/.claude.json |
When the same server appears in several places, Claude Code connects once, using the whole entry from the highest source: local → project → user → plugin → claude.ai connectors. An organisation’s managedMcpServers outranks all of them. Plugins and connectors are matched by endpoint, so a duplicate URL counts as the same server.
.mcp.json with environment variables#
{
"mcpServers": {
"api": {
"type": "http",
"url": "${API_BASE_URL:-https://api.example.com}/mcp",
"headers": { "Authorization": "Bearer ${API_KEY}" }
},
"db": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@bytebase/dbhub", "--dsn", "${DATABASE_URL}"],
"env": { "READ_ONLY": "true" }
}
}
}
${VAR}and${VAR:-default}expand incommand,args,env,urlandheaders. Unset variables without defaults stay literal and produce a warning inclaude mcp list.- Credential variables read as empty in remote
urlandheaders—ANTHROPIC_API_KEY, cloud provider tokens,NPM_TOKENand similar — so a committed.mcp.jsonor plugin can’t exfiltrate them. Copy a credential into a variable with your own name if a server truly needs it. streamable-httpis accepted as an alias forhttp.
Authentication#
- Remote servers that answer
401/403are flagged in/mcp; select Authenticate to run OAuth 2.0 in the browser. - Tokens refresh automatically; if the refresh token is rejected, Claude Code tells you to re-authenticate.
- Options for awkward setups: a fixed callback port, pre-configured OAuth client credentials (
--client-id,--client-secret), restricted scopes, metadata-discovery overrides, andheadersHelperfor dynamic headers from your own command. - A server whose
Authorizationheader you configured isn’t flagged for OAuth on401— fix the credential you set.
What Claude sees: tool search#
Tool search is on by default: only tool names and server instructions load at start; full schemas load when Claude searches for a tool. Adding servers therefore costs little context — but names still sit there every turn, so disable servers you don’t use.
ENABLE_TOOL_SEARCH |
Behaviour |
|---|---|
unset / true |
Defer all MCP tools (loaded up front on older models and some providers) |
auto |
Load up front while definitions total under 10% of the window; defer beyond that |
auto:N |
Same with an N% threshold |
Server authors can exempt a server from deferral (always-loaded tools) or mark tools for deferral.
Output limits#
| Limit | Default |
|---|---|
| Warning threshold | 10,000 tokens per tool result |
| Maximum | 25,000 tokens (MAX_MCP_OUTPUT_TOKENS); larger results are saved to a file Claude can read |
| Text without a declared limit | Saved to file above 50,000 characters |
| HTTP/SSE response, WebSocket message | Fails above 16 MiB |
| Server start-up | 30 s (MCP_TIMEOUT) |
Tools can declare anthropic/maxResultSizeChars to set their own text limit.
Resources and prompts#
- Resources appear in
@autocomplete:Analyze @github:issue://123 and suggest a fix. - Prompts become commands:
/mcp__github__list_prs(listed as/github:list_prs (MCP)), with arguments after the name. - Elicitation: a server can ask you for input mid-call; hooks (
Elicitation) can answer or decline automatically.
Permissions for MCP tools#
| Rule | Matches |
|---|---|
mcp__github or mcp__github__* |
Every tool from the github server |
mcp__github__create_issue |
One tool |
mcp__plugin_my-plugin_db__* |
A plugin-provided server |
{ "permissions": {
"allow": ["mcp__github__get_issue", "mcp__sentry__*"],
"deny": ["mcp__github__delete_repository"] } }
Server authors can set anthropic/requiresUserInteraction: true on a tool so it prompts every time, even in auto and bypass modes — for consent and access-grant steps.
claude.ai connectors#
Signed in with a claude.ai account, the connectors you (or your admins, on Team/Enterprise) added at claude.ai are available in Claude Code automatically. Turn them off with disableClaudeAiConnectors: true (honoured from any settings scope).
Claude Code as an MCP server#
claude mcp serve # stdio server exposing Claude Code's tools to another MCP client
Add it to Claude Desktop or another client as a stdio server. The client is responsible for confirming tool calls.
Organisation controls#
| Setting | Effect |
|---|---|
allowedMcpServers / deniedMcpServers |
Allowlist / blocklist by name, URL or command |
allowManagedMcpServersOnly |
Only the managed allowlist applies |
managedMcpServers |
Provide remote servers to everyone, alongside their own |
managed-mcp.json |
Deploy a fixed set; users can’t add others |
enableAllProjectMcpServers, enabledMcpjsonServers, disabledMcpjsonServers |
Pre-approve or reject project servers |
strictPluginOnlyCustomization.mcp |
MCP servers only from plugins or policy |
A blocked server shows ✘ Blocked by enterprise managed policy in claude mcp list.
Common mistakes#
Review questions#
The same server is defined in your local scope and in .mcp.json. Which is used?
The local-scope entry, whole — fields aren’t merged across scopes.
Why does adding many MCP servers cost less context than it used to? Tool search defers schemas: only names and server instructions load until Claude searches for a tool.
How do you share an MCP server with the team without committing its API key?
Add it at project scope (.mcp.json) with ${API_KEY} in headers; each developer sets API_KEY locally.