Official Docs Breakdown: Connect Claude Code to Tools via MCP
💬 hippo: This post is part of the Claude Code Official Docs Breakdown series. MCP is the feature I have been most eager to unpack—it turns Claude Code from a coding assistant into an end-to-end engineering operator.
1. What Is MCP?
MCP (Model Context Protocol) is an open standard for connecting AI applications to external tools. In practice, it lets Claude Code talk directly to your databases, APIs, monitoring stacks, and issue trackers over a standardized protocol—no manual copy-pasting required.
A few concrete workflows this unlocks:
- Pull requirements from a Jira ticket, implement the change, and open a GitHub PR automatically
- Query Sentry error logs to diagnose production incidents
- Connect to PostgreSQL to run natural-language queries and generate reports
- Respond to Telegram messages, Discord chats, and webhook events—letting Claude react to external events rather than only running on-demand tasks
2. Official Docs Breakdown
2.1 Installing and Managing MCP Servers
Claude Code supports three transports for connecting to MCP servers:
1 | # HTTP transport (recommended for cloud services, most widely supported) |
Comparing the three transports:
| Transport | Best For | Pros | Cons |
|---|---|---|---|
| HTTP | Cloud services, hosted APIs (Notion, Stripe) | Most widely supported, straightforward setup | Requires network access |
| SSE | Workflows requiring server-initiated push | Real-time streaming from the server | Less widely adopted |
| Stdio | Local tools, databases | Direct local resource access, works offline | Requires local runtime dependencies |
Day-to-day management commands:
1 | claude mcp list # List all configured servers |
Inside a Claude Code session, run /mcp to check the connection status of every configured server.
A few notable capabilities worth highlighting:
- Dynamic tool updates: When a server adds or modifies tools, it sends a
list_changednotification so Claude Code refreshes automatically without reconnecting. - Channel push: If a server advertises the
claude/channelcapability and you launch Claude Code with--channels, Claude can react to pushed external events (CI results, monitoring alerts, etc.). - Automatic Claude.ai sync: Once signed in to your Claude.ai account, MCP servers configured in Claude.ai become available automatically. Set
ENABLE_CLAUDEAI_MCP_SERVERS=falseto disable this behavior.
Plugin MCP servers are a newer official capability: plugins can bundle their own MCP servers and launch them automatically when enabled, with zero manual setup. A plugin’s root .mcp.json supports two dedicated environment variables—${CLAUDE_PLUGIN_ROOT} (the plugin installation directory) and ${CLAUDE_PLUGIN_DATA} (the plugin’s persistent data directory):
1 | { |
2.2 Configuration Scopes and Environment Variables
MCP servers can be configured at three distinct scopes:
| Scope | Storage Location | Visibility | Best For |
|---|---|---|---|
| Local (default) | ~/.claude.json (scoped to the project path) |
Only you, current project only | Personal experiments, sensitive credentials |
| Project | Project root .mcp.json |
Entire team | Shared team tooling |
| User | ~/.claude.json |
All projects on your machine | Personal cross-project utilities |
1 | # Add servers to different scopes |
The first time a project-scoped server is loaded, Claude Code prompts for confirmation so a malicious repository cannot silently inject an MCP server. Run claude mcp reset-project-choices to clear saved approval decisions.
Environment variable expansion makes .mcp.json safe to commit to Git—everyone shares the server definition while keeping their own credentials local:
1 | { |
${VAR} substitutes an environment variable directly, and ${VAR:-default} falls back to a default value when unset. Expansion works across five fields: command, args, env, url, and headers.
Three additional interaction primitives are worth knowing:
- MCP resource references: Use
@server-name:resource-pathto reference resources exposed by an MCP server just like local files. - MCP prompts as slash commands: Prompts exposed by an MCP server automatically surface as Claude Code slash commands.
- Elicitation: A server can pause mid-execution to request user input via either form mode or URL mode, enabling interactive workflows.
2.3 Authentication and Advanced Features
Many cloud MCP servers require authentication, and Claude Code ships with built-in OAuth 2.0 support. Two common CLI options cover strict OAuth setups:
1 | # Fixed callback port (to match a pre-registered redirect URI) |
If a server’s standard OAuth metadata endpoint returns an error, you can override the discovery URL in .mcp.json (requires v2.1.64+, and the URL must use https://):
1 | { |
headersHelper dynamic authentication covers non-OAuth setups (Kerberos, short-lived tokens, internal SSO, etc.) by executing a script on every connection to generate request headers:
1 | { |
Inline shell commands are also supported: "headersHelper": "echo '{\"Authorization\": \"Bearer '\"$(get-token)\"'\"}'".
headersHelper requirements:
| Requirement | Details |
|---|---|
| Output format | Must print a JSON object of string key-value pairs |
| Execution environment | Runs in a shell with a 10-second timeout |
| Precedence | Dynamic headers override static headers with the same name |
| Timing | Runs on every connection (session startup and reconnects) |
Note that Claude Code does not cache the output—your script needs to handle token reuse itself.
MCP tool output is capped at 25,000 tokens by default, with a warning triggered above 10,000 tokens. Override this limit with the MAX_MCP_OUTPUT_TOKENS environment variable. In addition, claude mcp serve exposes Claude Code itself as an MCP server so other applications can call it.
2.4 Tool Search and Enterprise Governance
Tool search prevents context window exhaustion when you connect many MCP servers. Once tool descriptions exceed 10% of the context window, Claude Code automatically switches to on-demand loading so only the tools actually needed enter context.
ENABLE_TOOL_SEARCH values:
| Value | Behavior |
|---|---|
| (unset) | Enabled by default; disabled when ANTHROPIC_BASE_URL points to a non-official host |
true |
Always enabled |
auto |
Activates when tool definitions exceed 10% of the context window |
auto:5 |
Activates at a custom threshold (5%) |
false |
Disabled; all tools are preloaded upfront |
1 | ENABLE_TOOL_SEARCH=auto:5 claude # Custom 5% threshold |
Tool search requires Sonnet 4+ or Opus 4+ models; Haiku does not support it.
Enterprise governance enforces centralized server configuration via managed-mcp.json, deployed to a system-level directory that end users cannot modify:
| OS | Deployment Path |
|---|---|
| macOS | /Library/Application Support/ClaudeCode/ |
| Linux/WSL | /etc/claude-code/ |
| Windows | C:\Program Files\ClaudeCode\ |
1 | { |
Pair this with an Allowlist/Denylist for fine-grained policy enforcement:
1 | { |
Restriction rule types:
| Rule Type | Matching Behavior | Applies To |
|---|---|---|
serverName |
Matches the configured server name | All server types |
serverCommand |
Exact match on command and arguments (order must match) | Stdio only |
serverUrl |
Wildcard match against the server URL | Remote only (HTTP/SSE) |
Key rules to keep in mind: command matching is strictly exact—argument order and count must match verbatim—and the denylist always takes precedence, blocking any matching server even if it appears on the allowlist.
3. Field Notes from hippo
💬 hippo: Here are a few patterns from running MCP in day-to-day work:
Pattern 1: Project Scope + Environment Variables for Team Repos
For shared repositories, commit .mcp.json using environment variable placeholders so each developer supplies their own credentials locally:
1 | # Set per developer in .zshrc |
1 | { |
New teammates just clone the repo, export their keys, and start working—zero per-machine MCP setup.
Pattern 2: Natural-Language Queries Against PostgreSQL
1 | claude mcp add --transport stdio db -- npx -y @bytebase/dbhub \ |
Once connected, you can query your data in plain English: "What is our total revenue this month?" or "Find customers who haven't made a purchase in the last 90 days". Always use a read-only database user so Claude cannot accidentally mutate data.
Pattern 3: headersHelper with Internal SSO
Our internal MCP servers authenticate through company SSO with tokens expiring every hour. A small headersHelper script fetches short-lived tokens automatically on each connection, and the 10-second timeout leaves plenty of headroom. Make sure the script caches tokens locally—otherwise every reconnect pays the full SSO handshake latency.
Pattern 4: Controlling Context Bloat with Tool Search
With 8 MCP servers enabled in one project, tool descriptions were eating up the context window. Setting ENABLE_TOOL_SEARCH=auto:5 lowered the activation threshold to 5% and cut context overhead noticeably via on-demand loading. Just note that Haiku does not support tool search—you need Sonnet 4+ or higher.
4. FAQ
Q: How do I choose between HTTP, SSE, and Stdio?
A: Use HTTP for cloud services (Notion, GitHub, Sentry), SSE when you need real-time server push, and Stdio for local tools (databases, filesystems). When in doubt, pick HTTP—it has the broadest support.
Q: How do I troubleshoot a failing MCP server connection?
A: Follow a three-step check: verify endpoint reachability with curl -I <URL>, inspect the saved config with claude mcp get <name>, and check the logs under ~/.claude/logs/.
Q: How can I run Claude Code itself as an MCP server?
A: Run claude mcp serve, then add a stdio entry pointing to claude mcp serve in the calling application’s MCP configuration.
5. Summary
MCP is Claude Code’s standardized extension bus for external tools. The main takeaways: default to HTTP among the three transports, use Project scope plus environment variables for team repositories, and lock down enterprise environments with managed-mcp.json alongside Allowlist/Denylist policies.
Series Navigation
- Index: Claude Code Complete Guide · Series Index
- Previous: Official Docs Breakdown: Subagents
- Next: Official Docs Breakdown: Claude Code Settings
Based on the official Connect Claude Code to tools via MCP documentation.
Last updated: 2026-03-31




