Guide

How to Set Up an MCP Server (Any Coding Agent)

Model Context Protocol (MCP) servers give your coding agent new tools — GitHub, web search, browser automation, your design files. The wiring is the same idea across agents but the commands differ. This guide explains the transport types, then gives the exact add command for Claude Code, OpenCode, and Codex CLI — verified first-hand against current versions on 2026-06-20.

By DK, Editor  ·  Last verified: 2026-06-20  · Claude Code v2.1.183, OpenCode v1.17.8, Codex CLI v0.141.0 (installed & run 2026-06-20)  ·  How we test

Before you start

  • A coding agent installed and authenticated (Claude Code, OpenCode, or Codex CLI)
  • The MCP server you want to add — an npm package / local binary (stdio), or a remote URL (HTTP/SSE)
  • Node.js if the server is an npm package run via npx
  • Any API key or bearer token the server requires (set as an environment variable or auth header, never hard-coded)

Steps

  1. 01

    Pick the transport: stdio, HTTP, or SSE

    Every MCP server uses one of three transports. stdio launches a local process and talks over stdin/stdout — this is most npm-packaged servers. HTTP connects to a hosted endpoint over request/response. SSE (Server-Sent Events) connects to a hosted endpoint that streams events. Use stdio for local tools; use HTTP or SSE for hosted services. Check the server's own docs for which it supports.

    # stdio  -> local process (e.g. npx a-package)
    # http   -> remote URL, request/response
    # sse    -> remote URL, streamed events
  2. 02

    Add a server in Claude Code

    Claude Code uses claude mcp add. Pass a stdio command after --, or use --transport http/sse with a URL. Inject secrets with -e KEY=value (stdio) or --header (remote). Claude Code has three scopes via -s: local (default, this project, private), user (all sessions), and project (written to .mcp.json, shared with the repo and approved per-developer).

    # stdio (local), default 'local' scope
    claude mcp add my-server -- npx my-mcp-server
    
    # stdio with an env var, available in every session
    claude mcp add -s user my-server -e API_KEY=xxx -- npx my-mcp-server
    
    # remote HTTP with a bearer token
    claude mcp add --transport http my-server https://example.com/mcp --header "Authorization: Bearer <token>"
    
    # manage
    claude mcp list && claude mcp get my-server
  3. 03

    Add a server in OpenCode

    OpenCode uses opencode mcp add with a name. Pass --url for a remote server, --header for HTTP headers, or --env for a local server's environment variables. For OAuth-based servers (e.g. GitHub), run opencode mcp auth <name> after adding; opencode mcp debug <name> helps when auth succeeds but tools do not appear.

    # remote HTTP server with an auth header
    opencode mcp add github --url https://mcp.example.com/github --header Authorization="Bearer <token>"
    
    # local server with an env var
    opencode mcp add my-server --env API_KEY=your_key_here
    
    # verify / authenticate
    opencode mcp list
    opencode mcp auth github
  4. 04

    Add a server in Codex CLI

    Codex CLI uses codex mcp add: a stdio command after --, or --url for a streamable HTTP server. Servers are written to ~/.codex/config.toml (command + args keys; env in a nested table). For OAuth servers use codex mcp login <name>; for token servers pass --env or --bearer-token-env-var. Run codex doctor if a server stops appearing.

    # stdio server
    codex mcp add context7 -- npx -y @upstash/context7-mcp
    
    # remote HTTP server with a token env var
    codex mcp add github --url https://api.githubcopilot.com/mcp --bearer-token-env-var GITHUB_PAT
    
    # manage
    codex mcp list && codex mcp get context7
  5. 05

    Verify the server is connected

    After adding, confirm the agent can see the server's tools. In Claude Code, run /mcp inside the session (or claude mcp list from the shell). In OpenCode, run opencode mcp list. In Codex CLI, run codex mcp list and codex doctor. Then ask the agent what tools it has, or give it a task that uses the new server.

    # Claude Code (inside the session)
    /mcp
    
    # OpenCode / Codex (shell)
    opencode mcp list
    codex mcp list
  6. 06

    Keep secrets out of config, and avoid tool bloat

    Never hard-code API keys in shared config (.mcp.json, config.toml). Reference environment variable names instead and set the values in your shell or a gitignored .env. And connect only the 2-3 servers you actually need: practitioners report that more than 5-7 connected servers floods the tool list and degrades the agent's tool selection. Remove servers you are not using.

    # remove a server you are not using
    claude mcp remove my-server
    opencode mcp logout github   # clears OAuth creds (OpenCode)
    codex mcp remove github

Popular MCP servers

  • Context7

    Pulls live, version-pinned library docs into context to prevent hallucinated APIs. A common first server for any agent.

    claude mcp add context7 -- npx @upstash/context7-mcp
  • GitHub

    Read/write access to repos, issues, PRs, CI, and code search. Now a remote server (the old npm package is deprecated); use the hosted endpoint with a token.

    claude mcp add --transport http github https://api.githubcopilot.com/mcp --header "Authorization: Bearer <your-pat>"
  • Playwright

    Drives a real browser for UI testing and scraping — navigate, click, fill forms, screenshot.

    claude mcp add playwright -- npx @playwright/mcp@latest
  • Exa

    Semantic web search returning full-text results; the most-used search MCP for coding agents in 2026. Requires an Exa API key.

    claude mcp add exa -e EXA_API_KEY=<your-key> -- npx exa-mcp-server

Troubleshooting

The server command is 'not found' when the agent starts it
stdio servers must be resolvable on the PATH the agent sees at startup, which can differ from your interactive shell. Use npx <package> so it resolves at runtime, or install the package globally and confirm with npm list -g. Add the npm global bin to your PATH in your shell profile and restart the agent.
Tools from the server never appear
Check the server registered (claude mcp list / opencode mcp list / codex mcp list). For project-scope servers in Claude Code's .mcp.json, approve them when prompted (or run claude mcp reset-project-choices). For OAuth servers, complete opencode mcp auth <name> or codex mcp login <name>. Confirm the server process starts on its own outside the agent.
A remote (HTTP/SSE) server returns 401
Verify the token and header format. Many servers require the header to be exactly Authorization: Bearer <token>. Inspect what you stored (claude mcp get <name> / codex mcp get <name>), regenerate the token if it expired, and re-add. Confirm the exact header the server expects in its own docs.
The agent gets worse after you add several servers
This is tool bloat: connecting more than ~5-7 servers overflows the tool list the model can reason about, causing wrong or ignored tool calls. Keep 2-3 servers active for a given task and remove the rest (claude mcp remove / codex mcp remove). Re-add them when you actually need them.

FAQ

What is an MCP server, in one sentence?
An MCP (Model Context Protocol) server is a small program that exposes tools — like GitHub access, web search, or browser control — that a coding agent can call during a task. You register it once with your agent, and the agent gains those tools.
What is the difference between stdio, HTTP, and SSE transport?
stdio launches a local process and communicates over stdin/stdout — used for npm-packaged and binary servers your agent runs locally. HTTP connects to a hosted endpoint over request/response. SSE connects to a hosted endpoint that streams events over a persistent connection. Use stdio for local tools and HTTP/SSE for hosted services; check the server's docs for which it supports.
How do I add the same MCP server to Claude Code, OpenCode, and Codex?
The concept is identical but commands differ: claude mcp add <name> -- <cmd> (or --transport http <url>) for Claude Code; opencode mcp add <name> --url <url> (or --env) for OpenCode; codex mcp add <name> -- <cmd> (or --url) for Codex CLI. Each was verified first-hand on 2026-06-20. See our per-agent guides for the full surface.
How many MCP servers should I connect at once?
Keep 2-3 active for a given task. Connecting more than 5-7 at once tends to flood the tool list faster than the model can reason about it cleanly — a phenomenon called tool bloat that leads to wrong or ignored tool calls. Register more in config but keep your active session lean.
Is it safe to commit my MCP config to a repo?
The config (server names, commands, URLs) is safe to commit; secrets are not. Reference environment variable names in config and set the actual values in your shell or a gitignored .env file. In Claude Code, project-scope servers in .mcp.json require each teammate to approve them before tools activate, which prevents a repo from silently running code on clone.