
# MCP Server + Claude Code: Add One with claude mcp add

**Adding a remote MCP server Claude Code can use takes one command: `claude mcp add --transport http <name> <url>`.** For a local server that runs on your machine, put its launch command after `--` instead. Then check the connection with `claude mcp list` or with `/mcp` inside a session.

Below: the full syntax from the [Claude Code docs](https://code.claude.com/docs/en/mcp), scopes, `.mcp.json`, and a working example with the 0x.cloud MCP server, which lets Claude Code price and create a VPS on its own.


## Add a remote MCP server to Claude Code

Remote servers use HTTP, the recommended transport:

```bash
# name, then URL; http transport
claude mcp add --transport http <name> <url>
```

If the service expects an API key in a header, add `--header` (short form `-H`):

```bash
# the key is sent in the Authorization header on every request
claude mcp add --transport http my-api https://api.example.com/mcp \
  --header "Authorization: Bearer your_key"
```

If the service uses OAuth sign-in, skip the header. Start `claude`, type `/mcp`, pick the server, and finish the login in your browser. Claude Code stores and refreshes the tokens for you. From the shell you can also run `claude mcp login <name>`.

Two gotchas. If you configured an `Authorization` header and the service rejects it, Claude Code reports a failed connection instead of falling back to OAuth: fix the key or remove the header to sign in. And non-interactive runs (`claude -p`, the Agent SDK) have no sign-in panel, so complete the login once in a normal session first.

## Add a local (stdio) MCP server

A local server is a process Claude Code starts on your machine. Options for Claude Code go before `--`; the server's own command and arguments go after it:

```bash
# pass an env var to the server and start it with npx
claude mcp add --transport stdio --env AIRTABLE_API_KEY=your_key airtable \
  -- npx -y airtable-mcp-server
```

On native Windows (not WSL), if an `npx` server fails with `Connection closed`, wrap it in `cmd /c`:

```powershell
claude mcp add --transport stdio my-server -- cmd /c npx -y some-mcp-package
```

## Claude Code MCP scopes: local, project, user

The `--scope` flag (`-s`) controls where the server is saved and who sees it:

| Scope | Stored in | Available to |
|---|---|---|
| `local` (default) | `~/.claude.json`, under the current project | you, in this project only |
| `project` | `.mcp.json` in the project root | everyone on the repo |
| `user` | `~/.claude.json` | you, in every project |

Use `--scope user` for a server you want everywhere, like your cloud provider. Use `--scope project` for a team server and commit `.mcp.json`, but never with a key inside. Claude Code asks you to approve servers from `.mcp.json` before first use; reset those choices with `claude mcp reset-project-choices`.

## Claude Code MCP config: .mcp.json with env vars

Keep keys out of git with variable expansion. Claude Code expands `${VAR}` and `${VAR:-default}` in `url`, `headers`, `command`, `args`, and `env`:

```json
{
  "mcpServers": {
    "0x-cloud": {
      "type": "http",
      "url": "https://0x.cloud/v1/mcp",
      "headers": {
        "Authorization": "Bearer ${OX_API_KEY}"
      }
    }
  }
}
```

Set the variable in your shell before starting Claude Code: `export OX_API_KEY=...` on Linux and macOS, `$env:OX_API_KEY = "..."` in PowerShell. If it's unset, `claude mcp list` shows a warning and the server receives the literal `${OX_API_KEY}` text, which ends in a 401. A pasted key with a trailing space or newline also triggers a warning: `Leading or trailing whitespace in: headers.Authorization`.

You can also add a JSON definition in one go with `claude mcp add-json <name> '<json>'`.

## Check and manage servers

```bash
claude mcp list             # every server and its status
claude mcp get 0x-cloud     # details for one server
claude mcp remove 0x-cloud  # remove a server
```

Inside a session, `/mcp` shows status and tools, and lets you sign in or clear authentication.

## Example: the 0x.cloud MCP server in Claude Code

With the 0x.cloud MCP server, Claude Code gets an exact price with `dry_run`, creates a server, lists your servers and balance, runs commands inside a server without SSH, takes snapshots, and deletes servers. The agent only sees tools the connection has permission for. See the [0x.cloud MCP server](https://0x.cloud/mcp) page for the full tool list.

**Option 1: sign in, no key (OAuth).** Add the server without a header and log in:

```bash
claude mcp add --transport http --scope user 0x-cloud https://0x.cloud/v1/mcp
claude mcp login 0x-cloud
```

The 0x.cloud sign-in page opens, and you choose the permissions, monthly spend cap, expiry, and "own servers only" restriction yourself. The connection then appears in your dashboard as a regular API key you can edit or revoke.

**Option 2: API key.** Create a dedicated key for Claude Code with `servers.read` and `servers.create`, without `servers.delete`, and a monthly spend cap such as $20. The create permission is also what `dry_run` needs. Keys get `servers.*` by default, which includes delete, so remove it explicitly. Details: [API key permissions](https://0x.cloud/kb/api-mcp/api-keys). Then run the ready-made install command:

```bash
npx -y @0xcloud/mcp
```

Or add it by hand, globally:

```bash
claude mcp add --transport http --scope user 0x-cloud https://0x.cloud/v1/mcp \
  --header "Authorization: Bearer your_key"
```

Check it: start `claude`, type `/mcp`, and confirm `0x-cloud` is connected. Then give it a task:


```text
Create an s2-4 server with Ubuntu 24.04 and hourly billing on 0x.cloud for my agent. Show me the price with dry_run first and wait for my approval. After it's created, wait until it's ready and tell me its id and status.
```


The agent gets the exact price, asks you, and only then creates the server. The whole flow is in how an AI agent creates a server. On hourly billing an s2-4 (2 vCPU, 4 GB RAM) costs about $0.109520 per hour, and deleting it stops charges right away with the remainder returned to your balance. To run Claude Code itself on a VPS around the clock, follow [Claude Code on a server](https://0x.cloud/deploy/claude-code); s2-4 at $15.99 a month fits a coding agent, and ready options are on [Claude Code VPS](https://0x.cloud/claude-code-vps).

## Troubleshooting MCP in Claude Code

| Symptom | Cause and fix |
|---|---|
| `Failed to connect` in `claude mcp list` | check the URL and transport: URLs need `--transport http` |
| 401 / Unauthorized | wrong, revoked, or expired key, or a typo in `Bearer`; for OAuth, sign in via `/mcp` or `claude mcp login` |
| `⏸ Pending approval` for a `.mcp.json` server | run `claude` in the project folder and approve it |
| create tool refused over a spend limit | the connection's monthly cap is used up; only the owner can raise it in the 0x.cloud dashboard |
| warning about `${OX_API_KEY}` | the variable isn't set in the shell that launched `claude` |
| local server times out on start | raise the startup timeout: `MCP_TIMEOUT=10000 claude` (10 seconds) |
| server shows in one project but not another | it was added with `local` scope; re-add with `--scope user` |
| Windows: `Connection closed` on an `npx` server | try the `cmd /c npx ...` wrapper, or run Claude Code in WSL |

Using Claude on the web or Claude Desktop instead? Those use custom connectors: see [how to connect an MCP server to Claude](https://0x.cloud/kb/api-mcp/mcp-claude).


[Create server: s2-4, $15.99/mo](https://0x.cloud/cabinet/create?plan=s2-4)


## MCP server Claude Code FAQ

**How do I add an MCP server to Claude Code globally?**
Use --scope user: claude mcp add --transport http --scope user <name> <url>. The server is saved in ~/.claude.json and is available in every project.

**Where does Claude Code store MCP config?**
Local and user scope servers live in ~/.claude.json. Project scope servers live in .mcp.json at the project root, which you can commit so your whole team gets the server.

**How do I remove an MCP server from Claude Code?**
Run claude mcp remove <name>. That deletes the stored OAuth tokens locally but does not revoke them at the service; to revoke them, run claude mcp logout <name> first.

**Why won't my MCP server connect in Claude Code?**
Run claude mcp list, or /mcp inside a session, to see the status and error. Common causes are a wrong URL, a missing auth header, or an unset environment variable for the key.
