Reference guide for adding and managing MCP (Model Context Protocol) servers in Claude Code CLI and Claude Desktop.
- What is MCP?
- Claude Code CLI
- Claude Desktop
- Common Patterns
- Real-World Examples
- Troubleshooting
- Tips
The Model Context Protocol is an open standard that lets AI assistants connect to external tools and data sources. MCP servers expose "tools" that Claude can call — things like reading databases, calling APIs, managing files, etc.
MCP servers communicate over one of three transports:
- stdio — Claude spawns the server as a subprocess and communicates over stdin/stdout (most common for local servers)
- SSE — Server-Sent Events over HTTP
- HTTP — Streamable HTTP transport
claude mcp add <server-name> [options] -- <command> [args...]The -- separates Claude's options from the server command. Everything after -- is the command used to start the MCP server.
# stdio (default) — runs a local process
claude mcp add my-server -- node /path/to/server.js
# HTTP/SSE — connects to a remote URL
claude mcp add my-server --transport http https://example.com/mcp
# SSE (legacy)
claude mcp add my-server --transport sse https://example.com/sse| Flag | Scope | Config File | Description |
|---|---|---|---|
-s user |
User (global) | ~/.claude.json |
Available in all projects |
-s project |
Project | .mcp.json (project root) |
Available only in this project, can be shared via git |
# Global — available everywhere
claude mcp add my-server -s user -- node server.js
# Project-only — lives in .mcp.json, can be committed
claude mcp add my-server -s project -- node server.jsPass environment variables with -e:
claude mcp add my-server \
-e API_KEY=sk-abc123 \
-e DATABASE_URL=postgres://localhost/db \
-- node server.js# List all configured servers and their health
claude mcp list
# Remove a server
claude mcp remove <server-name> -s user # remove from user scope
claude mcp remove <server-name> -s project # remove from project scope
# Reconnect servers (in an active session)
/mcp| OS | Path |
|---|---|
| macOS | ~/Library/Application Support/Claude/claude_desktop_config.json |
| Windows | %APPDATA%\Claude\claude_desktop_config.json |
{
"mcpServers": {
"server-name": {
"command": "node",
"args": ["/path/to/server.js", "--flag"],
"env": {
"API_KEY": "your-key",
"OTHER_VAR": "value"
}
}
}
}After editing, restart Claude Desktop to pick up changes.
For published MCP servers on npm:
# Claude Code CLI
claude mcp add my-server -- npx -y some-mcp-package
# Claude Desktop
{
"command": "npx",
"args": ["-y", "some-mcp-package"]
}The -y flag auto-confirms the npx install prompt.
For a server you've cloned and built locally:
# Claude Code CLI
claude mcp add my-server -- node /path/to/build/index.js
# Claude Desktop
{
"command": "node",
"args": ["/path/to/build/index.js"]
}# Claude Code CLI
claude mcp add my-server -- python /path/to/server.py
# Using uvx (Python package runner, like npx for Python)
claude mcp add my-server -- uvx some-mcp-package
# Claude Desktop
{
"command": "python",
"args": ["/path/to/server.py"]
}# Claude Code CLI
claude mcp add my-server -- docker run -i --rm \
-e API_KEY=value \
some-image:latest
# Claude Desktop
{
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "API_KEY=value",
"some-image:latest"
]
}
-i(interactive) is required for stdio transport so Docker keeps stdin open.--rmcleans up the container after it exits.
# Claude Code CLI
claude mcp add my-server --transport http https://example.com/mcp
# With auth header
claude mcp add my-server --transport http https://example.com/mcp \
--header "Authorization:Bearer your-token"For Claude Desktop, use mcp-remote to bridge remote servers:
{
"command": "npx",
"args": [
"mcp-remote",
"https://example.com/sse",
"--header",
"Authorization:${AUTH_HEADER}"
],
"env": {
"AUTH_HEADER": "Bearer your-token"
}
}Personal finance tool integration:
# Claude Code CLI
claude mcp add actual-budget \
-s user \
-e ACTUAL_SERVER_URL=https://your-actual-server.com \
-e ACTUAL_PASSWORD=your-password \
-e ACTUAL_BUDGET_SYNC_ID=your-budget-id \
-e DOTENV_CONFIG_QUIET=true \
-- node /path/to/actual-mcp/build/index.js --enable-write// Claude Desktop
{
"mcpServers": {
"actual-budget": {
"command": "node",
"args": ["/path/to/actual-mcp/build/index.js", "--enable-write"],
"env": {
"ACTUAL_SERVER_URL": "https://your-actual-server.com",
"ACTUAL_PASSWORD": "your-password",
"ACTUAL_BUDGET_SYNC_ID": "your-budget-id",
"DOTENV_CONFIG_QUIET": "true"
}
}
}
}
DOTENV_CONFIG_QUIET=trueis needed because dotenv v17+ prints to stdout, which corrupts the stdio MCP transport.
--enable-writeenables write tools (create/update/delete transactions, categories, etc.).
Project management integration (remote HTTP):
# Claude Code CLI
claude mcp add linear --transport http https://mcp.linear.app/mcpLinear handles auth via OAuth in the browser when you first connect.
Browser automation:
# Claude Code CLI
claude mcp add playwright -- npx @anthropic-ai/mcp-server-playwright@latest// Claude Desktop
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@anthropic-ai/mcp-server-playwright@latest"]
}
}
}Notion workspace integration (remote HTTP):
# Claude Code CLI
claude mcp add notion --transport http https://mcp.notion.com/mcpGive Claude access to specific directories:
# Claude Code CLI
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem /path/to/allowed/dir// Claude Desktop
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/you/Documents",
"/Users/you/Projects"
]
}
}
}The server is printing non-JSON output to stdout, corrupting the stdio transport. Common causes:
- dotenv v17+ prints a log line to stdout. Fix: set
DOTENV_CONFIG_QUIET=truein env vars. - console.log() in server code. MCP servers must only write protocol messages to stdout. Use
console.error()for logging.
- Check the server can run standalone:
node /path/to/server.js --test-resources(if supported) - Verify env vars are correct
- Check for version mismatches (e.g., API library older than the server it connects to)
For Actual Budget specifically: your @actual-app/api npm package version is older than your Actual Budget server. Upgrade the package:
npm install @actual-app/api@latest
npm run build- Restart the Claude Code session or Claude Desktop
- Some servers need flags to enable tools (e.g.,
--enable-writefor actual-mcp) - Check
claude mcp listto verify connection status
- Ensure the server binary/script is executable
- For Docker, ensure Docker Desktop is running
- For npx, ensure npm/node is on your PATH
- Use
claude mcp listregularly to check server health. - Use
-s projectand commit.mcp.jsonto share MCP config with your team (but keep secrets in env vars or a separate.env). - Use
DOTENV_CONFIG_QUIET=trueany time a server uses dotenv v17+. - Test servers locally first before adding them to Claude. Run the server command directly and check for errors on stderr.
- Keep MCP server packages updated to avoid version mismatches with the services they connect to.
- Use
/mcpin Claude Code to reconnect servers without restarting the session.
Last updated: February 2026