03 - Environment Setup

Module
PostgreSQL
Progress
30%

Environment Setup

🎯 What This Lab Covers

This hands-on lab guides you through setting up a complete development environment for building MCP servers with PostgreSQL integration.

You'll configure all necessary tools, deploy Azure resources, and validate your setup before proceeding with implementation.

Overview

A proper development environment is crucial for successful MCP server development. This lab provides step-by-step instructions for setting up Docker, Azure services, development tools, and validating that everything works correctly together.

By the end of this lab, you'll have a fully functional development environment ready for building the Zava Retail MCP server.

Learning Objectives

By the end of this lab, you will be able to:

  • Install and configure all required development tools
  • Deploy Azure resources needed for the MCP server
  • Set up Docker containers for PostgreSQL and the MCP server
  • Validate your environment setup with test connections
  • Troubleshoot common setup issues and configuration problems
  • Understand the development workflow and file structure
  • πŸ“‹ Prerequisites Check

    Before starting, ensure you have:

    Required Knowledge

  • Basic command line usage (Windows Command Prompt/PowerShell)
  • Understanding of environment variables
  • Familiarity with Git version control
  • Basic Docker concepts (containers, images, volumes)
  • System Requirements

  • Operating System: Windows 10/11, macOS, or Linux
  • RAM: Minimum 8GB (16GB recommended)
  • Storage: At least 10GB free space
  • Network: Internet connection for downloads and Azure deployment
  • Account Requirements

  • Azure Subscription: Free tier is sufficient
  • GitHub Account: For repository access
  • Docker Hub Account: (Optional) For custom image publishing
  • πŸ› οΈ Tool Installation

    1. Install Docker Desktop

    Docker provides the containerized environment for our development setup.

    Windows Installation

    1. Download Docker Desktop:

    ```cmd

    # Visit https://desktop.docker.com/win/stable/Docker%20Desktop%20Installer.exe

    # Or use Windows Package Manager

    winget install Docker.DockerDesktop

    ```

    2. Install and Configure:

    - Run the installer as Administrator

    - Enable WSL 2 integration when prompted

    - Restart your computer when installation completes

    3. Verify Installation:

    ```cmd

    docker --version

    docker-compose --version

    ```

    macOS Installation

    1. Download and Install:

    ```bash

    # Download from https://desktop.docker.com/mac/stable/Docker.dmg

    # Or use Homebrew

    brew install --cask docker

    ```

    2. Start Docker Desktop:

    - Launch Docker Desktop from Applications

    - Complete the initial setup wizard

    3. Verify Installation:

    ```bash

    docker --version

    docker-compose --version

    ```

    Linux Installation

    1. Install Docker Engine:

    ```bash

    # Ubuntu/Debian

    curl -fsSL https://get.docker.com -o get-docker.sh

    sudo sh get-docker.sh

    sudo usermod -aG docker $USER

    # Log out and back in for group changes to take effect

    ```

    2. Install Docker Compose:

    ```bash

    sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

    sudo chmod +x /usr/local/bin/docker-compose

    ```

    2. Install Azure CLI

    The Azure CLI enables Azure resource deployment and management.

    Windows Installation
    
    # Using Windows Package Manager
    
    winget install Microsoft.AzureCLI
    
    
    
    # Or download MSI from: https://aka.ms/installazurecliwindows
    
    
    macOS Installation
    
    # Using Homebrew
    
    brew install azure-cli
    
    
    
    # Or using installer
    
    curl -L https://aka.ms/InstallAzureCli | bash
    
    
    Linux Installation
    
    # Ubuntu/Debian
    
    curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
    
    
    
    # RHEL/CentOS
    
    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    
    sudo dnf install azure-cli
    
    
    Verify and Authenticate
    
    # Check installation
    
    az version
    
    
    
    # Login to Azure
    
    az login
    
    
    
    # Set default subscription (if you have multiple)
    
    az account list --output table
    
    az account set --subscription "Your-Subscription-Name"
    
    

    3. Install Git

    Git is required for cloning the repository and version control.

    Windows
    
    # Using Windows Package Manager
    
    winget install Git.Git
    
    
    
    # Or download from: https://git-scm.com/download/win
    
    
    macOS
    
    # Git is usually pre-installed, but you can update via Homebrew
    
    brew install git
    
    
    Linux
    
    # Ubuntu/Debian
    
    sudo apt update && sudo apt install git
    
    
    
    # RHEL/CentOS
    
    sudo dnf install git
    
    

    4. Install VS Code

    Visual Studio Code provides the integrated development environment with MCP support.

    Installation
    
    # Windows
    
    winget install Microsoft.VisualStudioCode
    
    
    
    # macOS
    
    brew install --cask visual-studio-code
    
    
    
    # Linux (Ubuntu/Debian)
    
    sudo snap install code --classic
    
    
    Required Extensions

    Install these VS Code extensions:

    
    # Install via command line
    
    code --install-extension ms-python.python
    
    code --install-extension ms-vscode.vscode-json
    
    code --install-extension ms-azuretools.vscode-docker
    
    code --install-extension ms-vscode.azure-account
    
    

    Or install through VS Code:

    1. Open VS Code

    2. Go to Extensions (Ctrl+Shift+X)

    3. Install:

    - Python (Microsoft)

    - Docker (Microsoft)

    - Azure Account (Microsoft)

    - JSON (Microsoft)

    5. Install Python

    Python 3.8+ is required for MCP server development.

    Windows
    
    # Using Windows Package Manager
    
    winget install Python.Python.3.11
    
    
    
    # Or download from: https://www.python.org/downloads/
    
    
    macOS
    
    # Using Homebrew
    
    brew install python@3.11
    
    
    Linux
    
    # Ubuntu/Debian
    
    sudo apt update && sudo apt install python3.11 python3.11-pip python3.11-venv
    
    
    
    # RHEL/CentOS
    
    sudo dnf install python3.11 python3.11-pip
    
    
    Verify Installation
    
    python --version  # Should show Python 3.11.x
    
    pip --version      # Should show pip version
    
    

    πŸš€ Project Setup

    1. Clone the Repository

    
    # Clone the main repository
    
    git clone https://github.com/microsoft/MCP-Server-and-PostgreSQL-Sample-Retail.git
    
    
    
    # Navigate to the project directory
    
    cd MCP-Server-and-PostgreSQL-Sample-Retail
    
    
    
    # Verify repository structure
    
    ls -la
    
    

    2. Create Python Virtual Environment

    
    # Create virtual environment
    
    python -m venv mcp-env
    
    
    
    # Activate virtual environment
    
    # Windows
    
    mcp-env\Scripts\activate
    
    
    
    # macOS/Linux
    
    source mcp-env/bin/activate
    
    
    
    # Upgrade pip
    
    python -m pip install --upgrade pip
    
    

    3. Install Python Dependencies

    
    # Install development dependencies
    
    pip install -r requirements.lock.txt
    
    
    
    # Verify key packages
    
    pip list | grep fastmcp
    
    pip list | grep asyncpg
    
    pip list | grep azure
    
    

    ☁️ Azure Resource Deployment

    1. Understand Resource Requirements

    Our MCP server requires these Azure resources:

    | Resource | Purpose | Estimated Cost |

    |--------------|-------------|-------------------|

    | Azure AI Foundry | AI model hosting and management | $10-50/month |

    | OpenAI Deployment | Text embedding model (text-embedding-3-small) | $5-20/month |

    | Application Insights | Monitoring and telemetry | $5-15/month |

    | Resource Group | Resource organization | Free |

    2. Deploy Azure Resources

    Option A: Automated Deployment (Recommended)
    
    # Navigate to infrastructure directory
    
    cd infra
    
    
    
    # Windows - PowerShell
    
    ./deploy.ps1
    
    
    
    # macOS/Linux - Bash
    
    ./deploy.sh
    
    

    The deployment script will:

    1. Create a unique resource group

    2. Deploy Azure AI Foundry resources

    3. Deploy the text-embedding-3-small model

    4. Configure Application Insights

    5. Create a service principal for authentication

    6. Generate .env file with configuration

    Option B: Manual Deployment

    If you prefer manual control or the automated script fails:

    
    # Set variables
    
    RESOURCE_GROUP="rg-zava-mcp-$(date +%s)"
    
    LOCATION="westus2"
    
    AI_PROJECT_NAME="zava-ai-project"
    
    
    
    # Create resource group
    
    az group create --name $RESOURCE_GROUP --location $LOCATION
    
    
    
    # Deploy main template
    
    az deployment group create \
    
      --resource-group $RESOURCE_GROUP \
    
      --template-file main.bicep \
    
      --parameters location=$LOCATION \
    
      --parameters resourcePrefix="zava-mcp"
    
    

    3. Verify Azure Deployment

    
    # Check resource group
    
    az group show --name $RESOURCE_GROUP --output table
    
    
    
    # List deployed resources
    
    az resource list --resource-group $RESOURCE_GROUP --output table
    
    
    
    # Test AI service
    
    az cognitiveservices account show \
    
      --name "your-ai-service-name" \
    
      --resource-group $RESOURCE_GROUP
    
    

    4. Configure Environment Variables

    After deployment, you should have a .env file. Verify it contains:

    
    # .env file contents
    
    PROJECT_ENDPOINT=https://your-project.cognitiveservices.azure.com/
    
    AZURE_OPENAI_ENDPOINT=https://your-openai.openai.azure.com/
    
    EMBEDDING_MODEL_DEPLOYMENT_NAME=text-embedding-3-small
    
    AZURE_CLIENT_ID=your-client-id
    
    AZURE_CLIENT_SECRET=your-client-secret
    
    AZURE_TENANT_ID=your-tenant-id
    
    APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=your-key;...
    
    
    
    # Database configuration (for development)
    
    POSTGRES_HOST=localhost
    
    POSTGRES_PORT=5432
    
    POSTGRES_DB=zava
    
    POSTGRES_USER=postgres
    
    POSTGRES_PASSWORD=your-secure-password
    
    

    🐳 Docker Environment Setup

    1. Understand Docker Composition

    Our development environment uses Docker Compose:

    
    # docker-compose.yml overview
    
    version: '3.8'
    
    services:
    
      postgres:
    
        image: pgvector/pgvector:pg17
    
        environment:
    
          POSTGRES_DB: zava
    
          POSTGRES_USER: postgres
    
          POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-secure_password}
    
        ports:
    
          - "5432:5432"
    
        volumes:
    
          - ./data:/backup_data:ro
    
          - ./docker-init:/docker-entrypoint-initdb.d:ro
    
        
    
      mcp_server:
    
        build: .
    
        depends_on:
    
          postgres:
    
            condition: service_healthy
    
        ports:
    
          - "8000:8000"
    
        env_file:
    
          - .env
    
    

    2. Start the Development Environment

    
    # Ensure you're in the project root directory
    
    cd /path/to/MCP-Server-and-PostgreSQL-Sample-Retail
    
    
    
    # Start the services
    
    docker-compose up -d
    
    
    
    # Check service status
    
    docker-compose ps
    
    
    
    # View logs
    
    docker-compose logs -f
    
    

    3. Verify Database Setup

    
    # Connect to PostgreSQL container
    
    docker-compose exec postgres psql -U postgres -d zava
    
    
    
    # Check database structure
    
    \dt retail.*
    
    
    
    # Verify sample data
    
    SELECT COUNT(*) FROM retail.stores;
    
    SELECT COUNT(*) FROM retail.products;
    
    SELECT COUNT(*) FROM retail.orders;
    
    
    
    # Exit PostgreSQL
    
    \q
    
    

    4. Test MCP Server

    
    # Check MCP server health
    
    curl http://localhost:8000/health
    
    
    
    # Test basic MCP endpoint
    
    curl -X POST http://localhost:8000/mcp \
    
      -H "Content-Type: application/json" \
    
      -H "x-rls-user-id: 00000000-0000-0000-0000-000000000000" \
    
      -d '{"method": "tools/list", "params": {}}'
    
    

    πŸ”§ VS Code Configuration

    1. Configure MCP Integration

    Create VS Code MCP configuration:

    
    // .vscode/mcp.json
    
    {
    
        "servers": {
    
            "zava-sales-analysis-headoffice": {
    
                "url": "http://127.0.0.1:8000/mcp",
    
                "type": "http",
    
                "headers": {"x-rls-user-id": "00000000-0000-0000-0000-000000000000"}
    
            },
    
            "zava-sales-analysis-seattle": {
    
                "url": "http://127.0.0.1:8000/mcp",
    
                "type": "http",
    
                "headers": {"x-rls-user-id": "f47ac10b-58cc-4372-a567-0e02b2c3d479"}
    
            },
    
            "zava-sales-analysis-redmond": {
    
                "url": "http://127.0.0.1:8000/mcp",
    
                "type": "http",
    
                "headers": {"x-rls-user-id": "e7f8a9b0-c1d2-3e4f-5678-90abcdef1234"}
    
            }
    
        },
    
        "inputs": []
    
    }
    
    

    2. Configure Python Environment

    
    // .vscode/settings.json
    
    {
    
        "python.defaultInterpreterPath": "./mcp-env/bin/python",
    
        "python.linting.enabled": true,
    
        "python.linting.pylintEnabled": true,
    
        "python.formatting.provider": "black",
    
        "python.testing.pytestEnabled": true,
    
        "python.testing.pytestArgs": ["tests"],
    
        "files.exclude": {
    
            "**/__pycache__": true,
    
            "**/.pytest_cache": true,
    
            "**/mcp-env": true
    
        }
    
    }
    
    

    3. Test VS Code Integration

    1. Open the project in VS Code:

    ```bash

    code .

    ```

    2. Open AI Chat:

    - Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS)

    - Type "AI Chat" and select "AI Chat: Open Chat"

    3. Test MCP Server Connection:

    - In AI Chat, type #zava and select one of the configured servers

    - Ask: "What tables are available in the database?"

    - You should receive a response listing the retail database tables

    βœ… Environment Validation

    1. Comprehensive System Check

    Run this validation script to verify your setup:

    
    # Create validation script
    
    cat > validate_setup.py << 'EOF'
    
    #!/usr/bin/env python3
    
    """
    
    Environment validation script for MCP Server setup.
    
    """
    
    import asyncio
    
    import os
    
    import sys
    
    import subprocess
    
    import requests
    
    import asyncpg
    
    from azure.identity import DefaultAzureCredential
    
    from azure.ai.projects import AIProjectClient
    
    
    
    async def validate_environment():
    
        """Comprehensive environment validation."""
    
        results = {}
    
        
    
        # Check Python version
    
        python_version = sys.version_info
    
        results['python'] = {
    
            'status': 'pass' if python_version >= (3, 8) else 'fail',
    
            'version': f"{python_version.major}.{python_version.minor}.{python_version.micro}",
    
            'required': '3.8+'
    
        }
    
        
    
        # Check required packages
    
        required_packages = ['fastmcp', 'asyncpg', 'azure-ai-projects']
    
        for package in required_packages:
    
            try:
    
                __import__(package)
    
                results[f'package_{package}'] = {'status': 'pass'}
    
            except ImportError:
    
                results[f'package_{package}'] = {'status': 'fail', 'error': 'Not installed'}
    
        
    
        # Check Docker
    
        try:
    
            result = subprocess.run(['docker', '--version'], capture_output=True, text=True)
    
            results['docker'] = {
    
                'status': 'pass' if result.returncode == 0 else 'fail',
    
                'version': result.stdout.strip() if result.returncode == 0 else 'Not available'
    
            }
    
        except FileNotFoundError:
    
            results['docker'] = {'status': 'fail', 'error': 'Docker not found'}
    
        
    
        # Check Azure CLI
    
        try:
    
            result = subprocess.run(['az', '--version'], capture_output=True, text=True)
    
            results['azure_cli'] = {
    
                'status': 'pass' if result.returncode == 0 else 'fail',
    
                'version': result.stdout.split('\n')[0] if result.returncode == 0 else 'Not available'
    
            }
    
        except FileNotFoundError:
    
            results['azure_cli'] = {'status': 'fail', 'error': 'Azure CLI not found'}
    
        
    
        # Check environment variables
    
        required_env_vars = [
    
            'PROJECT_ENDPOINT',
    
            'AZURE_OPENAI_ENDPOINT',
    
            'EMBEDDING_MODEL_DEPLOYMENT_NAME',
    
            'AZURE_CLIENT_ID',
    
            'AZURE_CLIENT_SECRET',
    
            'AZURE_TENANT_ID'
    
        ]
    
        
    
        for var in required_env_vars:
    
            value = os.getenv(var)
    
            results[f'env_{var}'] = {
    
                'status': 'pass' if value else 'fail',
    
                'value': '***' if value and 'SECRET' in var else value
    
            }
    
        
    
        # Check database connection
    
        try:
    
            conn = await asyncpg.connect(
    
                host=os.getenv('POSTGRES_HOST', 'localhost'),
    
                port=int(os.getenv('POSTGRES_PORT', 5432)),
    
                database=os.getenv('POSTGRES_DB', 'zava'),
    
                user=os.getenv('POSTGRES_USER', 'postgres'),
    
                password=os.getenv('POSTGRES_PASSWORD', 'secure_password')
    
            )
    
            
    
            # Test query
    
            result = await conn.fetchval('SELECT COUNT(*) FROM retail.stores')
    
            await conn.close()
    
            
    
            results['database'] = {
    
                'status': 'pass',
    
                'store_count': result
    
            }
    
        except Exception as e:
    
            results['database'] = {
    
                'status': 'fail',
    
                'error': str(e)
    
            }
    
        
    
        # Check MCP server
    
        try:
    
            response = requests.get('http://localhost:8000/health', timeout=5)
    
            results['mcp_server'] = {
    
                'status': 'pass' if response.status_code == 200 else 'fail',
    
                'response': response.json() if response.status_code == 200 else response.text
    
            }
    
        except Exception as e:
    
            results['mcp_server'] = {
    
                'status': 'fail',
    
                'error': str(e)
    
            }
    
        
    
        # Check Azure AI service
    
        try:
    
            credential = DefaultAzureCredential()
    
            project_client = AIProjectClient(
    
                endpoint=os.getenv('PROJECT_ENDPOINT'),
    
                credential=credential
    
            )
    
            
    
            # This will fail if credentials are invalid
    
            results['azure_ai'] = {'status': 'pass'}
    
            
    
        except Exception as e:
    
            results['azure_ai'] = {
    
                'status': 'fail',
    
                'error': str(e)
    
            }
    
        
    
        return results
    
    
    
    def print_results(results):
    
        """Print formatted validation results."""
    
        print("πŸ” Environment Validation Results\n")
    
        print("=" * 50)
    
        
    
        passed = 0
    
        failed = 0
    
        
    
        for component, result in results.items():
    
            status = result.get('status', 'unknown')
    
            if status == 'pass':
    
                print(f"βœ… {component}: PASS")
    
                passed += 1
    
            else:
    
                print(f"❌ {component}: FAIL")
    
                if 'error' in result:
    
                    print(f"   Error: {result['error']}")
    
                failed += 1
    
        
    
        print("\n" + "=" * 50)
    
        print(f"Summary: {passed} passed, {failed} failed")
    
        
    
        if failed > 0:
    
            print("\n❗ Please fix the failed components before proceeding.")
    
            return False
    
        else:
    
            print("\nπŸŽ‰ All validations passed! Your environment is ready.")
    
            return True
    
    
    
    if __name__ == "__main__":
    
        asyncio.run(main())
    
    
    
    async def main():
    
        results = await validate_environment()
    
        success = print_results(results)
    
        sys.exit(0 if success else 1)
    
    
    
    EOF
    
    
    
    # Run validation
    
    python validate_setup.py
    
    

    2. Manual Validation Checklist

    βœ… Basic Tools

  • [ ] Docker version 20.10+ installed and running
  • [ ] Azure CLI 2.40+ installed and authenticated
  • [ ] Python 3.8+ with pip installed
  • [ ] Git 2.30+ installed
  • [ ] VS Code with required extensions
  • βœ… Azure Resources

  • [ ] Resource group created successfully
  • [ ] AI Foundry project deployed
  • [ ] OpenAI text-embedding-3-small model deployed
  • [ ] Application Insights configured
  • [ ] Service principal created with proper permissions
  • βœ… Environment Configuration

  • [ ] .env file created with all required variables
  • [ ] Azure credentials working (test with az account show)
  • [ ] PostgreSQL container running and accessible
  • [ ] Sample data loaded in database
  • βœ… VS Code Integration

  • [ ] .vscode/mcp.json configured
  • [ ] Python interpreter set to virtual environment
  • [ ] MCP servers appear in AI Chat
  • [ ] Can execute test queries through AI Chat
  • πŸ› οΈ Troubleshooting Common Issues

    Docker Issues

    Problem: Docker containers won't start

    
    # Check Docker service status
    
    docker info
    
    
    
    # Check available resources
    
    docker system df
    
    
    
    # Clean up if needed
    
    docker system prune -f
    
    
    
    # Restart Docker Desktop (Windows/macOS)
    
    # Or restart Docker service (Linux)
    
    sudo systemctl restart docker
    
    

    Problem: PostgreSQL connection fails

    
    # Check container logs
    
    docker-compose logs postgres
    
    
    
    # Verify container is healthy
    
    docker-compose ps
    
    
    
    # Test direct connection
    
    docker-compose exec postgres psql -U postgres -d zava -c "SELECT 1;"
    
    

    Azure Deployment Issues

    Problem: Azure deployment fails

    
    # Check Azure CLI authentication
    
    az account show
    
    
    
    # Verify subscription permissions
    
    az role assignment list --assignee $(az account show --query user.name -o tsv)
    
    
    
    # Check resource provider registration
    
    az provider register --namespace Microsoft.CognitiveServices
    
    az provider register --namespace Microsoft.Insights
    
    

    Problem: AI service authentication fails

    
    # Test service principal
    
    az login --service-principal \
    
      --username $AZURE_CLIENT_ID \
    
      --password $AZURE_CLIENT_SECRET \
    
      --tenant $AZURE_TENANT_ID
    
    
    
    # Verify AI service deployment
    
    az cognitiveservices account list --query "[].{Name:name,Kind:kind,Location:location}"
    
    

    Python Environment Issues

    Problem: Package installation fails

    
    # Upgrade pip and setuptools
    
    python -m pip install --upgrade pip setuptools wheel
    
    
    
    # Clear pip cache
    
    pip cache purge
    
    
    
    # Install packages one by one to identify issues
    
    pip install fastmcp
    
    pip install asyncpg
    
    pip install azure-ai-projects
    
    

    Problem: VS Code can't find Python interpreter

    
    # Show Python interpreter paths
    
    which python  # macOS/Linux
    
    where python  # Windows
    
    
    
    # Activate virtual environment first
    
    source mcp-env/bin/activate  # macOS/Linux
    
    mcp-env\Scripts\activate     # Windows
    
    
    
    # Then open VS Code
    
    code .
    
    

    🎯 Key Takeaways

    After completing this lab, you should have:

    βœ… Complete Development Environment: All tools installed and configured

    βœ… Azure Resources Deployed: AI services and supporting infrastructure

    βœ… Docker Environment Running: PostgreSQL and MCP server containers

    βœ… VS Code Integration: MCP servers configured and accessible

    βœ… Validated Setup: All components tested and working together

    βœ… Troubleshooting Knowledge: Common issues and solutions

    πŸš€ What's Next

    With your environment ready, continue to Lab 04: Database Design and Schema to:

  • Explore the retail database schema in detail
  • Understand multi-tenant data modeling
  • Learn about Row Level Security implementation
  • Work with sample retail data
  • πŸ“š Additional Resources

    Development Tools

  • Docker Documentation - Complete Docker reference
  • Azure CLI Reference - Azure CLI commands
  • VS Code Documentation - Editor configuration and extensions
  • Azure Services

  • Azure AI Foundry Documentation - AI service configuration
  • Azure OpenAI Service - AI model deployment
  • Application Insights - Monitoring setup
  • Python Development

  • Python Virtual Environments - Environment management
  • AsyncIO Documentation - Async programming patterns
  • FastAPI Documentation - Web framework patterns
  • ---

    Next: Environment ready? Continue with Lab 04: Database Design and Schema

    ν™˜κ²½ μ„€μ •

    🎯 이 μ‹€μŠ΅μ—μ„œ λ‹€λ£¨λŠ” λ‚΄μš©

    이 μ‹€μŠ΅μ€ PostgreSQL 톡합을 톡해 MCP μ„œλ²„λ₯Ό κ΅¬μΆ•ν•˜κΈ° μœ„ν•œ μ™„μ „ν•œ 개발 ν™˜κ²½μ„ μ„€μ •ν•˜λŠ” 과정을 μ•ˆλ‚΄ν•©λ‹ˆλ‹€. ν•„μš”ν•œ λͺ¨λ“  도ꡬλ₯Ό κ΅¬μ„±ν•˜κ³ , Azure λ¦¬μ†ŒμŠ€λ₯Ό λ°°ν¬ν•˜λ©°, κ΅¬ν˜„μ„ μ§„ν–‰ν•˜κΈ° 전에 섀정을 κ²€μ¦ν•©λ‹ˆλ‹€.

    κ°œμš”

    μ μ ˆν•œ 개발 ν™˜κ²½μ€ MCP μ„œλ²„ 개발의 성곡에 ν•„μˆ˜μ μž…λ‹ˆλ‹€. 이 μ‹€μŠ΅μ€ Docker, Azure μ„œλΉ„μŠ€, 개발 도ꡬλ₯Ό μ„€μ •ν•˜κ³  λͺ¨λ“  것이 μ˜¬λ°”λ₯΄κ²Œ μž‘λ™ν•˜λŠ”μ§€ ν™•μΈν•˜λŠ” 단계별 지침을 μ œκ³΅ν•©λ‹ˆλ‹€.

    이 μ‹€μŠ΅μ„ μ™„λ£Œν•˜λ©΄ Zava Retail MCP μ„œλ²„λ₯Ό ꡬ좕할 μ€€λΉ„κ°€ 된 μ™„μ „ν•œ 개발 ν™˜κ²½μ„ κ°–μΆ”κ²Œ λ©λ‹ˆλ‹€.

    ν•™μŠ΅ λͺ©ν‘œ

    이 μ‹€μŠ΅μ„ μ™„λ£Œν•˜λ©΄ λ‹€μŒμ„ μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

  • ν•„μš”ν•œ 개발 도ꡬ μ„€μΉ˜ 및 ꡬ성
  • MCP μ„œλ²„μ— ν•„μš”ν•œ Azure λ¦¬μ†ŒμŠ€ 배포
  • PostgreSQL 및 MCP μ„œλ²„λ₯Ό μœ„ν•œ Docker μ»¨ν…Œμ΄λ„ˆ μ„€μ •
  • ν…ŒμŠ€νŠΈ 연결을 톡해 ν™˜κ²½ μ„€μ • 검증
  • 일반적인 μ„€μ • 문제 및 ꡬ성 문제 ν•΄κ²°
  • 개발 μ›Œν¬ν”Œλ‘œ 및 파일 ꡬ쑰 이해
  • πŸ“‹ 사전 μš”κ΅¬ 사항 확인

    μ‹œμž‘ν•˜κΈ° 전에 λ‹€μŒμ„ ν™•μΈν•˜μ„Έμš”:

    ν•„μš”ν•œ 지식

  • κΈ°λ³Έ λͺ…령쀄 μ‚¬μš©λ²• (Windows Command Prompt/PowerShell)
  • ν™˜κ²½ λ³€μˆ˜μ— λŒ€ν•œ 이해
  • Git 버전 관리에 λŒ€ν•œ κΈ°λ³Έ 지식
  • Docker의 κΈ°λ³Έ κ°œλ… (μ»¨ν…Œμ΄λ„ˆ, 이미지, λ³Όλ₯¨)
  • μ‹œμŠ€ν…œ μš”κ΅¬ 사항

  • 운영 체제: Windows 10/11, macOS λ˜λŠ” Linux
  • RAM: μ΅œμ†Œ 8GB (ꢌμž₯ 16GB)
  • μ €μž₯ 곡간: μ΅œμ†Œ 10GB의 μ—¬μœ  곡간
  • λ„€νŠΈμ›Œν¬: λ‹€μš΄λ‘œλ“œ 및 Azure 배포λ₯Ό μœ„ν•œ 인터넷 μ—°κ²°
  • 계정 μš”κ΅¬ 사항

  • Azure ꡬ독: 무료 κ³„μΈ΅μœΌλ‘œ μΆ©λΆ„
  • GitHub 계정: 리포지토리 μ•‘μ„ΈμŠ€λ₯Ό μœ„ν•΄
  • Docker Hub 계정: (선택 사항) μ‚¬μš©μž μ •μ˜ 이미지 κ²Œμ‹œλ₯Ό μœ„ν•΄
  • πŸ› οΈ 도ꡬ μ„€μΉ˜

    1. Docker Desktop μ„€μΉ˜

    DockerλŠ” 개발 ν™˜κ²½μ„ μ»¨ν…Œμ΄λ„ˆν™”λœ ν˜•νƒœλ‘œ μ œκ³΅ν•©λ‹ˆλ‹€.

    Windows μ„€μΉ˜

    1. Docker Desktop λ‹€μš΄λ‘œλ“œ:

    ```cmd

    # Visit https://desktop.docker.com/win/stable/Docker%20Desktop%20Installer.exe

    # Or use Windows Package Manager

    winget install Docker.DockerDesktop

    ```

    2. μ„€μΉ˜ 및 ꡬ성:

    - κ΄€λ¦¬μž κΆŒν•œμœΌλ‘œ μ„€μΉ˜ ν”„λ‘œκ·Έλž¨ μ‹€ν–‰

    - WSL 2 톡합 ν™œμ„±ν™”

    - μ„€μΉ˜ μ™„λ£Œ ν›„ 컴퓨터 μž¬μ‹œμž‘

    3. μ„€μΉ˜ 확인:

    ```cmd

    docker --version

    docker-compose --version

    ```

    macOS μ„€μΉ˜

    1. λ‹€μš΄λ‘œλ“œ 및 μ„€μΉ˜:

    ```bash

    # Download from https://desktop.docker.com/mac/stable/Docker.dmg

    # Or use Homebrew

    brew install --cask docker

    ```

    2. Docker Desktop μ‹œμž‘:

    - μ‘μš© ν”„λ‘œκ·Έλž¨μ—μ„œ Docker Desktop μ‹€ν–‰

    - 초기 μ„€μ • λ§ˆλ²•μ‚¬ μ™„λ£Œ

    3. μ„€μΉ˜ 확인:

    ```bash

    docker --version

    docker-compose --version

    ```

    Linux μ„€μΉ˜

    1. Docker Engine μ„€μΉ˜:

    ```bash

    # Ubuntu/Debian

    curl -fsSL https://get.docker.com -o get-docker.sh

    sudo sh get-docker.sh

    sudo usermod -aG docker $USER

    # Log out and back in for group changes to take effect

    ```

    2. Docker Compose μ„€μΉ˜:

    ```bash

    sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

    sudo chmod +x /usr/local/bin/docker-compose

    ```

    2. Azure CLI μ„€μΉ˜

    Azure CLIλŠ” Azure λ¦¬μ†ŒμŠ€ 배포 및 관리λ₯Ό κ°€λŠ₯ν•˜κ²Œ ν•©λ‹ˆλ‹€.

    Windows μ„€μΉ˜
    
    # Using Windows Package Manager
    
    winget install Microsoft.AzureCLI
    
    
    
    # Or download MSI from: https://aka.ms/installazurecliwindows
    
    
    macOS μ„€μΉ˜
    
    # Using Homebrew
    
    brew install azure-cli
    
    
    
    # Or using installer
    
    curl -L https://aka.ms/InstallAzureCli | bash
    
    
    Linux μ„€μΉ˜
    
    # Ubuntu/Debian
    
    curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
    
    
    
    # RHEL/CentOS
    
    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    
    sudo dnf install azure-cli
    
    
    μ„€μΉ˜ 확인 및 인증
    
    # Check installation
    
    az version
    
    
    
    # Login to Azure
    
    az login
    
    
    
    # Set default subscription (if you have multiple)
    
    az account list --output table
    
    az account set --subscription "Your-Subscription-Name"
    
    

    3. Git μ„€μΉ˜

    Git은 리포지토리 클둠 및 버전 관리λ₯Ό μœ„ν•΄ ν•„μš”ν•©λ‹ˆλ‹€.

    Windows
    
    # Using Windows Package Manager
    
    winget install Git.Git
    
    
    
    # Or download from: https://git-scm.com/download/win
    
    
    macOS
    
    # Git is usually pre-installed, but you can update via Homebrew
    
    brew install git
    
    
    Linux
    
    # Ubuntu/Debian
    
    sudo apt update && sudo apt install git
    
    
    
    # RHEL/CentOS
    
    sudo dnf install git
    
    

    4. VS Code μ„€μΉ˜

    Visual Studio CodeλŠ” MCP 지원을 μœ„ν•œ 톡합 개발 ν™˜κ²½μ„ μ œκ³΅ν•©λ‹ˆλ‹€.

    μ„€μΉ˜
    
    # Windows
    
    winget install Microsoft.VisualStudioCode
    
    
    
    # macOS
    
    brew install --cask visual-studio-code
    
    
    
    # Linux (Ubuntu/Debian)
    
    sudo snap install code --classic
    
    
    ν•„μˆ˜ ν™•μž₯ ν”„λ‘œκ·Έλž¨

    λ‹€μŒ VS Code ν™•μž₯ ν”„λ‘œκ·Έλž¨μ„ μ„€μΉ˜ν•˜μ„Έμš”:

    
    # Install via command line
    
    code --install-extension ms-python.python
    
    code --install-extension ms-vscode.vscode-json
    
    code --install-extension ms-azuretools.vscode-docker
    
    code --install-extension ms-vscode.azure-account
    
    

    λ˜λŠ” VS Codeλ₯Ό 톡해 μ„€μΉ˜:

    1. VS Code μ—΄κΈ°

    2. ν™•μž₯ ν”„λ‘œκ·Έλž¨μœΌλ‘œ 이동 (Ctrl+Shift+X)

    3. μ„€μΉ˜:

    - Python (Microsoft)

    - Docker (Microsoft)

    - Azure Account (Microsoft)

    - JSON (Microsoft)

    5. Python μ„€μΉ˜

    Python 3.8+λŠ” MCP μ„œλ²„ κ°œλ°œμ— ν•„μš”ν•©λ‹ˆλ‹€.

    Windows
    
    # Using Windows Package Manager
    
    winget install Python.Python.3.11
    
    
    
    # Or download from: https://www.python.org/downloads/
    
    
    macOS
    
    # Using Homebrew
    
    brew install python@3.11
    
    
    Linux
    
    # Ubuntu/Debian
    
    sudo apt update && sudo apt install python3.11 python3.11-pip python3.11-venv
    
    
    
    # RHEL/CentOS
    
    sudo dnf install python3.11 python3.11-pip
    
    
    μ„€μΉ˜ 확인
    
    python --version  # Should show Python 3.11.x
    
    pip --version      # Should show pip version
    
    

    πŸš€ ν”„λ‘œμ νŠΈ μ„€μ •

    1. 리포지토리 클둠

    
    # Clone the main repository
    
    git clone https://github.com/microsoft/MCP-Server-and-PostgreSQL-Sample-Retail.git
    
    
    
    # Navigate to the project directory
    
    cd MCP-Server-and-PostgreSQL-Sample-Retail
    
    
    
    # Verify repository structure
    
    ls -la
    
    

    2. Python 가상 ν™˜κ²½ 생성

    
    # Create virtual environment
    
    python -m venv mcp-env
    
    
    
    # Activate virtual environment
    
    # Windows
    
    mcp-env\Scripts\activate
    
    
    
    # macOS/Linux
    
    source mcp-env/bin/activate
    
    
    
    # Upgrade pip
    
    python -m pip install --upgrade pip
    
    

    3. Python 쒅속성 μ„€μΉ˜

    
    # Install development dependencies
    
    pip install -r requirements.lock.txt
    
    
    
    # Verify key packages
    
    pip list | grep fastmcp
    
    pip list | grep asyncpg
    
    pip list | grep azure
    
    

    ☁️ Azure λ¦¬μ†ŒμŠ€ 배포

    1. λ¦¬μ†ŒμŠ€ μš”κ΅¬ 사항 이해

    MCP μ„œλ²„μ—λŠ” λ‹€μŒ Azure λ¦¬μ†ŒμŠ€κ°€ ν•„μš”ν•©λ‹ˆλ‹€:

    | λ¦¬μ†ŒμŠ€ | λͺ©μ  | μ˜ˆμƒ λΉ„μš© |

    |------------|----------|---------------|

    | Azure AI Foundry | AI λͺ¨λΈ ν˜ΈμŠ€νŒ… 및 관리 | μ›” $10-50 |

    | OpenAI 배포 | ν…μŠ€νŠΈ μž„λ² λ”© λͺ¨λΈ (text-embedding-3-small) | μ›” $5-20 |

    | Application Insights | λͺ¨λ‹ˆν„°λ§ 및 원격 뢄석 | μ›” $5-15 |

    | Resource Group | λ¦¬μ†ŒμŠ€ 쑰직 | 무료 |

    2. Azure λ¦¬μ†ŒμŠ€ 배포

    μ˜΅μ…˜ A: μžλ™ 배포 (ꢌμž₯)
    
    # Navigate to infrastructure directory
    
    cd infra
    
    
    
    # Windows - PowerShell
    
    ./deploy.ps1
    
    
    
    # macOS/Linux - Bash
    
    ./deploy.sh
    
    

    배포 μŠ€ν¬λ¦½νŠΈλŠ” λ‹€μŒμ„ μˆ˜ν–‰ν•©λ‹ˆλ‹€:

    1. κ³ μœ ν•œ λ¦¬μ†ŒμŠ€ κ·Έλ£Ή 생성

    2. Azure AI Foundry λ¦¬μ†ŒμŠ€ 배포

    3. text-embedding-3-small λͺ¨λΈ 배포

    4. Application Insights ꡬ성

    5. 인증을 μœ„ν•œ μ„œλΉ„μŠ€ 주체 생성

    6. κ΅¬μ„±λœ .env 파일 생성

    μ˜΅μ…˜ B: μˆ˜λ™ 배포

    μžλ™ μŠ€ν¬λ¦½νŠΈκ°€ μ‹€νŒ¨ν•˜κ±°λ‚˜ μˆ˜λ™ μ œμ–΄λ₯Ό μ„ ν˜Έν•˜λŠ” 경우:

    
    # Set variables
    
    RESOURCE_GROUP="rg-zava-mcp-$(date +%s)"
    
    LOCATION="westus2"
    
    AI_PROJECT_NAME="zava-ai-project"
    
    
    
    # Create resource group
    
    az group create --name $RESOURCE_GROUP --location $LOCATION
    
    
    
    # Deploy main template
    
    az deployment group create \
    
      --resource-group $RESOURCE_GROUP \
    
      --template-file main.bicep \
    
      --parameters location=$LOCATION \
    
      --parameters resourcePrefix="zava-mcp"
    
    

    3. Azure 배포 확인

    
    # Check resource group
    
    az group show --name $RESOURCE_GROUP --output table
    
    
    
    # List deployed resources
    
    az resource list --resource-group $RESOURCE_GROUP --output table
    
    
    
    # Test AI service
    
    az cognitiveservices account show \
    
      --name "your-ai-service-name" \
    
      --resource-group $RESOURCE_GROUP
    
    

    4. ν™˜κ²½ λ³€μˆ˜ ꡬ성

    배포 ν›„ .env 파일이 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. λ‹€μŒμ„ ν¬ν•¨ν•˜λŠ”μ§€ ν™•μΈν•˜μ„Έμš”:

    
    # .env file contents
    
    PROJECT_ENDPOINT=https://your-project.cognitiveservices.azure.com/
    
    AZURE_OPENAI_ENDPOINT=https://your-openai.openai.azure.com/
    
    EMBEDDING_MODEL_DEPLOYMENT_NAME=text-embedding-3-small
    
    AZURE_CLIENT_ID=your-client-id
    
    AZURE_CLIENT_SECRET=your-client-secret
    
    AZURE_TENANT_ID=your-tenant-id
    
    APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=your-key;...
    
    
    
    # Database configuration (for development)
    
    POSTGRES_HOST=localhost
    
    POSTGRES_PORT=5432
    
    POSTGRES_DB=zava
    
    POSTGRES_USER=postgres
    
    POSTGRES_PASSWORD=your-secure-password
    
    

    🐳 Docker ν™˜κ²½ μ„€μ •

    1. Docker ꡬ성 이해

    개발 ν™˜κ²½μ€ Docker Composeλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€:

    
    # docker-compose.yml overview
    
    version: '3.8'
    
    services:
    
      postgres:
    
        image: pgvector/pgvector:pg17
    
        environment:
    
          POSTGRES_DB: zava
    
          POSTGRES_USER: postgres
    
          POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-secure_password}
    
        ports:
    
          - "5432:5432"
    
        volumes:
    
          - ./data:/backup_data:ro
    
          - ./docker-init:/docker-entrypoint-initdb.d:ro
    
        
    
      mcp_server:
    
        build: .
    
        depends_on:
    
          postgres:
    
            condition: service_healthy
    
        ports:
    
          - "8000:8000"
    
        env_file:
    
          - .env
    
    

    2. 개발 ν™˜κ²½ μ‹œμž‘

    
    # Ensure you're in the project root directory
    
    cd /path/to/MCP-Server-and-PostgreSQL-Sample-Retail
    
    
    
    # Start the services
    
    docker-compose up -d
    
    
    
    # Check service status
    
    docker-compose ps
    
    
    
    # View logs
    
    docker-compose logs -f
    
    

    3. λ°μ΄ν„°λ² μ΄μŠ€ μ„€μ • 확인

    
    # Connect to PostgreSQL container
    
    docker-compose exec postgres psql -U postgres -d zava
    
    
    
    # Check database structure
    
    \dt retail.*
    
    
    
    # Verify sample data
    
    SELECT COUNT(*) FROM retail.stores;
    
    SELECT COUNT(*) FROM retail.products;
    
    SELECT COUNT(*) FROM retail.orders;
    
    
    
    # Exit PostgreSQL
    
    \q
    
    

    4. MCP μ„œλ²„ ν…ŒμŠ€νŠΈ

    
    # Check MCP server health
    
    curl http://localhost:8000/health
    
    
    
    # Test basic MCP endpoint
    
    curl -X POST http://localhost:8000/mcp \
    
      -H "Content-Type: application/json" \
    
      -H "x-rls-user-id: 00000000-0000-0000-0000-000000000000" \
    
      -d '{"method": "tools/list", "params": {}}'
    
    

    πŸ”§ VS Code ꡬ성

    1. MCP 톡합 ꡬ성

    VS Code MCP ꡬ성을 μƒμ„±ν•˜μ„Έμš”:

    
    // .vscode/mcp.json
    
    {
    
        "servers": {
    
            "zava-sales-analysis-headoffice": {
    
                "url": "http://127.0.0.1:8000/mcp",
    
                "type": "http",
    
                "headers": {"x-rls-user-id": "00000000-0000-0000-0000-000000000000"}
    
            },
    
            "zava-sales-analysis-seattle": {
    
                "url": "http://127.0.0.1:8000/mcp",
    
                "type": "http",
    
                "headers": {"x-rls-user-id": "f47ac10b-58cc-4372-a567-0e02b2c3d479"}
    
            },
    
            "zava-sales-analysis-redmond": {
    
                "url": "http://127.0.0.1:8000/mcp",
    
                "type": "http",
    
                "headers": {"x-rls-user-id": "e7f8a9b0-c1d2-3e4f-5678-90abcdef1234"}
    
            }
    
        },
    
        "inputs": []
    
    }
    
    

    2. Python ν™˜κ²½ ꡬ성

    
    // .vscode/settings.json
    
    {
    
        "python.defaultInterpreterPath": "./mcp-env/bin/python",
    
        "python.linting.enabled": true,
    
        "python.linting.pylintEnabled": true,
    
        "python.formatting.provider": "black",
    
        "python.testing.pytestEnabled": true,
    
        "python.testing.pytestArgs": ["tests"],
    
        "files.exclude": {
    
            "**/__pycache__": true,
    
            "**/.pytest_cache": true,
    
            "**/mcp-env": true
    
        }
    
    }
    
    

    3. VS Code 톡합 ν…ŒμŠ€νŠΈ

    1. ν”„λ‘œμ νŠΈλ₯Ό VS Codeμ—μ„œ μ—΄κΈ°:

    ```bash

    code .

    ```

    2. AI Chat μ—΄κΈ°:

    - Ctrl+Shift+P (Windows/Linux) λ˜λŠ” Cmd+Shift+P (macOS) λˆ„λ₯΄κΈ°

    - "AI Chat" μž…λ ₯ ν›„ "AI Chat: Open Chat" 선택

    3. MCP μ„œλ²„ μ—°κ²° ν…ŒμŠ€νŠΈ:

    - AI Chatμ—μ„œ #zava μž…λ ₯ ν›„ κ΅¬μ„±λœ μ„œλ²„ 쀑 ν•˜λ‚˜ 선택

    - 질문: "λ°μ΄ν„°λ² μ΄μŠ€μ— μ–΄λ–€ ν…Œμ΄λΈ”μ΄ μžˆλ‚˜μš”?"

    - μ†Œλ§€ λ°μ΄ν„°λ² μ΄μŠ€ ν…Œμ΄λΈ” λͺ©λ‘μ„ ν¬ν•¨ν•œ 응닡을 λ°›μ•„μ•Ό ν•©λ‹ˆλ‹€

    βœ… ν™˜κ²½ 검증

    1. μ’…ν•© μ‹œμŠ€ν…œ 점검

    섀정을 ν™•μΈν•˜κΈ° μœ„ν•΄ 이 검증 슀크립트λ₯Ό μ‹€ν–‰ν•˜μ„Έμš”:

    
    # Create validation script
    
    cat > validate_setup.py << 'EOF'
    
    #!/usr/bin/env python3
    
    """
    
    Environment validation script for MCP Server setup.
    
    """
    
    import asyncio
    
    import os
    
    import sys
    
    import subprocess
    
    import requests
    
    import asyncpg
    
    from azure.identity import DefaultAzureCredential
    
    from azure.ai.projects import AIProjectClient
    
    
    
    async def validate_environment():
    
        """Comprehensive environment validation."""
    
        results = {}
    
        
    
        # Check Python version
    
        python_version = sys.version_info
    
        results['python'] = {
    
            'status': 'pass' if python_version >= (3, 8) else 'fail',
    
            'version': f"{python_version.major}.{python_version.minor}.{python_version.micro}",
    
            'required': '3.8+'
    
        }
    
        
    
        # Check required packages
    
        required_packages = ['fastmcp', 'asyncpg', 'azure-ai-projects']
    
        for package in required_packages:
    
            try:
    
                __import__(package)
    
                results[f'package_{package}'] = {'status': 'pass'}
    
            except ImportError:
    
                results[f'package_{package}'] = {'status': 'fail', 'error': 'Not installed'}
    
        
    
        # Check Docker
    
        try:
    
            result = subprocess.run(['docker', '--version'], capture_output=True, text=True)
    
            results['docker'] = {
    
                'status': 'pass' if result.returncode == 0 else 'fail',
    
                'version': result.stdout.strip() if result.returncode == 0 else 'Not available'
    
            }
    
        except FileNotFoundError:
    
            results['docker'] = {'status': 'fail', 'error': 'Docker not found'}
    
        
    
        # Check Azure CLI
    
        try:
    
            result = subprocess.run(['az', '--version'], capture_output=True, text=True)
    
            results['azure_cli'] = {
    
                'status': 'pass' if result.returncode == 0 else 'fail',
    
                'version': result.stdout.split('\n')[0] if result.returncode == 0 else 'Not available'
    
            }
    
        except FileNotFoundError:
    
            results['azure_cli'] = {'status': 'fail', 'error': 'Azure CLI not found'}
    
        
    
        # Check environment variables
    
        required_env_vars = [
    
            'PROJECT_ENDPOINT',
    
            'AZURE_OPENAI_ENDPOINT',
    
            'EMBEDDING_MODEL_DEPLOYMENT_NAME',
    
            'AZURE_CLIENT_ID',
    
            'AZURE_CLIENT_SECRET',
    
            'AZURE_TENANT_ID'
    
        ]
    
        
    
        for var in required_env_vars:
    
            value = os.getenv(var)
    
            results[f'env_{var}'] = {
    
                'status': 'pass' if value else 'fail',
    
                'value': '***' if value and 'SECRET' in var else value
    
            }
    
        
    
        # Check database connection
    
        try:
    
            conn = await asyncpg.connect(
    
                host=os.getenv('POSTGRES_HOST', 'localhost'),
    
                port=int(os.getenv('POSTGRES_PORT', 5432)),
    
                database=os.getenv('POSTGRES_DB', 'zava'),
    
                user=os.getenv('POSTGRES_USER', 'postgres'),
    
                password=os.getenv('POSTGRES_PASSWORD', 'secure_password')
    
            )
    
            
    
            # Test query
    
            result = await conn.fetchval('SELECT COUNT(*) FROM retail.stores')
    
            await conn.close()
    
            
    
            results['database'] = {
    
                'status': 'pass',
    
                'store_count': result
    
            }
    
        except Exception as e:
    
            results['database'] = {
    
                'status': 'fail',
    
                'error': str(e)
    
            }
    
        
    
        # Check MCP server
    
        try:
    
            response = requests.get('http://localhost:8000/health', timeout=5)
    
            results['mcp_server'] = {
    
                'status': 'pass' if response.status_code == 200 else 'fail',
    
                'response': response.json() if response.status_code == 200 else response.text
    
            }
    
        except Exception as e:
    
            results['mcp_server'] = {
    
                'status': 'fail',
    
                'error': str(e)
    
            }
    
        
    
        # Check Azure AI service
    
        try:
    
            credential = DefaultAzureCredential()
    
            project_client = AIProjectClient(
    
                endpoint=os.getenv('PROJECT_ENDPOINT'),
    
                credential=credential
    
            )
    
            
    
            # This will fail if credentials are invalid
    
            results['azure_ai'] = {'status': 'pass'}
    
            
    
        except Exception as e:
    
            results['azure_ai'] = {
    
                'status': 'fail',
    
                'error': str(e)
    
            }
    
        
    
        return results
    
    
    
    def print_results(results):
    
        """Print formatted validation results."""
    
        print("πŸ” Environment Validation Results\n")
    
        print("=" * 50)
    
        
    
        passed = 0
    
        failed = 0
    
        
    
        for component, result in results.items():
    
            status = result.get('status', 'unknown')
    
            if status == 'pass':
    
                print(f"βœ… {component}: PASS")
    
                passed += 1
    
            else:
    
                print(f"❌ {component}: FAIL")
    
                if 'error' in result:
    
                    print(f"   Error: {result['error']}")
    
                failed += 1
    
        
    
        print("\n" + "=" * 50)
    
        print(f"Summary: {passed} passed, {failed} failed")
    
        
    
        if failed > 0:
    
            print("\n❗ Please fix the failed components before proceeding.")
    
            return False
    
        else:
    
            print("\nπŸŽ‰ All validations passed! Your environment is ready.")
    
            return True
    
    
    
    if __name__ == "__main__":
    
        asyncio.run(main())
    
    
    
    async def main():
    
        results = await validate_environment()
    
        success = print_results(results)
    
        sys.exit(0 if success else 1)
    
    
    
    EOF
    
    
    
    # Run validation
    
    python validate_setup.py
    
    

    2. μˆ˜λ™ 검증 체크리슀트

    βœ… κΈ°λ³Έ 도ꡬ

  • [ ] Docker 버전 20.10+ μ„€μΉ˜ 및 μ‹€ν–‰ 쀑
  • [ ] Azure CLI 2.40+ μ„€μΉ˜ 및 인증 μ™„λ£Œ
  • [ ] Python 3.8+ 및 pip μ„€μΉ˜ μ™„λ£Œ
  • [ ] Git 2.30+ μ„€μΉ˜ μ™„λ£Œ
  • [ ] VS Code 및 ν•„μˆ˜ ν™•μž₯ ν”„λ‘œκ·Έλž¨ μ„€μΉ˜ μ™„λ£Œ
  • βœ… Azure λ¦¬μ†ŒμŠ€

  • [ ] λ¦¬μ†ŒμŠ€ κ·Έλ£Ή μ„±κ³΅μ μœΌλ‘œ 생성됨
  • [ ] AI Foundry ν”„λ‘œμ νŠΈ 배포 μ™„λ£Œ
  • [ ] OpenAI text-embedding-3-small λͺ¨λΈ 배포 μ™„λ£Œ
  • [ ] Application Insights ꡬ성 μ™„λ£Œ
  • [ ] μ μ ˆν•œ κΆŒν•œμ„ κ°€μ§„ μ„œλΉ„μŠ€ 주체 생성됨
  • βœ… ν™˜κ²½ ꡬ성

  • [ ] .env 파일 생성 및 λͺ¨λ“  ν•„μˆ˜ λ³€μˆ˜ 포함
  • [ ] Azure 자격 증λͺ… μž‘λ™ (az account show둜 ν…ŒμŠ€νŠΈ)
  • [ ] PostgreSQL μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰ 및 μ ‘κ·Ό κ°€λŠ₯
  • [ ] λ°μ΄ν„°λ² μ΄μŠ€μ— μƒ˜ν”Œ 데이터 λ‘œλ“œ μ™„λ£Œ
  • βœ… VS Code 톡합

  • [ ] .vscode/mcp.json ꡬ성 μ™„λ£Œ
  • [ ] Python 인터프리터λ₯Ό 가상 ν™˜κ²½μœΌλ‘œ μ„€μ •
  • [ ] MCP μ„œλ²„κ°€ AI Chat에 ν‘œμ‹œλ¨
  • [ ] AI Chat을 톡해 ν…ŒμŠ€νŠΈ 쿼리 μ‹€ν–‰ κ°€λŠ₯
  • πŸ› οΈ 일반적인 문제 ν•΄κ²°

    Docker 문제

    문제: Docker μ»¨ν…Œμ΄λ„ˆκ°€ μ‹œμž‘λ˜μ§€ μ•ŠμŒ

    
    # Check Docker service status
    
    docker info
    
    
    
    # Check available resources
    
    docker system df
    
    
    
    # Clean up if needed
    
    docker system prune -f
    
    
    
    # Restart Docker Desktop (Windows/macOS)
    
    # Or restart Docker service (Linux)
    
    sudo systemctl restart docker
    
    

    문제: PostgreSQL μ—°κ²° μ‹€νŒ¨

    
    # Check container logs
    
    docker-compose logs postgres
    
    
    
    # Verify container is healthy
    
    docker-compose ps
    
    
    
    # Test direct connection
    
    docker-compose exec postgres psql -U postgres -d zava -c "SELECT 1;"
    
    

    Azure 배포 문제

    문제: Azure 배포 μ‹€νŒ¨

    
    # Check Azure CLI authentication
    
    az account show
    
    
    
    # Verify subscription permissions
    
    az role assignment list --assignee $(az account show --query user.name -o tsv)
    
    
    
    # Check resource provider registration
    
    az provider register --namespace Microsoft.CognitiveServices
    
    az provider register --namespace Microsoft.Insights
    
    

    문제: AI μ„œλΉ„μŠ€ 인증 μ‹€νŒ¨

    
    # Test service principal
    
    az login --service-principal \
    
      --username $AZURE_CLIENT_ID \
    
      --password $AZURE_CLIENT_SECRET \
    
      --tenant $AZURE_TENANT_ID
    
    
    
    # Verify AI service deployment
    
    az cognitiveservices account list --query "[].{Name:name,Kind:kind,Location:location}"
    
    

    Python ν™˜κ²½ 문제

    문제: νŒ¨ν‚€μ§€ μ„€μΉ˜ μ‹€νŒ¨

    
    # Upgrade pip and setuptools
    
    python -m pip install --upgrade pip setuptools wheel
    
    
    
    # Clear pip cache
    
    pip cache purge
    
    
    
    # Install packages one by one to identify issues
    
    pip install fastmcp
    
    pip install asyncpg
    
    pip install azure-ai-projects
    
    

    문제: VS Codeμ—μ„œ Python 인터프리터λ₯Ό 찾을 수 μ—†μŒ

    
    # Show Python interpreter paths
    
    which python  # macOS/Linux
    
    where python  # Windows
    
    
    
    # Activate virtual environment first
    
    source mcp-env/bin/activate  # macOS/Linux
    
    mcp-env\Scripts\activate     # Windows
    
    
    
    # Then open VS Code
    
    code .
    
    

    🎯 μ£Όμš” μš”μ 

    이 μ‹€μŠ΅μ„ μ™„λ£Œν•œ ν›„, λ‹€μŒμ„ κ°–μΆ”κ²Œ λ©λ‹ˆλ‹€:

    βœ… μ™„μ „ν•œ 개발 ν™˜κ²½: λͺ¨λ“  도ꡬ μ„€μΉ˜ 및 ꡬ성 μ™„λ£Œ

    βœ… Azure λ¦¬μ†ŒμŠ€ 배포: AI μ„œλΉ„μŠ€ 및 지원 인프라

    βœ… Docker ν™˜κ²½ μ‹€ν–‰: PostgreSQL 및 MCP μ„œλ²„ μ»¨ν…Œμ΄λ„ˆ

    βœ… VS Code 톡합: MCP μ„œλ²„ ꡬ성 및 μ ‘κ·Ό κ°€λŠ₯

    βœ… μ„€μ • 검증 μ™„λ£Œ: λͺ¨λ“  ꡬ성 μš”μ†Œ ν…ŒμŠ€νŠΈ 및 μž‘λ™ 확인

    βœ… 문제 ν•΄κ²° 지식: 일반적인 문제 및 ν•΄κ²° 방법

    πŸš€ λ‹€μŒ 단계

    ν™˜κ²½μ΄ μ€€λΉ„λ˜μ—ˆμœΌλ©΄ Lab 04: λ°μ΄ν„°λ² μ΄μŠ€ 섀계 및 μŠ€ν‚€λ§ˆλ‘œ 계속 μ§„ν–‰ν•˜μ„Έμš”:

  • μ†Œλ§€ λ°μ΄ν„°λ² μ΄μŠ€ μŠ€ν‚€λ§ˆλ₯Ό μžμ„Ένžˆ 탐색
  • λ©€ν‹° ν…Œλ„ŒνŠΈ 데이터 λͺ¨λΈλ§ 이해
  • ν–‰ μˆ˜μ€€ λ³΄μ•ˆ κ΅¬ν˜„ ν•™μŠ΅
  • μƒ˜ν”Œ μ†Œλ§€ 데이터 μž‘μ—…
  • πŸ“š μΆ”κ°€ 자료

    개발 도ꡬ

  • Docker λ¬Έμ„œ - Docker μ°Έμ‘° 자료
  • Azure CLI μ°Έμ‘° - Azure CLI λͺ…λ Ήμ–΄
  • VS Code λ¬Έμ„œ - νŽΈμ§‘κΈ° ꡬ성 및 ν™•μž₯ ν”„λ‘œκ·Έλž¨
  • Azure μ„œλΉ„μŠ€

  • Azure AI Foundry λ¬Έμ„œ - AI μ„œλΉ„μŠ€ ꡬ성
  • Azure OpenAI μ„œλΉ„μŠ€ - AI λͺ¨λΈ 배포
  • Application Insights - λͺ¨λ‹ˆν„°λ§ μ„€μ •
  • Python 개발

  • Python 가상 ν™˜κ²½ - ν™˜κ²½ 관리
  • AsyncIO λ¬Έμ„œ - 비동기 ν”„λ‘œκ·Έλž˜λ° νŒ¨ν„΄
  • FastAPI λ¬Έμ„œ - μ›Ή ν”„λ ˆμž„μ›Œν¬ νŒ¨ν„΄
  • ---

    λ‹€μŒ: ν™˜κ²½μ΄ μ€€λΉ„λ˜μ—ˆλ‚˜μš”? Lab 04: λ°μ΄ν„°λ² μ΄μŠ€ 섀계 및 μŠ€ν‚€λ§ˆλ‘œ 계속 μ§„ν–‰ν•˜μ„Έμš”.

    ---

    λ©΄μ±… μ‘°ν•­:

    이 λ¬Έμ„œλŠ” AI λ²ˆμ—­ μ„œλΉ„μŠ€ Co-op Translatorλ₯Ό μ‚¬μš©ν•˜μ—¬ λ²ˆμ—­λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

    정확성을 μœ„ν•΄ μ΅œμ„ μ„ λ‹€ν•˜κ³  μžˆμœΌλ‚˜, μžλ™ λ²ˆμ—­μ—λŠ” 였λ₯˜λ‚˜ 뢀정확성이 포함될 수 μžˆμŠ΅λ‹ˆλ‹€.

    원본 λ¬Έμ„œμ˜ 원어 버전을 μ‹ λ’°ν•  수 μžˆλŠ” κΆŒμœ„ μžˆλŠ” 자료둜 κ°„μ£Όν•΄μ•Ό ν•©λ‹ˆλ‹€.

    μ€‘μš”ν•œ μ •λ³΄μ˜ 경우, 전문적인 인간 λ²ˆμ—­μ„ ꢌμž₯ν•©λ‹ˆλ‹€.

    이 λ²ˆμ—­ μ‚¬μš©μœΌλ‘œ 인해 λ°œμƒν•˜λŠ” μ˜€ν•΄λ‚˜ 잘λͺ»λœ 해석에 λŒ€ν•΄ λ‹Ήμ‚¬λŠ” μ±…μž„μ„ μ§€μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

    MCP Academy — microsoft/mcp-for-beginners