2.4 Integrate MCP servers into Claude Code and agent workflows
Configure MCP servers at the right scope with secrets kept out of the repo, and make MCP tools and resources discoverable and attractive to the agent.
Key points
- 1
Three Claude Code MCP scopes: local (default; this project only, private, stored in
~/.claude.json), project (.mcp.jsonat the repository root, committed and shared with the team) and user (~/.claude.json, all of one user's projects, private). Shared team tooling goes in project scope; personal or experimental servers go in user scope. - 2
Add servers with
claude mcp add --transport http|sse|stdio <name> --scope project|user|local ...; for stdio servers--separates Claude's options from the server command, and--env KEY=valuepasses environment to the server.claude mcp list,claude mcp get <name>,claude mcp remove <name>and/mcpinside a session manage and inspect servers. - 3
.mcp.jsonsupports environment variable expansion:${VAR}and${VAR:-default}incommand,args,env,urlandheaders. Reference${GITHUB_TOKEN}in the committed file and set the variable on each machine or CI runner. Never commit token values, and do not park them in CLAUDE.md (it is committed and loaded into context). - 4
If a referenced variable is unset with no default, the config still loads:
claude mcp listshows a missing-variable warning and the literal${VAR}text is used as-is, so the server may connect and then fail authentication. In CI, map the secret into the exact variable name the file expects. - 5
All scopes load together. Tools from every configured server, project and user alike, are discovered at connection time and available simultaneously. If the same server name is defined in several scopes, the highest-precedence definition wins (local, then project, then user).
- 6
Project
.mcp.jsonservers require a one-time approval prompt in interactive sessions; inclaude -p, Agent SDK and cloud runs they load without prompting. MCP tool names appear asmcp__<server>__<tool>in permission rules,allowed-tools, subagenttoolslists and hook matchers. - 7
If the agent prefers a built-in tool (Grep) over a more capable MCP tool, the usual cause is a thin MCP description. Enhance it to explain capabilities, outputs and when to prefer it over the built-in alternative; do not remove the built-in tool or add blanket "always use X" prompt rules.
- 8
Prefer existing community or vendor MCP servers for standard integrations (Jira, GitHub, Slack, databases); reserve custom servers for team-specific workflows nothing else covers.
- 9
MCP resources expose content catalogues (issue summaries, documentation hierarchies, database schemas) so the agent can see what data exists without exploratory tool calls. Resources are application-driven context; tools are model-controlled actions. A static copy in CLAUDE.md or a
list_everythingtool are the wrong substitutes. - 10
In the Agent SDK, pass servers in the
mcpServersoption (stdiocommand/args/env, ortype: "http"/"sse"withurlandheaders); a project.mcp.jsonis picked up when theprojectsetting source is enabled. Grant access withallowedTools: ["mcp__server__*"]rather than broad permission modes, and check theinitsystem message for server status (connected,failed,needs-auth).
Read the source
Test yourself on 2.4 Integrate MCP servers into Claude Code and agent workflows
Ten questions, with the answer and explanation after each one.