Skip to content
Advertisement

How to Add MCP Servers to Cursor, Codex, Gemini CLI, opencode

SumitSumit··8 min read
Cursor, OpenAI and Gemini logos above the words MCP servers for coding agents

The good news about MCP (Model Context Protocol) is that a server written once works in every agent that speaks the protocol. The annoying part is that every agent wants it configured differently: JSON in one place, TOML in another, a slightly different key name in a third.

This guide shows exactly how to add an MCP server to Cursor, Codex, Gemini CLI and opencode, with copy-paste config for each, plus which features each client supports. We have Codex, Gemini CLI, opencode and Claude Code all installed on the machine this was written on, and every config format was checked against official docs on September 26, 2026. Looking for which servers to install? See our list of the best MCP servers for Claude: every server in it works in these agents too.

Quick answers
  • Any MCP server works in Cursor, Codex, Gemini CLI, opencode and Claude Code. All five support local (stdio) servers and remote HTTP servers with OAuth.
  • Config files: Cursor uses .cursor/mcp.json, Codex uses ~/.codex/config.toml, Gemini CLI uses .gemini/settings.json, opencode uses opencode.json.
  • Codex, Gemini CLI and Claude Code have an mcp add command, so you rarely edit files by hand.
  • Gemini CLI uses httpUrl for remote servers, and opencode wants the command as an array. Those two trip people up most.
  • Big servers like GitHub (90+ tools) can crowd the context in agents without on-demand tool loading. Use tool filters.

Which clients support what

CursorCodex CLIGemini CLIopencodeClaude Code
Local (stdio) serversYesYesYesYesYes
Remote HTTP serversYesYesYesYesYes
OAuth loginYescodex mcp loginYes (oauth block)Automatic/mcp
Add from command lineNo (one-click install instead)codex mcp addgemini mcp addNo (edit config)claude mcp add
Project-level config.cursor/mcp.json.codex/config.toml (trusted projects).gemini/settings.jsonopencode.json.mcp.json
Global config~/.cursor/mcp.json~/.codex/config.toml~/.gemini/settings.json~/.config/opencode/opencode.json~/.claude.json
Filter tools per serverNo documented optionenabled_tools, disabled_toolsincludeTools, excludeToolsGlob patterns in toolsVia toolset flags
Loads tools on demandNot documentedNot documentedNot documentedNoYes (tool search)

That last row matters more than it looks. Claude Code only loads a tool's full definition when it needs it. The others load every tool from every enabled server up front, so the GitHub server's 90+ tools cost context on every message. opencode's own docs single out GitHub as a server that "can easily exceed the context limit". Use tool filters in agents that have them.

A note on Gemini CLI

Gemini CLI's MCP support is excellent, but since June 18, 2026 it only serves Gemini Code Assist Standard or Enterprise licences and paid API keys. Free and Google AI Pro users moved to Antigravity CLI. Details in our Claude Code vs Codex vs Gemini CLI vs opencode comparison.

Setup for each client

The examples below add two servers: Context7 (remote) and Playwright (local). Swap in any server you like.

Cursor

Create .cursor/mcp.json in your project, or ~/.cursor/mcp.json for every project:

{
  "mcpServers": {
    "context7": {
      "url": "https://mcp.context7.com/mcp",
      "headers": { "Authorization": "Bearer ${env:CONTEXT7_API_KEY}" }
    },
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    }
  }
}

Cursor supports ${env:NAME} and ${workspaceFolder} in configs, so keys stay out of the file. OAuth servers show "Needs login" in settings; click it. Many servers also offer a one-click "Add to Cursor" button.

Codex CLI

The quickest way is the command:

codex mcp add playwright -- npx @playwright/mcp@latest
codex mcp add context7 --url https://mcp.context7.com/mcp --bearer-token-env-var CONTEXT7_API_KEY
codex mcp list

Or edit ~/.codex/config.toml directly:

[mcp_servers.playwright]
command = "npx"
args = ["@playwright/mcp@latest"]

[mcp_servers.github]
url = "https://api.githubcopilot.com/mcp/"
bearer_token_env_var = "GITHUB_PAT"
enabled_tools = ["list_issues", "get_issue", "create_pull_request"]

The same file is shared by the Codex CLI, the IDE extension and the desktop app, so you set a server up once. enabled_tools is the easiest way to tame a big server. Run codex mcp login <name> for OAuth servers.

Gemini CLI

gemini mcp add -s user playwright npx @playwright/mcp@latest
gemini mcp add -s user -t http context7 https://mcp.context7.com/mcp

The default scope is the project; -s user makes it global. In settings.json it looks like this. Note that a streamable HTTP server uses httpUrl, not url (which means the older SSE transport):

{
  "mcpServers": {
    "context7": { "httpUrl": "https://mcp.context7.com/mcp" },
    "github": {
      "httpUrl": "https://api.githubcopilot.com/mcp/",
      "headers": { "Authorization": "Bearer $GITHUB_PAT" },
      "includeTools": ["list_issues", "get_issue"]
    }
  }
}

Type /mcp inside Gemini CLI to see server status.

opencode

opencode has no add command; you edit opencode.json in the project or ~/.config/opencode/opencode.json. Local servers take the command as an array:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "playwright": {
      "type": "local",
      "command": ["npx", "@playwright/mcp@latest"],
      "enabled": true
    },
    "context7": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp"
    }
  },
  "tools": {
    "github*": false
  }
}

OAuth starts automatically for remote servers that need it (opencode mcp auth <name> to do it by hand). The tools block uses glob patterns to switch a server's tools off globally, and you can switch them back on for a single agent. That is a neat way to give only your "review" agent access to GitHub.

Claude Code (for comparison)

claude mcp add playwright -- npx @playwright/mcp@latest
claude mcp add --transport http context7 https://mcp.context7.com/mcp

--scope project writes a .mcp.json your team can commit. Full details in our Claude MCP guide.

Five servers to start with

Once your client is set up, these are the servers we would add first. Each one is written up in full, with safety notes, in our best MCP servers for Claude list.

  • Context7 (https://mcp.context7.com/mcp): current library docs, only two tools.
  • Playwright MCP (npx @playwright/mcp@latest): lets the agent drive a browser and check its UI work.
  • GitHub MCP (https://api.githubcopilot.com/mcp/): issues, PRs and Actions. Filter its tools.
  • Your database vendor's server: Supabase, Neon or DBHub for plain SQL. Read-only mode on.
  • Sentry (https://mcp.sentry.dev/mcp): errors and stack traces, so "find and fix the new bug" is one prompt.

One config for every agent?

There is no single shared MCP config file yet. Two ways to avoid maintaining five copies:

  1. Docker MCP Gateway. Configure servers once in Docker's gateway, then connect each client to the gateway (docker mcp client connect <client>). Each server runs in its own container with managed secrets.
  2. Prefer remote servers. A remote URL with OAuth is one line in every client and needs no local runtime. Most vendors (GitHub, Supabase, Sentry, Linear, Notion, Figma, Cloudflare, Vercel) now offer one.

Some servers restrict which clients can connect. Vercel's MCP server, for example, only accepts approved clients; Cursor, Codex, Gemini CLI, opencode and Claude Code are all on its list.

Security checklist

  • Use official vendor servers; read the code of any community server first
  • Turn on read-only modes (Supabase read_only=true, GitHub /readonly, Neon readonly=true)
  • Reference secrets as environment variables, never paste them into a committed config
  • Filter tools on big servers to cut both context use and blast radius
  • Never give an agent production database or live payment credentials
  • Treat anything a server returns as untrusted: web pages and tickets can carry prompt injection

Setting up an agent from scratch? Pick one with our comparison of Claude Code, Codex, Gemini CLI and opencode, or go zero-cost with our free AI coding agents guide. If you run a home server, our home lab MCP servers list covers Proxmox, Docker and Home Assistant.

Do MCP servers work in Cursor, Codex and Gemini CLI?
Yes. MCP is an open protocol, so the same server works in Cursor, Codex CLI, Gemini CLI, opencode, Claude Code and other agents. Only the configuration format differs between clients.
Where is the MCP config file for Codex?
Codex reads MCP servers from ~/.codex/config.toml under [mcp_servers.] tables. Trusted projects can also have a .codex/config.toml. You can add servers without editing the file using codex mcp add.
How do I add an MCP server to opencode?
Add it under the mcp key in opencode.json (project) or ~/.config/opencode/opencode.json (global). Local servers use type local with the command as an array; remote servers use type remote with a url. OAuth starts automatically.
Why does the GitHub MCP server use so much context?
It exposes 90+ tools across all toolsets, and most agents load every tool definition up front. Limit it with a toolset or read-only URL, or with tool filters like enabled_tools in Codex, includeTools in Gemini CLI or glob patterns in opencode.
What is the best MCP server for coding?
Context7 is the most useful single server for most developers: it gives the agent current documentation for the libraries you use, with only two tools. After that, a browser server (Playwright or Chrome DevTools) and GitHub's official server cover most needs.
SSumit

Sumit

Contributor

Hi, I'm Sumit, Being an introvert I have always been obsessed with technology-computers and reading dozens of posts to learn, find answers out of my curiosity. I love to write as I explore more.

106 articles writtenView all posts by Sumit →

Related articles

See all