Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Tutorial

Connect MCP servers to Claude Code, Codex and Cursor

Add local and remote MCP servers to Claude Code, Codex and Cursor, choose the right scope, sign in with OAuth and check which tools actually loaded.

By Beginner25 min hands-on
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
Quiz at the end
On this page

An MCP server gives your coding agent new tools: a browser to drive, a docs index to search, your issue tracker to read. The protocol is the same everywhere, but each agent stores its server list in a different place and with slightly different syntax. This tutorial adds the same two servers to Claude Code, Codex and Cursor:

  • Context7, a local server (stdio) that fetches current library documentation.
  • Sentry, a remote server (Streamable HTTP) that needs you to sign in.

Then it shows how to check what loaded, and how to decide who else should get the configuration. Commands were checked against each tool’s docs on 20 November 2026.

Local or remote?

A local server is a program the agent starts on your machine and talks to over standard input and output (the stdio transport). You configure the command that starts it. It runs with your user’s permissions, so it can read what you can read.

A remote server is a web service the agent connects to by URL over Streamable HTTP. You configure the URL and, usually, sign in with OAuth in your browser. Nothing runs on your machine except the connection.

Claude Code

Claude Code manages servers with claude mcp. For a local server, everything after -- is the command that starts it:

claude mcp add context7 -- npx -y @upstash/context7-mcp

For a remote server, pass the transport and the URL:

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

Then start a session and run /mcp. Sentry shows as needing authentication; select it and follow the browser sign-in. Claude Code stores the token, so you do this once per machine.

If a server needs an API key, pass it with --env before the server name, and put another option between --env and the name so the CLI does not read the name as a second variable:

claude mcp add --env MY_API_KEY=xxxx --transport stdio my-server -- npx -y some-mcp-server

Scopes in Claude Code

Every server has a scope that decides where it is stored and who gets it:

Scope Flag Stored in Who gets it
Local (default) --scope local ~/.claude.json, under this project You, in this project
Project --scope project .mcp.json in the repository Everyone who clones the repo
User --scope user ~/.claude.json You, in every project

A project-scoped .mcp.json looks like this, and is the file to commit when the whole team needs a server:

{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp"]
    },
    "sentry": {
      "type": "http",
      "url": "https://mcp.sentry.dev/mcp"
    }
  }
}

Note "type": "http" on the remote entry. An entry with a url but no type is treated as stdio and skipped. Claude Code asks each person to approve project-scoped servers the first time it sees them, because a cloned repository should not be able to start programs on your machine silently.

Keep secrets out of .mcp.json. It expands environment variables, so reference them instead:

{
  "mcpServers": {
    "internal-api": {
      "type": "http",
      "url": "${API_BASE_URL:-https://api.example.com}/mcp",
      "headers": { "Authorization": "Bearer ${INTERNAL_API_TOKEN}" }
    }
  }
}

Useful commands: claude mcp list (with health status), claude mcp get <name>, claude mcp remove <name>. Removing a remote server deletes the local token but does not revoke it at the provider; run claude mcp logout <name> first if you want it revoked.

Codex

Codex has the same shape of command:

codex mcp add context7 -- npx -y @upstash/context7-mcp
codex mcp add sentry --url https://mcp.sentry.dev/mcp
codex mcp login sentry

codex mcp login runs the OAuth sign-in. Everything is stored in ~/.codex/config.toml, which you can also edit directly:

[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]

[mcp_servers.sentry]
url = "https://mcp.sentry.dev/mcp"

For a project-only server, put the same tables in .codex/config.toml in the repository. Codex only reads project config in projects you have marked as trusted.

Two keys worth knowing:

[mcp_servers.context7]
command = "npx"
args = ["-y", "@upstash/context7-mcp"]
startup_timeout_sec = 20       # default 10; raise it for slow first npx downloads
enabled_tools = ["resolve-library-id", "query-docs"]

enabled_tools (and its opposite, disabled_tools) limit which of a server’s tools the model sees. Fewer tools means less context spent on tool descriptions and fewer wrong choices. Check the tool names with /mcp before you restrict them. In the Codex TUI, /mcp lists servers and their tools; codex mcp list does the same from the shell.

Cursor

Cursor reads JSON from two files: .cursor/mcp.json in the project and ~/.cursor/mcp.json for every project. The format matches Claude Code’s .mcp.json closely:

{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp"]
    },
    "sentry": {
      "url": "https://mcp.sentry.dev/mcp"
    }
  }
}

Cursor uses ${env:NAME} for environment variables, not ${NAME}:

{
  "mcpServers": {
    "internal-api": {
      "url": "https://api.example.com/mcp",
      "headers": { "Authorization": "Bearer ${env:INTERNAL_API_TOKEN}" }
    }
  }
}

After saving, open the MCP section of Cursor’s settings (under Customize in current versions). Each server shows a status dot and its tool list; remote servers that need OAuth show a sign-in button. You can switch servers off there without deleting them. Cursor asks before running MCP tools by default.

Check what actually loaded

A server that is configured is not necessarily a server that works. Before you rely on one:

  1. Look at the status. /mcp in Claude Code and Codex, the MCP settings panel in Cursor. A failed start usually means a wrong path, a missing runtime, or a first npx download that timed out.
  2. Read the tool list. Are these the tools you expected? A server with forty tools costs context even when idle. Turn off servers you are not using.
  3. Ask a question only the server can answer.
use context7 to look up how to define a route in the current version of Hono

You should see a call to a Context7 tool in the transcript before the answer. If the agent answers from memory instead, the server is not loaded or its tool descriptions are not matching your request.

  1. Test the server without an agent when something is odd. MCP Inspector connects to a server directly and lets you call each tool by hand:
npx @modelcontextprotocol/inspector npx -y @upstash/context7-mcp

Deciding where a server belongs

  • Project scope for servers the code needs: the project’s database in a dev environment, the team’s issue tracker, Playwright for the end-to-end suite. Commit the config, not the secrets.
  • User scope for personal tools: your notes, your docs lookup.
  • Nowhere for servers you have not read. A local server is a program running as you; a remote server sees whatever your agent sends it and returns text your agent will read. Treat adding one like installing a package. MCP security risks explains what can go wrong.

Pitfalls

Relative paths. Agents start local servers from their own working directory. Use absolute paths for anything that is not on your PATH.

Secrets in committed files. Use variable expansion, and add .claude/settings.local.json and any .env files to .gitignore.

Too many servers. Each one adds tool descriptions to every request. Claude Code defers tool definitions by default, but Codex and Cursor have their own limits and costs. Keep the list short.

Stale OAuth tokens. If a remote server suddenly fails, sign in again with /mcp (Claude Code), codex mcp login or the Cursor settings panel.

Next steps

Covers

Check your understanding

Connect MCP servers to your agent quiz

Local and remote servers, Claude Code scopes, Codex and Cursor config files, OAuth sign-in and checking which tools loaded.

7 questions · pass mark 70%

Question 1 of 70 answered
  1. What is the difference between a local and a remote MCP server?
  • MCP explained: hosts, clients, servers and transports

    What MCP is and how the Model Context Protocol connects AI apps to tools and data: hosts, clients, servers, transports and what the 2026-07-28 spec changed.

    TutorialBeginner20 min

  • MCP config cheat sheet

    Where Claude Code, Codex and Cursor keep MCP server config, with copyable JSON and TOML for local and remote servers, secrets, scopes and OAuth commands.

    Article

  • MCP security: tool poisoning, token scope and the lethal trifecta

    The real attacks on MCP setups, from tool poisoning and rug pulls to token passthrough and the lethal trifecta, what hosts do about them, and a checklist.

    Article

  • MCP servers worth installing, checked

    A short list of MCP servers worth installing for browsers, GitHub, docs and databases, with the access each one needs and the security settings to turn on.

    Article

  • MCP server

    A program that exposes tools, resources or prompts to MCP clients, running locally over stdio or remotely over HTTP, so any MCP host can use them.

    Glossary

Back to top