πŸ€– AI Tools
Β· 4 min read
Last updated on

How to Use MCP with Claude Code β€” Complete Setup Guide


Claude Code has native MCP support. Add MCP servers to give Claude access to databases, APIs, and tools directly from your terminal.

Prerequisites

Before setting up MCP with Claude Code, you need:

  • Claude Code installed (npm install -g @anthropic-ai/claude-code)
  • Node.js 18+ (for running MCP servers via npx)
  • API keys for any services you want to connect (GitHub, databases, etc.)

Adding servers

CLI command (easiest)

claude mcp add github npx @modelcontextprotocol/server-github
claude mcp add my-db npx @modelcontextprotocol/server-postgres \
  -e POSTGRES_URL="postgresql://user:pass@localhost/mydb"
claude mcp list
claude mcp remove github

Project-level config with .mcp.json

For project-specific MCP servers that your whole team can share, create a .mcp.json file in your project root:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-filesystem", "./src"]
    },
    "postgres": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-postgres"],
      "env": {
        "POSTGRES_URL": "postgresql://dev:dev@localhost:5432/myapp"
      }
    },
    "github": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}"
      }
    }
  }
}

Claude Code automatically detects .mcp.json when you start it in a directory. Environment variables with ${VAR} syntax are resolved from your shell environment, so you don’t commit secrets.

Global config file

For servers you want available in every project, edit ~/.claude/claude_desktop_config.json:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-filesystem", "/home/user/projects"]
    },
    "github": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-github"],
      "env": { "GITHUB_TOKEN": "ghp_..." }
    }
  }
}
ServerWhat it does
FilesystemRead/write project files
GitHubIssues, PRs, code search
PostgresDatabase queries
Brave SearchWeb search for docs
DockerContainer management
MemoryPersistent knowledge across sessions
PuppeteerBrowser automation and testing
SQLiteLocal database queries

See our full list of 15 recommended servers for more options.

Step-by-step setup example

Here’s a complete workflow for adding GitHub and a database to Claude Code:

# 1. Set your environment variables
export GITHUB_TOKEN="ghp_your_token"
export DATABASE_URL="postgresql://user:pass@localhost:5432/mydb"

# 2. Add the GitHub server
claude mcp add github npx @modelcontextprotocol/server-github \
  -e GITHUB_TOKEN="$GITHUB_TOKEN"

# 3. Add the Postgres server
claude mcp add postgres npx @modelcontextprotocol/server-postgres \
  -e POSTGRES_URL="$DATABASE_URL"

# 4. Verify servers are running
claude mcp list

# 5. Start Claude Code β€” servers are now available
claude

Using tools

Once added, just ask naturally:

> Search GitHub for open issues about authentication
> Query the database for users who signed up this week
> List all files in the src/components directory

Claude shows which tool it’s calling and asks for approval. You can approve individual calls or use /permissions to auto-approve specific tools.

Practical workflows

Database-driven development

With the Postgres MCP server, you can ask Claude to:

  • Inspect your schema and suggest migrations
  • Write queries based on natural language
  • Debug slow queries by examining table structures
  • Generate TypeScript types from your database schema

GitHub-integrated coding

With the GitHub MCP server connected:

  • Ask Claude to review open PRs and suggest fixes
  • Create issues from bugs you find during coding
  • Search the codebase across repos for usage patterns
  • Auto-generate PR descriptions from your changes

For a deeper dive into MCP architecture and building your own servers, see the MCP Complete Developer Guide.

Troubleshooting

Server won’t start

# Check if npx can find the package
npx @modelcontextprotocol/server-github --help

# Clear npx cache if package is outdated
npx clear-npx-cache

# Check Claude Code logs
claude mcp list --verbose

”Tool not found” errors

  • Restart Claude Code after adding servers (/quit then claude)
  • Verify the server is listed in claude mcp list
  • Check that environment variables are set correctly

Server crashes mid-session

MCP servers run as child processes. If one crashes, Claude Code will show an error. Fix the issue and restart:

claude mcp remove broken-server
claude mcp add broken-server npx @modelcontextprotocol/server-name

Permission denied

If Claude keeps asking for approval on every tool call, configure permissions:

/permissions add mcp__github__search_repositories
/permissions add mcp__filesystem__read_file

For more debugging strategies, see our MCP Debugging Guide.

Works with other models too

If you’re using Claude Code with GLM-5.1 or Mistral via custom endpoints, MCP servers work the same β€” they’re model-agnostic.

Security

MCP servers run with your permissions. Use read-only credentials for databases, limit filesystem access to specific directories, and use scoped API tokens. See our MCP Security Checklist.

Key security practices:

  • Never commit .mcp.json files with hardcoded secrets β€” use ${ENV_VAR} syntax
  • Use read-only database users for MCP Postgres connections
  • Scope GitHub tokens to only the repos you need
  • Limit filesystem server access to your project directory, not /

Related: Best MCP Servers Β· How to Use Claude Code Β· MCP Complete Guide Β· MCP Debugging Guide Β· Build MCP Server (TypeScript)