Home › Claude Code › MCP
OverviewInstallCLI referencePricing & limitsAgent SDKSkills & pluginsGitHubWeb, desktop & IDEModelsErrorsOpen source?TutorialFor studentsQA automationvs Cursorvs Codex & OpenCodeSubagentsHooksMCPEcosystemVS CodeOpenRouterRate limits中文指南
Last updated: November 06, 2026

Claude Code MCP: connecting servers, scopes, remote MCP and real examples

MCP — the Model Context Protocol — is how Claude Code reaches things that are not files in your repo: a database, a browser, GitHub, your analytics, your ticket tracker. A server exposes tools and resources; Claude Code connects to it and the agent can use them like any built-in tool. Setup is one command per server.

TLDR

  • claude mcp add <name> -- <command> for local (stdio) servers; claude mcp add --transport http <name> <url> for remote ones.
  • Scopes: local (you, this project), project (.mcp.json, shared with the repo), user (you, every project).
  • /mcp inside a session shows status, authenticates OAuth servers and lists their tools.
  • Resources are @-mentionable; server prompts appear as slash commands.

Adding a server

# local server over stdio (runs the command, talks over its stdin/stdout)
claude mcp add playwright -- npx @playwright/mcp@latest

# remote server over HTTP
claude mcp add --transport http github https://api.githubcopilot.com/mcp/

# with a header (API-key style auth)
claude mcp add --transport http posthog https://mcp.posthog.com/mcp \
  --header "Authorization: Bearer $POSTHOG_API_KEY"

claude mcp list      # what is configured
claude mcp remove playwright

Stdio servers are programs Claude Code starts for you — most community servers are npm or Python packages run this way. Remote servers are URLs; they authenticate with OAuth (run /mcp in a session and follow the browser flow) or with a header you pass at add time, as in the PostHog example. Check each vendor's docs for the current URL — remote endpoints move.

Scopes and .mcp.json

  • local (default) — stored in your user settings, for this project only. Personal, private servers.
  • project (--scope project) — written to .mcp.json in the repo root and shared with everyone who clones it. Claude Code asks before trusting a project's servers the first time.
  • user (--scope user) — available in every project on your machine.
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres", "${DATABASE_URL}"]
    }
  }
}

.mcp.json supports environment-variable expansion, so the repo can ship the server definition while each developer supplies their own credentials.

Using a server in a session

Once connected, the server's tools are simply available — ask for "the last 24 hours of errors from PostHog" and Claude Code calls the tool. Resources the server exposes can be referenced with @-mentions (@github:issue://123), which pulls them into context on demand. Prompts a server defines show up as slash commands under /mcp__<server>__<prompt>. /mcp shows connection status, lets you reconnect or authenticate, and lists every tool with its description.

Examples worth copying

  • PostHog MCP — product analytics from inside the agent: "which feature flag is this code behind, and what is its rollout?" PostHog publishes a remote MCP server; add it with --transport http and your personal API key as a bearer header.
  • GitHub — issues and pull requests as context; pair it with the GitHub guide's Action for the review loop.
  • Playwright — a real browser for end-to-end tests and for checking the UI you just changed; see the QA automation guide.
  • Postgres / SQLite — schema-aware queries and migrations; give it a read-only user unless you mean it.
  • Filesystem outside the repo — --add-dir is simpler for extra directories; MCP is for things that are not files.

Cost and context

Every tool result an MCP server returns lands in the conversation and is resent on each turn afterwards. A server that returns 5,000 rows is a context bomb. Prefer tools with limits, ask for summaries, and /compact after a heavy query. Servers run locally or against the vendor; they do not go through the model endpoint, so ANTHROPIC_BASE_URL=https://aiprimetech.io is unaffected — only the tokens the results consume are billed.

Frequently asked questions

How do I add an MCP server to Claude Code?

`claude mcp add <name> -- <command>` for a local server, or `claude mcp add --transport http <name> <url>` for a remote one; add `--scope project` to share it via .mcp.json.

How do I connect PostHog to Claude Code?

Add PostHog's remote MCP server with `claude mcp add --transport http posthog <url> --header "Authorization: Bearer <api key>"`, using the URL from PostHog's MCP docs, then ask about events, flags or errors in a session.

Does MCP work through a gateway?

Yes. MCP servers run locally or against the vendor and are independent of the model endpoint; only the tokens their results consume are billed through the gateway.

Run Claude Code on the gateway

Same models, two environment variables, credits at 7.69231× face value — or a flat-rate unlimited plan.

Get an API key See unlimited plans

AI Prime Tech is an independent API gateway and is not affiliated with, endorsed by, or sponsored by Anthropic. “Claude” and “Claude Code” are trademarks of Anthropic. Claude Code features described here follow Anthropic’s public documentation at the time of writing and change frequently; prices and model lists on this page are read from this gateway’s live settings.

More Claude Code guides

Claude Code: the complete guideHow to install Claude CodeClaude Code CLI documentation: commands and flagsClaude Code pricing and limits, explainedThe Claude Code SDK, now the Claude Agent SDKClaude Code skills and pluginsClaude Code in GitHub: the App, the Action and @claudeDoes Claude Code have a web interface? Web, desktop and IDE explainedWhich model Claude Code uses, and how to change itClaude Code errors and how to fix themIs Claude Code open source?Claude Code tutorial: your first real sessionClaude for students: Claude Code, the API and what education actually gets youHow to use Claude Code for QA automationClaude Code vs Cursor: which one, when — and how to run bothClaude Code vs Codex vs OpenCode: the terminal agents comparedClaude Code subagents: how they work, how to define them, and agent teamsClaude Code hooks: deterministic control over what the agent doesThe Claude Code ecosystem: routers, frameworks, plugins and the lists that track themClaude Code in VS Code: the extension, the terminal route, and the errorsHow to use OpenRouter in Claude Code (and when not to)Claude rate limit error: what "API error: rate limit reached" means and how to fix itClaude Code 怎么用:从安装到日常使用