Installing and configuring an MCP
Complete guide to installing, configuring, and debugging an MCP in Claude Code. The .mcp.json file, the claude mcp add command, and troubleshooting common issues.
The MCP configuration file
MCPs are configured in a JSON file that tells Claude Code which MCP servers to launch and how to connect them. There are two levels of configuration: global for your personal tools, and per-project for each repository's tech stack.
Global configuration
The ~/.claude/settings.json file contains the MCPs available across all your projects. This is where you put generic MCPs (Gmail, Slack, Calendar) and personal tokens.
Per-project configuration
The .mcp.json file at the root of your project contains MCPs specific to that project. This is where you put development-related MCPs (Context7, Sentry, project database).
.mcp.json file structure
{"mcpServers": {"mcp-name": {"command": "npx","args": ["-y", "@package/mcp-server"],"env": {"API_KEY": "your-key-here"}}}}
Each entry in mcpServers defines an MCP with:
command: the command to launch the MCP server (npx,uvx,docker, or a path to a binary)args: the arguments passed to the command (the npm package, configuration options)env(optional): required environment variables (tokens, API keys)
Installing an MCP: three methods
Method 1: via the claude mcp add command (recommended)
The simplest way to install an MCP. Claude Code handles everything.
# General syntaxclaude mcp add <name> -- <command> <args...># Example: add Context7claude mcp add context7 -- npx -y @upstash/context7-mcp# Example: add GitHub with a tokenclaude mcp add github -- npx -y @modelcontextprotocol/server-github# Example: add an MCP with environment variablesclaude mcp add slack -e SLACK_BOT_TOKEN=xoxb-your-token -- npx -y @modelcontextprotocol/server-slack
Method 2: manually edit the JSON file
For full control, edit the configuration file directly.
{"mcpServers": {"context7": {"command": "npx","args": ["-y", "@upstash/context7-mcp"]},"github": {"command": "npx","args": ["-y", "@modelcontextprotocol/server-github"],"env": {"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_your_token"}}}}
Method 3: via Docker (for complex MCPs)
Some MCPs require specific dependencies. Docker isolates everything cleanly.
{"mcpServers": {"postgres": {"command": "docker","args": ["run", "-i", "--rm","-e", "DATABASE_URL","mcp/postgres"],"env": {"DATABASE_URL": "postgresql://user:pass@host:5432/dbname"}}}}
Configuration in Claude Code
Check installed MCPs
After adding an MCP, restart Claude Code and verify it's connected.
# List all configured MCPsclaude mcp list# Expected output:# context7: connected# Tools: query-docs, resolve-library-id# github: connected# Tools: list_issues, create_pull_request, search_code, ...# Remove an MCPclaude mcp remove <name># View details of an MCPclaude mcp get <name>
Configuration scope
# Add an MCP at the project level (default)claude mcp add context7 -- npx -y @upstash/context7-mcp# Add an MCP at the global level (all projects)claude mcp add context7 --scope global -- npx -y @upstash/context7-mcp# Add an MCP at the user level (for this user)claude mcp add context7 --scope user -- npx -y @upstash/context7-mcp
Best practice: separate global and project
Put universal MCPs (Gmail, Slack, Calendar) in global and project-specific MCPs (Context7, Sentry, database) in project. That way, each project only has access to the tools it needs.
Debug and troubleshooting
The MCP won't connect
Check that the command is accessible
# Check that npx is installedwhich npx# Check that the MCP package existsnpx -y @upstash/context7-mcp --help# If you're using uvx (Python)which uvx
Check the MCP logs
# View MCP connection logsclaude mcp logs# View logs for a specific MCPclaude mcp logs context7
Validate JSON syntax
An extra comma or a missing quote can break everything. Use a JSON validator.
# Validate your .mcp.json filecat .mcp.json | python3 -m json.tool# Or with Node.jsnode -e "console.log(JSON.parse(require('fs').readFileSync('.mcp.json','utf8')))"
Test the MCP manually
You can launch the MCP server directly to see if it starts correctly.
# Launch the MCP server directlynpx -y @upstash/context7-mcp# If the server starts and waits for stdin input, it's working# Ctrl+C to quit
Common errors and solutions
| Error | Likely cause | Solution |
|---|---|---|
command not found: npx | Node.js not installed | Install Node.js 18+ |
ENOENT | MCP package doesn't exist | Check the package name |
ECONNREFUSED | Invalid or expired token | Regenerate the token |
timeout | MCP server too slow to start | Increase timeout or use Docker |
permission denied | Insufficient permissions | Check token/file permissions |
Token security
Never commit your tokens to a Git repository. Use the global configuration (~/.claude/settings.json) for sensitive information, or system environment variables.
Full example: configuring three MCPs
Here's a realistic configuration example with three MCPs for a web development project.
{"mcpServers": {"context7": {"command": "npx","args": ["-y", "@upstash/context7-mcp"]},"playwright": {"command": "npx","args": ["-y", "@playwright/mcp"]},"github": {"command": "npx","args": ["-y", "@modelcontextprotocol/server-github"],"env": {"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..."}}}}
With this configuration, you can ask Claude Code:
"Look up the Next.js 14 docs, create a 404 error page following best practices, test it in the browser, and create a pull request."
Claude Code will automatically chain Context7 (documentation), file editing (page creation), Playwright (visual testing), and GitHub (pull request).
Next steps
Is your first MCP configured? Now discover the best MCPs by category.
- Understanding MCPs: How the MCP protocol works, explained
- Top productivity MCPs: Gmail, Slack, Calendar, Figma, Lighthouse
- Top development MCPs: Context7, GitHub, Sentry, databases
- Top design & UI MCPs: Playwright, Chrome DevTools, 21st.dev Magic