Setting Up MCP in Claude Code: stdio, Remote HTTP, and Troubleshooting
2026-07-08
The cleanest way to wire MCP servers into Claude Code is the built-in claude mcp CLI rather than hand-editing nested JSON files. Once you understand transport types and config scopes, most setup errors take less than a minute to diagnose.
Choosing a Transport
| Transport | Best for | Command shape |
|---|---|---|
| stdio (local process) | Local files, Git, local databases, CLI wrappers | claude mcp add name -- npx -y @org/server |
| HTTP (remote endpoint) | Hosted SaaS tools, shared team indexes, directories | claude mcp add --transport http name https://... |
Pay attention to the -- separator: it tells Claude Code that everything after it is the server executable and its flags, preventing the CLI from parsing server flags as its own.
Config Scopes: User vs. Project
Claude Code stores MCP declarations in three scopes:
--scope user: available across all repositories on your machine — ideal for general utilities like docs search or the askskill directory.--scope project: writes to.mcp.jsonin the repo root so teammates share the same tooling. Never commit raw secrets to.mcp.json; reference environment variables such as${GITHUB_TOKEN}instead.--scope local(default): applies only to the current workspace on your machine, great for experiments or personal credentials.
Practical Examples
- Add a hosted HTTP MCP server (such as askskill):
claude mcp add --transport http --scope user askskill https://askskill.ai/api/mcp
- Add a local stdio package with an API token:
claude mcp add --scope local github -e GITHUB_PERSONAL_ACCESS_TOKEN=your_token -- npx -y @modelcontextprotocol/server-github
Verify connectivity right away:
claude mcp list
claude mcp get askskill
Four Common Pitfalls
spawn npx ENOENT: When Node is managed bynvmorfnm, non-interactive child shells may miss yourPATH. Runwhich npxand pass the full binary path if needed.- Cold-start timeout on first
npx -y: Downloading a large package on the first agent turn can hit startup timeouts. Pre-warm the cache once in your terminal before launching Claude Code. - Missing environment variables: Shell exports in
~/.zshrcare not always inherited across desktop launchers; pass secrets explicitly via-e KEY=VAL. - Logs written to
stdout: Overstdio,stdoutis reserved strictly for JSON-RPC messages. Custom scripts usingconsole.loginstead ofconsole.errorwill break protocol framing.
Keeping Context Lean
Keep only 3–5 active MCP servers enabled at a time. Every connected server injects its tool schemas into the model context; remove unused ones with claude mcp remove <name> and re-export anytime from the MCP catalog or AI Stack Builder.
Further reading: How to Choose and Install MCP Tools Safely and MCP Security Governance for Teams.