Claude Code MCP Server Setup: A Step-by-Step Configuration Guide
Claude Code ships with the ability to read files, run commands and edit code, but the moment you need it to query a database, call an internal API or read a page in a browser, the built-in tools run out. MCP (Model Context Protocol) is the extension protocol that closes that gap: it wraps external capabilities into a set of tools so Claude Code can call them exactly like its own. This guide covers both clients — Claude Desktop and Claude Code — then the common servers, the errors you will actually hit, and how to consolidate your keys behind a single gateway. If you have not installed Claude Code yet, start with the Claude Code from-scratch tutorial.
TL;DR
MCP servers run on your own machine: you can register one and call its tools without a model API key.
- Version: Claude Code CLI 1.x with Node.js 18+. The
mcpServersschema on this page was checked against Anthropic's docs as of 2026-10-10. - Compatibility: local servers run over stdio, remote servers over HTTP/SSE. Scopes are local, project (
.mcp.json) and user. Claude Desktop readsclaude_desktop_config.json; Claude Code registers servers withclaude mcp add. - Shortest working path:
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem ., thenclaude mcp listto confirm the server is registered.
Table of Contents
- 1. What MCP Is: Claude's External Tool Layer
- 2. Before You Start
- 3. Claude Desktop: the mcpServers Block
- 4. Claude Code: Connect Your First Server in Three Steps
- 5. Common Servers Cheat Sheet
- 6. Common Errors Cheat Sheet
- 7. Troubleshooting: Scope, PATH and Permissions
- 8. FAQ
- 9. Consolidate Your Keys: Route Model Calls Through One Gateway
- Summary
1. What MCP Is: Claude's External Tool Layer
MCP is an open protocol proposed by Anthropic that describes which tools and resources a program can offer a model. An MCP server is a standalone process or service that declares tools, resources and prompt templates; the client — Claude Desktop or Claude Code — connects to it and merges the declared tools into its own available set.
For everyday use, three points are enough:
- Transport: local processes use stdio (the client launches the child process and talks to it over standard input/output); remote services use HTTP / SSE.
- Scope (Claude Code): a configuration can apply only to the current project (project), only to your machine (local), or to all of your projects (user). Configurations shared by a team should use project scope and be committed to the repository.
- Configure once, use forever: once a server is registered, every subsequent start of the client mounts it automatically — no repeated setup.
2. Before You Start
Confirm three things before you begin:
- The client is installed and starts normally (for Claude Code, `claude --version` prints output).
- Node.js 18+ and npx are available — the vast majority of community MCP servers ship as npm packages, and npx is the least fussy way to launch them without a global install. The fetch server is the exception: it is Python and runs through uvx.
- You know which capability you want: reading a local directory, connecting to a database, calling a SaaS API, or wiring in your own internal service. Decide the goal first, then find the matching server — that beats installing a pile you never use.
Security note: an MCP server holds whatever permissions you grant it, file-system servers most of all. Install only servers from sources you trust, narrow the path arguments to a specific directory, and do not hand it your entire disk root on day one.
3. Claude Desktop: the mcpServers Block
Claude Desktop reads its MCP servers from a single JSON file. Open or create it at:
- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
- Windows: %APPDATA%\Claude\claude_desktop_config.json
The file has one top-level key, mcpServers. Each key under it is the name you will see in the client, and each value is an object with command, args, and optionally env. A complete, paste-ready example that exposes one project directory:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/your/project"
]
}
}
}Add a second entry under the same mcpServers object for a second server. Credentials for a server belong in that server’s own env object — not in a top-level field:
{
"mcpServers": {
"github": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "<your-token>"
}
}
}
}Save the file, then fully quit and reopen Claude Desktop — the app reads the file at startup, so a reload of the window is not enough. Once it reopens, the tools appear in the client’s tool menu. If the server does not appear, the first thing to check is whether the command runs by itself in a terminal: copy the command and args out of the JSON and run them verbatim.
There is no documented file-level key that points Claude Desktop at a different API host. To route the app’s model calls through your own gateway, use the documented third-party inference mode instead — the step-by-step walkthrough is in Claude Desktop developer mode and third-party inference.
4. Claude Code: Connect Your First Server in Three Steps
The example below uses the official filesystem server; the whole flow is one command plus one verification.
Step 1: Register the server
Claude Code provides the claude mcp add subcommand, so you can register the server directly:
# syntax: claude mcp add <name> -- <launch command> [args...]
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem /path/to/your/projectEverything after -- is the launch command for the server, which Claude Code starts over stdio. Add --scope to control where the configuration is written:
claude mcp add filesystem --scope project -- npx -y @modelcontextprotocol/server-filesystem .- --scope local: (default) written only to this machine’s private configuration for the current project; never committed.
- --scope project: written to .mcp.json at the project root, which can be committed to version control so teammates pick up the same configuration after cloning.
- --scope user: applies to all of your projects.
If you would rather not use the command line, edit the configuration file directly: for project scope, edit .mcp.json at the project root; for user / local scope, edit the user-level configuration. The structure is the same mcpServers object Claude Desktop uses.
Step 2: Verify the registration
claude mcp list # list registered servers and their connection statusInside an interactive session, typing /mcp also shows the currently mounted servers and their tools. If your server shows up in the list with a healthy status, the registration succeeded.
Step 3: Make one real call in a session
Start Claude Code and simply ask it to list the files in the project root with the filesystem tool. If Claude Code can list them, the whole chain — registration, process launch, tool call — is working. Your first successful call is best spent on a real task, for example asking it to read the dependency versions from package.json, so that you validate both the configuration and its practical payoff in one go.
To connect a remote MCP service (HTTP / SSE transport), swap the command for claude mcp add --transport http <name> <URL> and pass authentication headers with --header when needed. Always inject credentials from environment variables or command-line arguments — never into a .mcp.json that you commit to the repository.
If a tool call hangs instead of failing cleanly, the problem is usually a timeout rather than the registration. The defaults, the layers, and how to raise them are covered in Claude MCP tool call timeout.
The MCP server itself runs on your own machine: you can register it and call its tools without a model API key. The key only decides where Claude Code sends the model call — swapping it changes nothing about the server or the tools it exposes.
To replace Anthropic direct with a CodeGateway key, set ANTHROPIC_BASE_URL=https://api.codegateway.dev and set ANTHROPIC_API_KEY to your gateway key — see the Claude Code quick setup for the full steps. Claude Desktop has no base-URL setting: point it at a gateway with the third-party inference window instead. If you prefer a file over shell exports, the config generator writes that same base URL and key into ~/.claude/settings.json, ready to paste.
No official Anthropic key? Get Claude API credits: create an account, or top up on the Claude API credits page.
5. Common Servers Cheat Sheet
Three official servers cover most first setups. Names, launch commands and required environment variables:
Server | Package | Launch | Credentials |
|---|---|---|---|
filesystem | @modelcontextprotocol/server-filesystem | npx -y @modelcontextprotocol/server-filesystem <directory> | None — access is limited to the directories you pass |
github | @modelcontextprotocol/server-github | npx -y @modelcontextprotocol/server-github | GITHUB_PERSONAL_ACCESS_TOKEN |
fetch | mcp-server-fetch (Python) | uvx mcp-server-fetch | None |
For Claude Code, register each one with the same command you would run by hand: claude mcp add github -e GITHUB_PERSONAL_ACCESS_TOKEN=<token> -- npx -y @modelcontextprotocol/server-github. For Claude Desktop, put the same command and args into the mcpServers entry and the credential into its env object.
6. Common Errors Cheat Sheet
Symptom | Most likely cause | Fix |
|---|---|---|
claude mcp list shows the server but no tools | Server process never started, or crashed on launch | Run the command after -- manually in a terminal and read its output |
command not found | The PATH of the launched child process differs from your shell | Use an absolute path to node / npx, or declare the environment with -e / env |
npx exits or downloads forever on first run | First-run package download, or a registry/proxy problem | Pre-install the package, or run npx once by hand to warm the cache |
Permission denied / path outside the allowed roots | The tool tried to reach a directory you did not pass as an argument | Narrow or add the path arguments; never pass the disk root |
Tool call fails at about 60 seconds | The MCP SDK’s default request timeout, or a proxy idle timeout | See the MCP tool call timeout guide linked below |
The same tool ran twice | The client retried after a timeout | Raise the timeout or emit progress notifications; check the server log |
7. Troubleshooting: Scope, PATH and Permissions
Registered successfully but calls fail and the tool list is empty? Nine times out of ten the server process never started. Run the launch command that follows -- manually in your terminal and watch whether it produces output — the usual causes are a misspelled package name, an npx first-download timeout, or a missing dependency in the runtime environment. Get the command working verbatim in the terminal, then go back to claude mcp add.
"command not found"? The PATH Claude Code uses when it launches a child process may differ from your interactive shell. The most reliable fix is an absolute path to node / npx, or declaring the required environment variables explicitly with env in the configuration.
Server reports a permission error? For a file-system server, the arguments decide which directories it can touch — narrow the path to your project directory. For a database server, check the connection string and that the read-only account is configured. When the client prompts you to approve a tool call, read which tool it is and what it will touch before you allow it.
Configuration conflicts across projects? Remember the scope precedence: local > project > user. When the same name is registered in several scopes, the more specific scope overrides the broader one. To diagnose, start with claude mcp list to see which configuration is actually in effect.
Connection errors rather than tool errors? The timeout and TLS classes are covered separately in Claude Code connection timeout troubleshooting.
8. FAQ
Q: Where does Claude Desktop store MCP server configuration?
A: In claude_desktop_config.json — ~/Library/Application Support/Claude/claude_desktop_config.json on macOS and %APPDATA%\Claude\claude_desktop_config.json on Windows. The file has a single mcpServers object; each key is a server name and each value holds command, args and optionally env. Quit and reopen the app after editing it.
Q: What is the difference between claude mcp add and editing .mcp.json?
A: They write the same configuration. claude mcp add is the command-line shortcut and takes --scope local|project|user; .mcp.json at the project root is the project-scope file itself, which you can commit so teammates inherit it. Use the command for one-off setup and the file when the configuration belongs in version control.
Q: Why does a registered MCP server show no tools?
A: Almost always because the server process failed to start. Copy the command and args out of the configuration and run them verbatim in a terminal; fix whatever error appears there, then re-register. A missing package, a PATH difference, or a crashed child process all look identical from inside the client.
Q: Can I use MCP servers without an official Anthropic API key?
A: Yes. MCP servers run locally and are independent of the model provider; the model call is what needs a key. A gateway that implements the Anthropic Messages API can serve those model calls, and the MCP configuration stays exactly the same. The ANTHROPIC_BASE_URL setup below shows the client side.
9. Consolidate Your Keys: Route Model Calls Through One Gateway
Sooner or later configuration runs into a practical problem: many MCP servers want their own third-party account or credit card, while model calls each need a key of their own. Run two or three servers in a project and layer on several models, and keys end up scattered while the bill never adds up to a single number.
Instead of applying for a separate official key per upstream — — you can get one key from CodeGateway. It is a multi-model AI gateway: one key calls upstream models such as Claude / GPT / Gemini, with billing and quota managed in one place. Create a key in the CodeGateway Dashboard (the plaintext is shown once — save it immediately), then point Claude Code at the gateway with two environment variables:
export ANTHROPIC_BASE_URL=https://api.codegateway.dev
export ANTHROPIC_API_KEY=sk-cg-...
claude --print "hello" # one round trip proves the key and the base URLKeep those exports in your shell profile or a project-level .env that is git-ignored — never in a committed .mcp.json. MCP server entries are unchanged by this: they still launch locally over stdio; only the model calls move to the gateway. To estimate cost first, the pricing page lists the full rate card; to confirm model availability, the model catalog documents context window and capabilities per model.
Summary
Configuring an MCP server comes down to three things: point the client at a config file or register with claude mcp add, verify with the tool list, and get the first call through inside a real task. Claude Desktop reads one JSON file at startup; Claude Code offers scopes so a configuration can travel with the repository. When troubleshooting, always get the launch command working on its own in the terminal first, then come back to the configuration. Get this step right and the client stops being "an assistant that edits code" and becomes "a collaborator wired into your whole toolchain".
