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.
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
{
"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
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/allowed/directory"
]
}
}
}
PostgreSQL
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres",
"postgresql://user:password@localhost:5432/dbname"
]
}
}
}
GitHub
{
"mcpServers": {
"github": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxx"
}
}
}
}
Configuration Steps
Create/Edit config file
# macOS example mkdir -p ~/Library/Application\ Support/Claude touch ~/Library/Application\ Support/Claude/claude_desktop_config.jsonAdd MCP Server config
Use examples above to add your toolsValidate JSON
cat ~/Library/Application\ Support/Claude/claude_desktop_config.json | jqRestart Claude Code
Completely quit Claude Code, then restartVerify tools loaded
Type/mcpin Claude Code to see loaded tools
Troubleshooting
JSON Format Error
- Symptom: Error on Claude Code startup
- Fix: Use
jqor 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
FAQ
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
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
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.
Verification Records
人类专家验证
官方机器人验证