본문으로 건너뛰기
0%
약 6분 (1,185 단어) ko

Automating Dev Environment Setup: Building a DevContainer MCP Bootstrapper

Categories TechSavvy Container
Tags #DevContainer #MCP #Docker #Claude #AI #Bootstrap #Automation #Development

DevContainer MCP Bootstrapper

Automating Dev Environment Setup: Building a DevContainer MCP Bootstrapper

Hey there! Today I want to talk about this cool project I recently built: the DevContainer MCP Bootstrapper.

It’s a bootstrapper that automatically installs Claude MCP (Model Context Protocol) servers and sets up all your dev tools in one go. There were some pretty interesting stories during the development process that I’d love to share!

🤔 Why Did I Build This?

I had this realization while writing the Claude Code installation guide recently. Setting up development environments in containers every single time was getting ridiculously tedious.

I kept running into these repetitive situations:

  1. Every time I created a new DevContainer: Had to redo Git configs, shell aliases, Vim settings, etc.
  2. Claude MCP setup: Manually installing and configuring Context7 and Supermemory MCP servers each time
  3. Dev tools: Constantly re-setting up Docker aliases and useful functions

All this repetitive work was driving me nuts, so I thought “Let’s just automate everything in one step!”

🚀 What Did I Automate?

Core Features

1. Automatic Claude MCP Server Installation

  • Context7: Latest docs and code example search
  • Supermemory: Personal memory management between AI tools

2. Development Tool Configuration

  • Git global settings and useful aliases
  • Productivity-boosting shell aliases and functions
  • Basic Vim configuration
  • Docker shortcuts and utilities

3. Environment Personalization

  • Zsh with Oh My Zsh setup
  • Custom prompt themes
  • Useful bash functions for daily development

🛠️ How Does It Work?

The magic happens through a simple curl command:

curl -fsSL https://raw.githubusercontent.com/jayleekr/devcontainer-mcp-bootstrapper/main/bootstrap.sh | bash

Here’s what happens under the hood:

Step 1: Environment Detection

# Detect the operating system and package manager
detect_os() {
    if command -v apt-get >/dev/null 2>&1; then
        OS="ubuntu"
        PACKAGE_MANAGER="apt"
    elif command -v yum >/dev/null 2>&1; then
        OS="centos"
        PACKAGE_MANAGER="yum"
    elif command -v apk >/dev/null 2>&1; then
        OS="alpine"
        PACKAGE_MANAGER="apk"
    else
        echo "Unsupported OS"
        exit 1
    fi
}

Step 2: MCP Server Installation

The script automatically downloads and configures the latest MCP servers:

install_mcp_servers() {
    echo "Installing Claude MCP servers..."
    
    # Install Context7
    if ! command -v context7 >/dev/null 2>&1; then
        wget -O /tmp/context7 "${CONTEXT7_URL}"
        chmod +x /tmp/context7
        sudo mv /tmp/context7 /usr/local/bin/
    fi
    
    # Install Supermemory
    npm install -g @supermemory/mcp-server
}

Step 3: Development Environment Setup

setup_dev_environment() {
    # Git configuration
    git config --global alias.st status
    git config --global alias.co checkout
    git config --global alias.br branch
    git config --global alias.ci commit
    
    # Useful shell functions
    cat >> ~/.bashrc << 'EOF'
# Docker shortcuts
alias dps='docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"'
alias dimg='docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"'
alias dclean='docker system prune -f'

# Quick directory navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ll='ls -la'
EOF
}

🎯 Cool Features

Smart Configuration Detection

The bootstrapper is pretty smart about not overwriting existing configurations:

# Only set up Git config if not already configured
if [ -z "$(git config --global user.name)" ]; then
    echo "Setting up Git configuration..."
    read -p "Enter your Git username: " git_username
    read -p "Enter your Git email: " git_email
    git config --global user.name "$git_username"
    git config --global user.email "$git_email"
else
    echo "Git already configured, skipping..."
fi

Modular Installation

You can pick and choose what to install:

./bootstrap.sh --mcp-only          # Only install MCP servers
./bootstrap.sh --dev-tools-only    # Only set up dev tools
./bootstrap.sh --full              # Everything (default)

Error Handling and Rollback

If something goes wrong, the script can clean up after itself:

cleanup_on_error() {
    echo "Installation failed, cleaning up..."
    # Remove partially installed components
    rm -f /usr/local/bin/context7
    npm uninstall -g @supermemory/mcp-server
    echo "Cleanup completed"
}

📝 Lessons Learned

1. Cross-Platform Compatibility is Tricky

Different container images use different package managers and have different default configurations. I had to make the script adaptive:

install_package() {
    local package=$1
    case $PACKAGE_MANAGER in
        "apt")
            sudo apt-get install -y "$package"
            ;;
        "yum")
            sudo yum install -y "$package"
            ;;
        "apk")
            sudo apk add "$package"
            ;;
    esac
}

2. User Experience Matters

Initially, the script was completely silent during installation. I learned that users want to see what’s happening:

show_progress() {
    local current=$1
    local total=$2
    local desc=$3
    echo "[$current/$total] $desc"
}

3. Configuration Backup is Essential

Always backup existing configurations before modifying:

backup_config() {
    local config_file=$1
    if [ -f "$config_file" ]; then
        cp "$config_file" "${config_file}.backup.$(date +%Y%m%d-%H%M%S)"
        echo "Backed up $config_file"
    fi
}

🚀 What’s Next?

I’m planning to add more features:

  1. IDE Integration: Automatic VS Code extensions and settings
  2. Language-Specific Tools: Go, Python, Node.js development environments
  3. Team Configurations: Shared team settings and tools
  4. Cloud Integration: Automatic cloud CLI setup (AWS, GCP, Azure)

💡 Pro Tips

If you’re building similar automation tools:

  1. Make it idempotent: Running the script multiple times should be safe
  2. Provide good feedback: Users want to know what’s happening
  3. Handle failures gracefully: Always have a cleanup strategy
  4. Test on multiple environments: What works on Ubuntu might not work on Alpine

🎉 Try It Out!

If you’re tired of manually setting up dev environments like I was, give it a shot:

curl -fsSL https://raw.githubusercontent.com/jayleekr/devcontainer-mcp-bootstrapper/main/bootstrap.sh | bash

The whole thing takes about 2-3 minutes and you’ll have a fully configured development environment ready to go!

Life’s too short to manually configure the same dev environment over and over again! 🚀

Share this article

Found this helpful? Share it with your network

Join the Discussion

Share your thoughts and connect with other readers

댓글

GitHub 계정으로 로그인하여 댓글을 남겨보세요. 건설적인 의견과 질문을 환영합니다!

댓글을 불러오는 중...