MCP Servers in Claude Code, Codex and Gemini CLI
How MCP servers plug into coding agents: transports, claude mcp add and scopes, OAuth and headers, output and time limits, tool permissions, and how Codex CLI and Gemini CLI compare. Checked 2026-11-14.
- MCP servers give an agent tools, resources and prompts. In Claude Code you add one with claude mcp add at local (the default), project (.mcp.json) or user scope, and local wins over project, which wins over user.
- Use HTTP (Streamable HTTP) for remote servers; SSE is deprecated. Claude Code signs in with OAuth from /mcp or claude mcp login, or sends headers you set.
- Treat every server as code or text you are trusting. claude -p loads .mcp.json servers without asking, so block servers you don't want with disabledMcpjsonServers or --strict-mcp-config.
This page is a map of MCP servers in coding agents: what MCP provides, how Claude Code adds servers and picks which definition wins, how authentication, limits and permissions work, where Codex CLI and Gemini CLI keep the same settings, and the order in which to read our MCP articles. Every fact was checked against the official docs on 2026-11-14, when the latest Claude Code on npm was 2.1.325 and @modelcontextprotocol/sdk was 1.32.2.
We did not run any command for this hub. Where the docs did not state something, we left it out or marked it “unverified”.
What MCP gives an agent
MCP (Model Context Protocol) is an open standard that connects AI clients to tools, data sources and APIs. A server offers three kinds of things:
| Server feature | What it is | How you use it in Claude Code |
|---|---|---|
| Tools | Functions the model calls | Named mcp__<server>__<tool>, the name permission rules and hook matchers use |
| Resources | Content the server exposes | @server:protocol://resource/path |
| Prompts | Templates the server defines | Run /mcp__servername__promptname |
The current MCP spec version is 2026-07-28, and its transports section lists stdio and Streamable HTTP. Claude Code has a v1 client runtime on TypeScript SDK 1.x and a v2 runtime on SDK 2.0, which adds revision 2026-07-28. MCP_SDK_GENERATION (v1 or v2) picks one yourself.
| Transport in Claude Code | How to add | Notes |
|---|---|---|
HTTP (http, or streamable-http in JSON) | claude mcp add --transport http <name> <url> | Recommended for remote servers. Supports OAuth |
| SSE | Same command; it falls back to SSE when the server rejects HTTP (v2.1.265+), or --transport sse | Deprecated |
| stdio | claude mcp add [options] <name> -- <command> [args...] | A local process. Everything after -- goes to the server |
WebSocket (ws) | .mcp.json or claude mcp add-json only | Header-only auth, no OAuth |
(source: https://code.claude.com/docs/en/mcp, checked 2026-11-14) (source: https://modelcontextprotocol.io/docs/2026-07-28/learn/versioning, checked 2026-11-14) (source: https://modelcontextprotocol.io/llms.txt, checked 2026-11-14)
Adding servers to Claude Code
Besides add, claude mcp has add-json, list, get, remove, login, logout, serve and more. In a session, /mcp shows status and lets you sign in, reconnect or turn a server off.
| Scope | Loads in | Shared | Stored in |
|---|---|---|---|
local (default) | Current project | No | ~/.claude.json, under the project’s path |
project | Current project | Yes, via version control | .mcp.json at the project root |
user | All your projects | No | ~/.claude.json |
When a server is defined in several places, Claude Code connects once, from the highest-precedence source: local, project, user, plugin servers, claude.ai connectors. The whole entry is used and fields are not merged. A server from the managedMcpServers managed setting ranks above all of them (v2.1.259+).
An interactive session asks before using .mcp.json servers, and claude mcp list shows ⏸ Pending approval until you approve. A cloned repository can’t approve its own servers: enableAllProjectMcpServers or enabledMcpjsonServers committed to .claude/settings.json is ignored in an untrusted folder.
.mcp.json expands ${VAR} and ${VAR:-default} in command, args, env, url and headers. An unset variable without a default stays as literal ${VAR} text, with a warning.
(source: https://code.claude.com/docs/en/mcp, checked 2026-11-14)
Authentication
OAuth. A remote server that answers 401 or 403 is flagged in /mcp, where you sign in through the browser. claude mcp login <name> runs the same flow from a shell, and --no-browser prints the URL instead. claude mcp logout <name> clears stored credentials; remove deletes local tokens but doesn’t revoke them. A claude -p or Agent SDK run can’t run OAuth, so sign in interactively first.
Headers. --header or a headers object sends static values. headersHelper runs a command at connection time that prints a JSON object of headers, and Claude Code gives up on it after 10 seconds. If the server rejects an Authorization header you configured, the connection fails; there is no fallback to OAuth.
What can’t leak. In a remote server’s url and headers, credential variables read as empty: ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, cloud provider credentials and others such as NPM_TOKEN. A name outside that set, such as API_KEY, expands as written. A project or local-scope headersHelper runs only after you trust the folder.
(source: https://code.claude.com/docs/en/mcp, checked 2026-11-14)
Limits and timeouts
| What | Default | Setting |
|---|---|---|
| Output warning | Above 10,000 tokens | — |
| Output limit | 25,000 tokens | MAX_MCP_OUTPUT_TOKENS |
| Text result saved to a file | Over 50,000 characters | Tool’s _meta["anthropic/maxResultSizeChars"], up to 500,000 |
| Wall clock per call | About 28 hours | Per-server timeout (ms) or MCP_TOOL_TIMEOUT |
| Idle (no response or progress) | 5 min remote, 30 min stdio | CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUT |
| Move to background | After 2 min in the main conversation | CLAUDE_CODE_MCP_AUTO_BACKGROUND_MS |
Tool search is on by default: only tool names and server instructions load at startup, and definitions load when needed. ENABLE_TOOL_SEARCH=false loads every tool upfront, and alwaysLoad: true keeps one server’s tools loaded.
(source: https://code.claude.com/docs/en/mcp, checked 2026-11-14)
Permissions for MCP tools
Rules name MCP tools in full. A plugin’s server adds the plugin name, mcp__plugin_<plugin-name>_<server-name>__<tool-name>, in permission rules, allowed-tools, a subagent’s tools and hook matchers.
For subagents, tools: mcp__github__* grants one server’s tools, disallowedTools: mcp__github withholds them and disallowedTools: mcp__* withholds every MCP tool.
A server can mark a tool with _meta["anthropic/requiresUserInteraction"]: true. Claude Code then prompts on every call, even in bypassPermissions, and allow rules don’t skip it.
How allow, ask and deny rules treat MCP globs is on the permissions page, which we did not re-check for this hub (unverified here). Our cheat sheet and choosing article cover it as of their check dates.
(source: https://code.claude.com/docs/en/mcp, checked 2026-11-14) (source: https://code.claude.com/docs/en/sub-agents, checked 2026-11-14)
Codex CLI and Gemini CLI
| Claude Code | Codex CLI | Gemini CLI | |
|---|---|---|---|
| Config | ~/.claude.json, .mcp.json | [mcp_servers.<name>] in ~/.codex/config.toml or a trusted project’s .codex/config.toml | mcpServers in ~/.gemini/settings.json or .gemini/settings.json |
| Add | claude mcp add (default local) | codex mcp add <name> -- <command> | gemini mcp add (default project, stdio) |
| Transports | stdio, HTTP, SSE, WebSocket | stdio, Streamable HTTP | stdio, SSE (url), Streamable HTTP (httpUrl) |
| Auth | OAuth, headers, headersHelper | OAuth, bearer_token_env_var, http_headers | OAuth (/mcp auth), headers |
| Limit tools | Rules on mcp__<server>__<tool> | enabled_tools, disabled_tools | includeTools, excludeTools |
| Tool timeout | timeout (ms) | tool_timeout_sec, default 60 | timeout (ms), default 600,000 |
Gemini CLI names tools mcp_<server>_<tool> and splits on the first underscore, so its docs say not to put _ in server names. Codex CLI saves a secret passed with --oauth-client-secret in config.toml; keep that file out of version control.
(source: https://learn.chatgpt.com/docs/extend/mcp, checked 2026-11-14) (source: https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md, checked 2026-11-14)
Using MCP safely
A server is something you trust. The Claude Code docs say to verify you trust each server before connecting, and that servers fetching external content expose you to prompt injection. A stdio server is a program on your machine; read the command before adding or approving it.
Headless runs skip approval. claude -p, Agent SDK sessions and some cloud sessions load .mcp.json servers without asking. If the job checks out code you didn’t write, block servers with disabledMcpjsonServers, drop project settings with --setting-sources, or pass only your own with --strict-mcp-config and --mcp-config.
Keep secrets out of shared files. Use ${VAR} in .mcp.json. Gemini CLI strips variables like *TOKEN* from a server’s environment unless listed in env. More in Keep Secrets Away from Claude Code.
(source: https://code.claude.com/docs/en/mcp, checked 2026-11-14) (source: https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md, checked 2026-11-14)
Reading order
Starting points, not a ranking. New to MCP? Read top to bottom.
- MCP Servers 101 and Five Design Rules: a minimal TypeScript server and five design rules.
- How to Choose MCP Servers: maintainer, transport, scope, output size and narrowing permissions.
- How to Build Your Own MCP Server: the Python SDK, testing over JSON-RPC and registering with full paths.
- Claude Code Permissions and settings.json: A Cheat Sheet: rule syntax, including
mcp__rules. - Permission Design for AI Agents: splitting reads from writes.
- Keep Secrets Away from Claude Code: which processes, stdio servers included, see your keys.
- Claude Code Headless Mode: claude -p for Scripts and Cron:
-pand.mcp.json, and what--bareskips. - How to Define Claude Code Subagents:
mcpServersfor one subagent and MCP entries intools. - Codex CLI Config: config.toml, Approvals and Sandbox:
[mcp_servers.<id>]among Codex settings. - Gemini CLI vs Claude Code: Config File Map: Gemini’s
mcpServersnext to.mcp.json.
Related hubs
- Claude Code Setup and Daily Operations: settings and permissions.
- Claude Code Hooks: Events, Exit Codes and Examples: matching MCP tools in hooks.
- Claude Code in CI, Headless and Production: MCP servers in unattended runs.
- Claude Code Subagents and Parallel Agents: which MCP servers subagents get.
- AI Coding Tools Compared: Plans and Prices (2026): picking a CLI.
Summary
- MCP servers offer tools, resources and prompts; the current spec is 2026-07-28.
claude mcp addsaves at local scope by default. Local beats project (.mcp.json), which beats user, and entries are not merged.- Use HTTP for remote servers; SSE is deprecated. Sign in with
/mcporclaude mcp login;-pruns can’t do OAuth. - Output is capped at 25,000 tokens by default, and long text results go to a file. Set a per-server
timeoutfor tools that can hang. claude -ploads.mcp.jsonservers without asking. Block what you don’t trust withdisabledMcpjsonServersor--strict-mcp-config.- Codex CLI uses
[mcp_servers.<name>]inconfig.toml; Gemini CLI usesmcpServersinsettings.json. - Checked against the official docs on 2026-11-14; we ran nothing.
FAQ
- Where does claude mcp add save a server?
- At local scope by default: ~/.claude.json under the current project's path, private to you. --scope project writes .mcp.json at the project root, and --scope user saves in ~/.claude.json for all your projects.
- Which definition wins when the same server is in more than one scope?
- Claude Code connects once, from the highest-precedence source: local, project, user, plugin servers, then claude.ai connectors. The whole entry is used; fields are not merged.
- Do .mcp.json servers always ask for approval?
- No. An interactive session asks first, but claude -p runs, Agent SDK sessions and some cloud sessions load them without asking. disabledMcpjsonServers blocks a server in every mode.
- How large can an MCP tool result be in Claude Code?
- Claude Code warns above 10,000 tokens and the default limit is 25,000 tokens, set with MAX_MCP_OUTPUT_TOKENS. A successful text result over 50,000 characters is saved to a file, unless the tool declares anthropic/maxResultSizeChars, which can go up to 500,000.
- Where do Codex CLI and Gemini CLI keep MCP servers?
- Codex CLI uses [mcp_servers.<name>] in ~/.codex/config.toml, or .codex/config.toml in a trusted project. Gemini CLI uses mcpServers in ~/.gemini/settings.json or .gemini/settings.json.