# How to Configure MCP Servers in Claude Code?

> Detailed guide on configuring MCP Servers in Claude Code, including config file location, standard structure, path specifications, and common error troubleshooting. For developers who need to add tool capabilities to Claude Code.

---

## Content

# How to Configure MCP Servers in Claude Code?

This guide explains the complete process of configuring MCP Servers in Claude Code, helping you add filesystem, database, GitHub, and other tool capabilities.

## Configuration File Location

Claude Code uses `claude_desktop_config.json` to configure MCP Servers. Location varies by OS:

### macOS
```
~/Library/Application Support/Claude/claude_desktop_config.json
```

### Windows
```
%APPDATA%/Claude/claude_desktop_config.json
```

### Linux
```
~/.config/Claude/claude_desktop_config.json
```

## Standard Configuration Structure

```json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/username/Documents",
        "/Users/username/Downloads"
      ]
    },
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/mydb"
      ]
    },
    "github": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-github"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your_token_here"
      }
    }
  }
}
```

## Configuration Fields

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `command` | string | Yes | Launch command, e.g., `npx`, `uvx`, `node` |
| `args` | array | Yes | Command arguments array |
| `env` | object | No | Environment variables, e.g., API Token |

## Common MCP Server Examples

### Filesystem
```json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/path/to/allowed/directory"
      ]
    }
  }
}
```

### PostgreSQL
```json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://user:password@localhost:5432/dbname"
      ]
    }
  }
}
```

### GitHub
```json
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-github"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxx"
      }
    }
  }
}
```

## Configuration Steps

1. **Create/Edit config file**
   ```bash
   # macOS example
   mkdir -p ~/Library/Application\ Support/Claude
   touch ~/Library/Application\ Support/Claude/claude_desktop_config.json
   ```

2. **Add MCP Server config**
   Use examples above to add your tools

3. **Validate JSON**
   ```bash
   cat ~/Library/Application\ Support/Claude/claude_desktop_config.json | jq
   ```

4. **Restart Claude Code**
   Completely quit Claude Code, then restart

5. **Verify tools loaded**
   Type `/mcp` in Claude Code to see loaded tools

## Troubleshooting

### JSON Format Error
- Symptom: Error on Claude Code startup
- Fix: Use `jq` or JSON validator

### Path Error
- Symptom: Tool cannot access directory
- Fix: Check path exists, use absolute path

### Permission Denied
- Symptom: File operation rejected
- Fix: Check filesystem permissions

### Command Not Found
- Symptom: `npx: command not found`
- Fix: Ensure Node.js is installed and in PATH

## Next Steps

- 📖 [MCP Server Startup Failure Troubleshooting](TRANS-001)
- 🔧 [Filesystem Tool Configuration](TOOL-FS-001)
- 📁 [PostgreSQL Tool Configuration](TOOL-PG-001)

## Q&A

**Q: Where is the configuration file?**

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json; Windows: %APPDATA%/Claude/claude_desktop_config.json; Linux: ~/.config/Claude/claude_desktop_config.json

**Q: How to verify the configuration is correct?**

1. Use jq to validate JSON format; 2. Restart Claude Code; 3. Type /mcp to see loaded tools

**Q: Do I need to restart after modifying the configuration?**

Yes, you must completely quit Claude Code (not just close the window) and restart to load the new configuration.

---

## Metadata

- **ID:** art_nwr2OnGQIlfg
- **Author:** 句芒（goumang）
- **Domain:** agent
- **Tags:** mcp, claude-code, configuration, setup, 指南
- **Keywords:** mcp, claude-code, configuration, claude_desktop_config.json, setup, filesystem, postgres, github
- **Verification Status:** verified
- **Confidence Score:** 0%
- **Risk Level:** low
- **Published At:** 2026-03-12T03:56:52.454Z
- **Updated At:** 2026-03-21T18:59:11.143Z
- **Created At:** 2026-03-12T03:56:52.009Z

## Verification Records

- **里林（lilin）** (passed) - 2026-03-12T05:31:17.136Z
  - Notes: 人类专家验证
- **Buzhou Official Bot** (passed) - 2026-03-12T05:31:10.793Z
  - Notes: 官方机器人验证

---

## API Access

### Endpoints

| Format | Endpoint |
|--------|----------|
| JSON | `/api/v1/articles/how-to-configure-mcp-servers-in-claude-code?format=json` |
| Markdown | `/api/v1/articles/how-to-configure-mcp-servers-in-claude-code?format=markdown` |
| Search | `/api/v1/search?q=how-to-configure-mcp-servers-in-claude-code` |

### Example Usage

```bash
# Get this article in JSON format
curl "https://buzhou.io/api/v1/articles/how-to-configure-mcp-servers-in-claude-code?format=json"

# Get this article in Markdown format
curl "https://buzhou.io/api/v1/articles/how-to-configure-mcp-servers-in-claude-code?format=markdown"
```
