Complete Claude Code Guide: From Installation to Advanced Usage

Complete Claude Code Guide: From Installation to Advanced Usage

A comprehensive tutorial covering everything you need to know about Claude Code - from basic installation and setup to advanced features like MCP integration, automation, and security best practices.

Lesson 2 2025-07-03 08:01

MCP Integration: Supercharge Claude Code with External Tools

MCP Integration: Supercharge Claude Code with External Tools

The Model Context Protocol (MCP) is one of Claude Code's most powerful features, allowing you to connect external tools, services, and data sources directly to your AI assistant. This guide will show you how to set up, configure, and use MCP to dramatically expand Claude Code's capabilities.

What is MCP?

MCP (Model Context Protocol) is Anthropic's protocol for connecting AI assistants to external tools and data sources. Think of it as a bridge that allows Claude to interact with:

  • Development tools: Git, GitHub, Docker, and more
  • Databases: PostgreSQL, MySQL, SQLite, MongoDB
  • APIs: REST services, web scraping, search engines
  • Cloud services: AWS, Google Cloud, Azure
  • File systems: Local and remote file access
  • Custom tools: Your own applications and scripts

MCP Architecture

Claude Code ←→ MCP Protocol ←→ MCP Servers ←→ External Services

MCP servers act as intermediaries that translate between Claude's requests and external tools. Each server provides specific capabilities through a standardized interface.

Setting Up MCP

Basic MCP Commands

# Interactive MCP configuration
claude mcp

# List configured servers
claude mcp list

# Add a new server
claude mcp add <name> <command>

# Remove a server
claude mcp remove <name>

# Check MCP status
claude mcp status

# Restart all servers
claude mcp restart --all

MCP Configuration Files

MCP servers are configured in JSON files:

Global Configuration: ~/.claude.json

{
  "mcpServers": {
    "git": {
      "command": "git-mcp-server",
      "args": [],
      "env": {}
    },
    "postgres": {
      "command": "postgres-mcp-server",
      "args": ["--host", "localhost", "--port", "5432"],
      "env": {
        "POSTGRES_USER": "developer",
        "POSTGRES_PASSWORD": "dev_password",
        "POSTGRES_DB": "myapp_development"
      }
    }
  }
}

Project Configuration: .mcp.json (in project root)

{
  "mcpServers": {
    "project-db": {
      "command": "postgres-mcp-server",
      "args": ["--host", "localhost"],
      "env": {
        "POSTGRES_URL": "postgresql://user:pass@localhost:5432/project_db"
      }
    }
  }
}

Development Tools

1. Git Integration

# Install Git MCP server
npm install -g @modelcontextprotocol/server-git

# Add to configuration
claude mcp add git "@modelcontextprotocol/server-git"

Usage examples:

# In Claude Code
claude "Show me the git status and recent commits"
claude "Create a new branch called 'feature/user-auth'"
claude "Review the diff before committing"

2. GitHub Integration

# Install GitHub MCP server
npm install -g @modelcontextprotocol/server-github

# Add to configuration with API token
claude mcp add github "@modelcontextprotocol/server-github"

Configuration with API key:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "your-github-token-here"
      }
    }
  }
}

Database Integration

1. PostgreSQL

# Install PostgreSQL MCP server
npm install -g @modelcontextprotocol/server-postgres

# Add to configuration
claude mcp add postgres "@modelcontextprotocol/server-postgres"

Usage examples:

claude "Show me the database schema"
claude "Query users table for recent signups"
claude "Optimize this slow query"

2. SQLite

# Install SQLite MCP server
npm install -g @modelcontextprotocol/server-sqlite

# Add to configuration
claude mcp add sqlite "@modelcontextprotocol/server-sqlite /path/to/database.db"

Web and API Tools

1. Web Scraping with Puppeteer

# Install Puppeteer MCP server
npm install -g @modelcontextprotocol/server-puppeteer

# Add to configuration
claude mcp add puppeteer "@modelcontextprotocol/server-puppeteer"

2. HTTP Client

# Install Fetch MCP server
npm install -g @kazuph/mcp-fetch

# Add to configuration
claude mcp add fetch "@kazuph/mcp-fetch"

Search and Information

# Install Brave Search MCP server
npm install -g @modelcontextprotocol/server-brave-search

# Add to configuration
claude mcp add brave-search "@modelcontextprotocol/server-brave-search"

Configuration with API key:

{
  "mcpServers": {
    "brave-search": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-brave-search"],
      "env": {
        "BRAVE_API_KEY": "your-brave-api-key"
      }
    }
  }
}

File System Access

1. Filesystem Server

# Install Filesystem MCP server
npm install -g @modelcontextprotocol/server-filesystem

# Add to configuration with allowed directories
claude mcp add filesystem "@modelcontextprotocol/server-filesystem /path/to/allowed/directory"

Advanced MCP Configuration

Server Types

Most MCP servers use the stdio type, but you can configure different connection types:

{
  "mcpServers": {
    "my-server": {
      "type": "stdio",           // Most common
      "command": "my-server",
      "args": ["--option", "value"],
      "env": {"VAR": "value"}
    }
  }
}

Environment Variables

Use environment variables for sensitive data:

{
  "mcpServers": {
    "database": {
      "command": "postgres-mcp-server",
      "env": {
        "POSTGRES_URL": "${DATABASE_URL}",
        "POSTGRES_SSL": "require"
      }
    }
  }
}

Server Arguments

Pass specific arguments to configure server behavior:

{
  "mcpServers": {
    "git": {
      "command": "git-mcp-server",
      "args": [
        "--repository", "/path/to/repo",
        "--branch", "main",
        "--max-commits", "100"
      ]
    }
  }
}

Working with MCP in Claude Code

Tool Permissions

Control which MCP tools Claude can use:

# Allow specific MCP tools
claude --allowedTools "mcp__git__commit,mcp__git__push"

# Allow all tools from specific server
claude --allowedTools "mcp__postgres__*"

# Combined with built-in tools
claude --allowedTools "Edit,View,mcp__git__*"

Using MCP Tools in Conversations

Once configured, you can use MCP tools naturally in conversation:

# Database queries
claude "Show me all users who signed up this week"

# Git operations
claude "Create a feature branch and commit these changes"

# Web scraping
claude "Scrape the latest news from example.com"

# API calls
claude "Call the /api/users endpoint and analyze the response"

Creating Custom MCP Servers

Basic Server Structure

You can create custom MCP servers for your specific needs:

// my-custom-server.js
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');

const server = new Server({
  name: 'my-custom-server',
  version: '1.0.0',
});

// Add tools
server.setRequestHandler('tools/list', async () => {
  return {
    tools: [
      {
        name: 'my-tool',
        description: 'Description of what this tool does',
        inputSchema: {
          type: 'object',
          properties: {
            input: { type: 'string' }
          }
        }
      }
    ]
  };
});

// Handle tool calls
server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;

  if (name === 'my-tool') {
    // Your custom logic here
    return {
      content: [
        {
          type: 'text',
          text: 'Tool executed successfully'
        }
      ]
    };
  }
});

// Start server
const transport = new StdioServerTransport();
server.connect(transport);

Running Custom Servers

# Make executable
chmod +x my-custom-server.js

# Add to MCP configuration
claude mcp add my-server "node /path/to/my-custom-server.js"

Troubleshooting MCP

Common Issues

  1. Server won't start

    # Check server installation
    npx -y @modelcontextprotocol/server-git --version
    
    # Check configuration
    claude mcp list
    

  2. Permission errors

    # Check MCP permissions
    claude config get allowedTools
    
    # Enable MCP tools
    claude --allowedTools "mcp__*"
    

  3. Environment variables not loaded

    # Check environment
    echo $GITHUB_TOKEN
    
    # Restart Claude Code after setting variables
    

Debug Mode

Enable MCP debugging for troubleshooting:

# Enable debug mode
claude --mcp-debug

# Check MCP logs
claude mcp status

Testing MCP Servers

Test servers manually before adding to Claude Code:

# Test server directly
npx -y @modelcontextprotocol/server-git

# Test with specific arguments
npx -y @modelcontextprotocol/server-postgres --host localhost --port 5432

MCP Best Practices

Security

  1. Use environment variables for secrets

    {
      "env": {
        "API_KEY": "${MY_API_KEY}"
      }
    }
    

  2. Limit tool permissions

    claude --allowedTools "mcp__git__status,mcp__git__log"
    

  3. Validate server sources

  4. Only install MCP servers from trusted sources
  5. Review server code before installation
  6. Use specific versions rather than latest

Performance

  1. Optimize server configuration
  2. Use appropriate connection limits
  3. Configure timeouts
  4. Limit result sizes

  5. Monitor resource usage

  6. Check server memory usage
  7. Monitor API rate limits
  8. Clean up unused servers

Maintenance

  1. Regular updates

    # Update MCP servers
    npm update -g @modelcontextprotocol/server-git
    
    # Restart servers after updates
    claude mcp restart --all
    

  2. Configuration management

  3. Version control your MCP configurations
  4. Document server purposes and dependencies
  5. Test configurations in development first

Example Workflows

Development Workflow

# Morning standup
claude "Show me yesterday's commits and today's planned tasks"

# Code review
claude "Review the latest pull request for security issues"

# Database migration
claude "Check if the latest migration ran successfully"

# Deployment
claude "Deploy the current branch to staging and run tests"

Data Analysis Workflow

# Database analysis
claude "Analyze user signup trends for the last month"

# API monitoring
claude "Check API response times and error rates"

# Log analysis
claude "Search logs for errors in the authentication service"

Conclusion

MCP integration transforms Claude Code from a simple AI assistant into a powerful orchestration tool that can interact with your entire development environment. By connecting databases, APIs, version control, and custom tools, you can create sophisticated workflows that automate complex tasks and provide deep insights into your projects.

Start with basic integrations like Git and gradually add more specialized servers as your needs grow. The key is to experiment and find the combination of tools that best supports your specific workflow and requirements.

Next Steps

  1. Choose your first MCP server - Start with Git or a database you use regularly
  2. Practice with basic commands - Get comfortable with MCP tool permissions
  3. Explore advanced servers - Try web scraping, APIs, or custom tools
  4. Create custom servers - Build tools for your specific needs
  5. Optimize configurations - Fine-tune settings for performance and security

With MCP, Claude Code becomes not just an AI assistant, but a central hub for your entire development ecosystem.