MCP Servers for Coding Agents: Set Up, Manage and Budget Them in Claude Code and Codex CLI (November 2026)
As of 2026-11-25, you add MCP servers to Claude Code with claude mcp add (scopes local, project and user; project config lives in .mcp.json at the repo root), and to Codex CLI with [mcp_servers.<name>] tables in ~/.codex/config.toml. The servers themselves run on your machine or a remote service, but every tool definition they expose and every result they return is sent to the model as input tokens. More servers means more expensive turns. This guide covers the config for both tools, useful server categories, token-cost math and the security baseline.
QCode is an independent third-party API service with no official or partner relationship with Anthropic, OpenAI or Google. MCP traffic does not pass through QCode; QCode handles model requests and bills per token. Commands and config keys below follow Anthropic's and OpenAI's official docs.
Updated 2026-11-26
Key facts
- Protocol version: the current MCP spec revision is 2026-07-28, supported by Claude Code's v2 client runtime (Anthropic docs). Use stdio (local) or Streamable HTTP (remote); SSE is deprecated.
- Claude Code:
claude mcp adddefaults tolocalscope (stored in~/.claude.json, current project only).--scope projectwrites.mcp.jsonfor the team;--scope userapplies to all your projects. - Codex CLI: set
command/args/env(stdio) orurl/bearer_token_env_var(HTTP) inconfig.toml.startup_timeout_secdefaults to 10 andtool_timeout_secto 60 (OpenAI docs). - Cost: Anthropic's docs estimate that 50 tool definitions use about 10K–20K tokens. Claude Code turns on tool search by default and loads definitions on demand, and since v2.1.304 that also holds behind an
ANTHROPIC_BASE_URLgateway. - Security: connect only servers you trust. Servers that fetch external content expose you to prompt injection (Anthropic's own warning). In CI,
claude -ploads project-scoped servers without asking.
What MCP is, and how it relates to QCode
MCP (Model Context Protocol) is an open protocol that lets AI coding tools connect to outside capabilities in a standard way. An MCP server can offer three things: tools (actions, such as opening a PR or querying a database), resources (data to read, such as a docs page) and prompts (task templates).
There are two ways to run one:
- stdio: the tool starts a local child process (often a package launched with
npxoruvx). Data stays on your machine. - Streamable HTTP: the tool connects to a remote service, usually with OAuth or a bearer token.
The relationship to QCode is simple. Once you set ANTHROPIC_BASE_URL=https://api.qcode.cc/api in Claude Code, or a QCode model_provider in Codex, model requests go to QCode. MCP calls are made by Claude Code or Codex locally or straight to the remote service, not through QCode. Tool definitions and tool results do end up in the model's context, though, so they show up on your QCode token bill.
Add MCP servers in Claude Code
2.1 Core commands
# stdio: everything after -- is passed through as the launch command
claude mcp add --transport stdio context7 -- npx -y @upstash/context7-mcp
claude mcp add playwright -- npx @playwright/mcp@latest
# remote HTTP (recommended for remote servers)
claude mcp add --transport http notion https://mcp.notion.com/mcp
# add from JSON in one go (the form GitHub's own install guide uses)
claude mcp add-json github '{"type":"http","url":"https://api.githubcopilot.com/mcp","headers":{"Authorization":"Bearer YOUR_GITHUB_PAT"}}'
# manage
claude mcp list # all servers with health status
claude mcp get github # one server's details
claude mcp remove github # remove it
Inside a session, /mcp shows connection status and tool counts and handles OAuth sign-in. One gotcha: --env accepts several KEY=value pairs, so if the server name comes right after --env it is read as another pair and rejected. Put another option, such as --transport stdio, in between.
2.2 The three scopes
| Scope | Applies to | Stored in | Good for |
|---|---|---|---|
local (default) |
Current project, you only | ~/.claude.json |
Servers with personal credentials |
project |
Current project, shared via git | .mcp.json at project root |
A team-wide tool set |
user |
All your projects | ~/.claude.json |
General tools such as docs lookup |
When the same server name exists in several scopes, precedence is local → project → user → plugin → claude.ai connectors. The whole entry comes from the winning source; fields are not merged across scopes.
2.3 A team .mcp.json
{
"mcpServers": {
"github": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp",
"headers": { "Authorization": "Bearer ${GITHUB_PAT}" }
},
"playwright": {
"type": "stdio",
"command": "npx",
"args": ["@playwright/mcp@latest"]
},
"context7": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"]
}
}
}
Things that trip people up:
${VAR}and${VAR:-default}work incommand,args,env,urlandheaders. Keep tokens in environment variables and never commit real credentials.- For safety, credential variables such as
ANTHROPIC_AUTH_TOKENandANTHROPIC_API_KEYalways expand to empty in a remote server'surlandheaders. Your QCode key (cr_...) is not accidentally sent to a third-party MCP server. - An entry with a
urlbut notypeis read as stdio and skipped. Always write"type": "http"for remote servers. - The first time you use a project's
.mcp.jsoninteractively, Claude Code asks for approval. Reset those choices withclaude mcp reset-project-choices.
Add MCP servers in Codex CLI
Codex keeps MCP config in the same config.toml as the model config. Here is a full example that runs GPT-6.2 Sol on QCode with two MCP servers (for key setup, see the QCode Codex docs):
model_provider = "qcode"
model = "gpt-6.2-sol"
[model_providers.qcode]
name = "qcode"
base_url = "https://api.qcode.cc/openai"
wire_api = "responses"
requires_openai_auth = true
# stdio server
[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
startup_timeout_sec = 20
# Streamable HTTP server, token read from an env var
[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp"
bearer_token_env_var = "GITHUB_PAT"
enabled_tools = ["get_issue", "list_pull_requests", "create_pull_request"]
default_tools_approval_mode = "writes"
tool_timeout_sec = 60
Notes:
- stdio keys:
command(required),args,env,env_vars,cwd. HTTP keys:url(required),bearer_token_env_var,http_headersand a few more. - Trimming tools:
enabled_toolsis an allow list;disabled_toolsis applied after it. The tool names above are illustrative; use the names/mcpshows. - Approvals:
default_tools_approval_modeacceptsauto,prompt,writesandapprove.writesasks before any tool not marked read-only. You can override per tool withtools.<tool>.approval_mode. - Project scope: servers can also live in a project's
.codex/config.toml, but only in trusted projects. - CLI: if you prefer the command line, check the help output of your installed Codex version for
mcpsubcommands; the config-file method above does not depend on them.
More on Codex with QCode: Codex CLI with GPT-6.2 Sol.
Server categories that pay off for coding
| Category | Example | When it's worth it | Watch out |
|---|---|---|---|
| Filesystem | @modelcontextprotocol/server-filesystem |
Desktop chat clients, or to restrict access to one directory | Claude Code and Codex already read and write files; usually unnecessary there |
| Git / GitHub | GitHub's remote server https://api.githubcopilot.com/mcp |
Reading and writing issues, PRs, Actions | Use the built-in shell for local git; use a fine-grained, least-privilege PAT |
| Browser | Playwright MCP (@playwright/mcp) |
Front-end debugging, end-to-end tests, screenshot checks | Any external page is an injection risk; restrict reachable domains |
| Database | A Postgres / MySQL MCP server your team has vetted | Letting the agent inspect schemas and run read-only queries | Always a read-only DB role; never a production write connection |
| Docs | Context7 (@upstash/context7-mcp) |
Current library docs and examples, fewer "outdated API" mistakes | The remote version needs an API key |
Start with one or two servers you will actually use, watch which tools get called for a week, then decide whether to add more. Our MCP server ecosystem 2026 page has a broader survey.
Token cost: tool definitions cost money too
Every MCP tool has a name, a description and a JSON Schema for its parameters. If those definitions go to the model on every turn, they are a fixed input cost. Anthropic's tool-search docs estimate that 50 tool definitions take roughly 10K–20K tokens, and that tool-selection accuracy drops once more than 30–50 tools are loaded at once.
Claude Code: loads on demand by default
Claude Code turns tool search on by default. Definitions are kept out of the context; the model searches when it needs a capability and loads the most relevant few (up to five by default). Since v2.1.304 this is also on by default behind an ANTHROPIC_BASE_URL gateway, such as QCode, with nothing to set. Tune it with ENABLE_TOOL_SEARCH:
| Value | Behavior |
|---|---|
unset / true |
Tool search on, definitions loaded on demand |
auto |
Activates once deferrable definitions reach 10% of the context window |
auto:5 |
Same, with a 5% threshold |
false |
Off; every definition loads on every turn |
The other lever is tool output size. MAX_MCP_OUTPUT_TOKENS defaults to 25,000 tokens, with a warning above 10,000. A tool that returns a whole table or a whole HTML page can eat tens of thousands of tokens in one call.
Codex: trim the tool list
In Codex, the documented controls are enabled_tools / disabled_tools and enabling servers only where you need them (enabled = false switches one off); check the current Codex docs for any deferred-loading option.
A quick budget check
Say tool definitions take a steady 15K tokens and you send 200 model requests a day. That fixed overhead is 3 million input tokens per day. At list prices:
| Model (QCode ID) | No cache | All cached |
|---|---|---|
Claude Sonnet 5.5 (claude-sonnet-5-5, $2 / cache $0.10) |
~$6.00 / day | ~$0.30 / day |
Claude Opus 5.5 (claude-opus-5-5, $4 / cache $0.20) |
~$12.00 / day | ~$0.60 / day |
GPT-6.2 Sol (gpt-6.2-sol, $2 / cache $0.10) |
~$6.00 / day | ~$0.30 / day |
Official prices as of 2026-11-26; cache reads at 5% of input for Opus 5.5 / Sonnet 5.5.
This is unit-price arithmetic to show the order of magnitude. The lesson is clear: when the tool list is stable, caching cuts this overhead to about one twentieth. Adding and removing servers or editing tool lists often breaks the cache. On a $35-per-day plan, uncached Opus tool definitions alone could use about a third of the budget. Live prices are on /models.
Security baseline: least privilege and prompt injection
Anthropic's docs put it plainly: verify you trust each server before connecting it, because servers that fetch external content can expose you to prompt injection. In practice:
- Least privilege. Use a fine-grained GitHub PAT scoped to the repos and permissions you need, a read-only database role, and a filesystem server limited to the project directory.
- No credentials in the repo. Put only references like
${GITHUB_PAT}in.mcp.json; keep the real values in local env vars or a secrets manager. - Review other people's
.mcp.json. When you clone an unfamiliar repo, interactive mode asks you to approve its project servers. Read them before you agree. - Be explicit in CI.
claude -pand Agent SDK sessions load project-scoped servers without asking. In pipelines, use--strict-mcp-configto load only the config you pass, or block servers withdisabledMcpjsonServers. - Keep a human in the loop. In Codex use
default_tools_approval_mode = "writes"or"prompt". In Claude Code, write permission rules againstmcp__<server>__<tool>. - Pin versions. In team configs, replace
@latestwith a fixed version and read the changelog before upgrading.
For a deeper threat model and sandboxing, see MCP security and sandboxing.
Troubleshooting
- Project server missing from
/mcp: it may be pending approval. Runclaudeinteractively and approve, or runclaude mcp reset-project-choices. - Server start-up timeout: in Claude Code,
MCP_TIMEOUT=10000 claudesets a 10-second start-up timeout; in Codex, raisestartup_timeout_sec. - Remote server skipped: check that the entry has
"type": "http". - Connectors added on claude.ai don't appear: they load only when you sign in with a claude.ai subscription. With
ANTHROPIC_AUTH_TOKENset (as with QCode) they are not loaded, so add the server locally withclaude mcp add. - Tool result truncated: raise
MAX_MCP_OUTPUT_TOKENS, or better, make the tool return only the fields you need.
Trends to watch into 2027
- More vendor-hosted MCP servers. Expect more SaaS vendors to run their own remote MCP servers for their data. Before you rely on a specific integration, check the vendor's current documentation for availability and billing terms.
- Long-running and async tools. The 2026-07-28 revision plus the MCP tasks extension lets servers return long jobs such as builds or exports asynchronously, and Claude Code supports it (Anthropic docs).
- MCP merges with skills and plugins. Expect capability bundles that package a server together with its prompts and workflows, instead of single-purpose servers.
- On-demand loading becomes the norm. As tool counts grow, tool search and deferred loading become the standard way to control context and cost.
FAQ
Does MCP traffic go through QCode?
No. Claude Code or Codex make MCP calls locally or directly to the remote service; QCode only handles model requests. Tool definitions and tool results do enter the model's context and are billed as normal input tokens.
Which Claude Code scope should I use: local, project or user?
Use local (the default) for servers with personal credentials that only you use. Use project for servers the whole team should get on checkout; it writes .mcp.json for you to commit. Use user for general tools you want in every project.
Does Claude Code's tool search still work when I use QCode?
Yes. Per Anthropic's docs, since Claude Code v2.1.304 tool search is on by default behind an ANTHROPIC_BASE_URL gateway with nothing to set. To force it off, set ENABLE_TOOL_SEARCH=false.
Where does Codex MCP config go?
In [mcp_servers.<name>] tables in ~/.codex/config.toml by default. You can also use a project's .codex/config.toml, but only in trusted projects.
Why did my bill go up after adding many MCP servers?
Tool definitions and tool output count as input tokens; by Anthropic's estimate 50 tool definitions are about 10K–20K tokens. Keeping the tool list stable so it caches, trimming unused tools and capping output size are the three most effective fixes.
Can my QCode key leak to an MCP server?
Claude Code expands credential variables such as ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY to empty in remote servers' url and headers, which lowers the risk. You should still never write your key into any MCP config.
What should I watch for when using MCP in CI?
claude -p loads project-scoped servers without asking. Use --strict-mcp-config to load only the config you pass explicitly, and give CI its own least-privilege tokens.
Recommended plan: Daily 35
If you work in Claude Code or Codex all day with MCP servers attached, tool definitions, tool results and long sessions use far more tokens than plain chat. The Daily 35 plan ($53.57 for 30 days, with $35 of credit per day, reset at 00:00 Beijing time) fits that kind of steady agent workflow, and you can buy a top-up if you run out on a busy day. Claude and GPT models are billed at the official API price ×1.0, and one key works in both Claude Code and Codex. Compare all plans on /pricing.