HomeClaude Code › MCP
OverviewInstallCLI referencePricing & limitsAgent SDKSkills & pluginsGitHubWeb, desktop & IDEModelsErrorsOpen source?TutorialFor studentsQA automationvs Cursorvs Codex & OpenCodeSubagentsHooksMCPEcosystem中文指南
Last updated: September 22, 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

{
  "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

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.69× 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 Code for studentsHow 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 怎么用:从安装到日常使用