Skip to main content

How to Set Up MCP in Claude Code

Set up MCP in Claude Code: add local and remote MCP servers, choose the right scope, authenticate with OAuth, and manage your connected tools.

Hosna Kachooee By Hosna Kachooee Updated August 2026

MCP (Model Context Protocol) is an open standard that lets Claude Code connect to external tools and data sources. Once you add an MCP server, Claude can read and act on that system directly, such as an issue tracker, a monitoring dashboard, or a database, instead of you copying and pasting data into the chat. This guide walks through adding servers, choosing where they live, signing in, and managing them.

What MCP is and why it matters

An MCP server is a small connector that exposes a tool’s capabilities to Claude Code. Connect one when you find yourself repeatedly pulling information from another system into a session. With servers connected, you can ask Claude to do things like “Review PR #456 and suggest improvements” or “Show me the schema for the orders table,” and it works against the real service.

There are a few transport types, which just describe how Claude Code talks to the server:

  • HTTP (--transport http): the recommended way to connect to remote, cloud-based services.
  • SSE (--transport sse): an older remote transport that is now deprecated. Use HTTP where you can.
  • stdio (--transport stdio): a local server that runs as a process on your own machine, ideal for tools that need direct system access.

One safety note before you connect anything: only add servers you trust. A server that pulls in external content can expose you to prompt injection, so treat unfamiliar servers with caution.

Adding a server with a real example

The main command is claude mcp add. For a remote HTTP server, the basic shape is:

claude mcp add --transport http <name> <url>

Here is a concrete example. GitHub’s remote MCP server authenticates with a personal access token passed as a header, so you generate a fine-grained token in your GitHub settings and then add the server:

claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \
  --header "Authorization: Bearer YOUR_GITHUB_PAT"

Replace YOUR_GITHUB_PAT with your real token. The command saves the configuration without validating the credential, so run /mcp inside Claude Code afterwards to confirm the server shows as connected. Then you can ask Claude things like “Create a new issue for the bug we just found.”

For a local (stdio) server, put the launch command after a double dash (--). Everything after -- is passed to the server untouched, so Claude Code does not mistake the server’s own flags for its options:

claude mcp add db -- npx -y @bytebase/dbhub \
  --dsn "postgresql://readonly:pass@prod.db.com:5432/analytics"

That connects Claude to a Postgres database through a read-only user, so the queries it runs cannot change your data. Pass environment variables with --env (placed after the name and before the --) when a server needs them.

Choosing a scope

Scope controls which projects a server loads in and whether it is shared with your team. There are three, set with the --scope (or -s) flag:

  • local (the default): available only to you, only in the current project. Stored in ~/.claude.json. Good for personal or experimental servers and anything with credentials you do not want to share.
  • project: shared with everyone on the project through a .mcp.json file at the project root. Commit that file to version control so your teammates get the same tools.
  • user: available to you across all your projects, but private to your account. Stored in ~/.claude.json.

A project-scoped server produces a standardized .mcp.json at your project root that looks like this:

{
  "mcpServers": {
    "shared-server": {
      "type": "http",
      "url": "https://example.com/mcp"
    }
  }
}

For security, Claude Code asks you to approve project-scoped servers from .mcp.json the first time you use them in an interactive session. You can also keep sensitive values out of the committed file with environment variable expansion, using ${VAR} or ${VAR:-default} inside fields like url and headers.

Authenticating remote servers with OAuth

Many cloud services require sign-in, and Claude Code supports OAuth 2.0. Add the server first, for example Sentry:

claude mcp add --transport http sentry https://mcp.sentry.dev/mcp

Then run /mcp inside Claude Code and follow the browser prompts to log in. Claude Code stores the token securely and refreshes it automatically, and you can revoke access later with “Clear authentication” in the /mcp menu. If you prefer to stay in your shell, claude mcp login <name> runs the same OAuth flow from the command line, with claude mcp logout <name> to clear it.

Managing your servers

Once servers are configured, a few commands keep them tidy:

# List all configured servers and their status
claude mcp list

# Get details for one server
claude mcp get github

# Remove a server
claude mcp remove github

Inside a Claude Code session, run /mcp to see server status, authenticate servers that need sign-in, and toggle a server off without deleting its configuration. claude mcp list shows a health status next to each server, such as connected, needs authentication, or failed to connect, so it is the quickest way to spot a bad credential or a typo in a URL.

Keep going

MCP turns Claude Code into a hub for the tools you already use, and it pairs well with the rest of the workflow. Explore more in the Claude Code hub, or start with how to install Claude Code, then layer on slash commands and subagents to build a setup that fits your projects. If you are newer to working with AI tools, our AI course covers the fundamentals, and you can start with the free lessons too.

Frequently asked questions

What is MCP in Claude Code?

MCP is the Model Context Protocol, an open standard for connecting AI tools to external systems. In Claude Code, an MCP server gives Claude direct access to a tool, database, or API, like GitHub, Sentry, or Postgres, so it can read and act on that system instead of you copying data into chat.

How do I add an MCP server to Claude Code?

Use the claude mcp add command. For a remote service, run claude mcp add --transport http <name> <url>. For a local tool, run claude mcp add <name> -- <command> [args], putting the launch command after the double dash. Then run /mcp inside Claude Code to check the connection or sign in.

Where are my MCP servers stored?

It depends on the scope. Local and user servers live in ~/.claude.json, while project servers live in a .mcp.json file at your project root that you commit so your team shares the same tools. Local is the default and stays private to you in one project.

Start free

Get free access to our beginner courses

Drop your email and we'll let you know the moment each free course is live - plus new courses and deals. No spam, unsubscribe anytime.

Master Claude Code from start to finish

This is one lesson from a much larger course. Get the full course with a single one-time payment and lifetime access.

Explore our AI course