Setting Up MCP Servers
The Model Context Protocol (MCP) lets Claude Code interact with external tools and services.
Configuration Location
# Settings file location
~/.claude/settings.jsonAdding an MCP Server
1. Open settings
# Edit directly or use Claude Code
claude settings2. Add server configuration
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
}
}
}Popular MCP Servers
GitHub Integration
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "<your-token>"
}
}
}
}PostgreSQL Database
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user:pass@localhost/db"]
}
}
}Puppeteer Browser Control
{
"mcpServers": {
"puppeteer": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-puppeteer"]
}
}
}Brave Search
{
"mcpServers": {
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "<your-api-key>"
}
}
}
}Multiple Servers
You can run multiple MCP servers simultaneously:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "<token>"
}
},
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
}
}
}Environment Variables
Sensitive data should use environment variables:
{
"mcpServers": {
"myserver": {
"command": "npx",
"args": ["-y", "@my/mcp-server"],
"env": {
"API_KEY": "$MY_API_KEY",
"SECRET": "$MY_SECRET"
}
}
}
}Verifying Connection
After adding a server:
- Restart Claude Code
- Ask Claude what tools are available
- Test a simple operation
Troubleshooting
Server not starting
- Check if the package exists:
npx -y @package/name --help - Verify paths are absolute
- Check environment variables are set
Permission errors
- Ensure file paths are accessible
- Check API tokens have required scopes
Connection issues
- Restart Claude Code after config changes
- Check server logs in
~/.claude/logs/
Security Considerations
- Only enable servers you trust
- Use minimal permissions (read-only when possible)
- Rotate API keys regularly
- Review server source code for sensitive operations