Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell Script Content #1

Open
patruff opened this issue Dec 2, 2024 · 0 comments
Open

PowerShell Script Content #1

patruff opened this issue Dec 2, 2024 · 0 comments

Comments

@patruff
Copy link
Owner

patruff commented Dec 2, 2024

Here's the PowerShell script content that should be saved as setup-claude-mcps.ps1:

# Claude MCP Setup Script

# Package Configuration
# Format: 
# - Packages starting with @ will be installed via npm
# - Other packages will be installed via pip
$PACKAGES_TO_INSTALL = @(
    "@modelcontextprotocol/server-filesystem",
    "@patruff/server-terminator",
    "mcp-server-sqlite"
    # Add new packages below this line
    # "@patruff/server-somenewone",
    # "patruff-mcp-financetool"
)

# API Keys Configuration
# Define all API keys here - they can be passed as parameters or prompted during script execution
$API_KEYS = @{
    GIT_PAT_TOKEN = ""  # GitHub Personal Access Token
    # Add new API keys here
    # OPENAI_API_KEY = ""
    # AZURE_API_KEY = ""
}

# MCP Server Configurations
# Add new MCP configurations here as hashtables
$MCP_CONFIGS = @{
    filesystem = @{
        command = "C:\Program Files\nodejs\node.exe"
        args = @(
            "C:\Users\$env:USERNAME\AppData\Roaming\npm\node_modules\@modelcontextprotocol\server-filesystem\dist\index.js",
            "C:\Users\$env:USERNAME\anthropicFun"
        )
    }
    terminator = @{
        command = "C:\Program Files\nodejs\node.exe"
        args = @(
            "C:\Users\$env:USERNAME\AppData\Roaming\npm\node_modules\@patruff\server-terminator\dist\index.js"
        )
        env = @{
            GITHUB_PERSONAL_ACCESS_TOKEN = "{GIT_PAT_TOKEN}"  # Reference to API key
        }
    }
    sqlite = @{
        command = "uv"
        args = @(
            "--directory",
            "parent_of_servers_repo/servers/src/sqlite",
            "run",
            "mcp-server-sqlite",
            "--db-path",
            "~/test.db"
        )
    }
}

param (
    [Parameter(HelpMessage = "GitHub Personal Access Token")]
    [string]$GIT_PAT_TOKEN = "",
    # Add additional API key parameters here
    [Parameter(HelpMessage = "Skip API key prompts and use empty values")]
    [switch]$skipPrompts = $false
)

# Get current username and paths
$username = $env:USERNAME
$configPath = "C:\Users\$username\AppData\Roaming\Claude"
$configFile = Join-Path $configPath "claude_desktop_config.json"

# Check if Claude desktop directory exists
if (-not (Test-Path $configPath)) {
    Write-Host "Error: Claude desktop directory not found. Please install Claude desktop first." -ForegroundColor Red
    exit 1
}

# Check if config file exists
if (-not (Test-Path $configFile)) {
    Write-Host "Error: Claude desktop config file not found." -ForegroundColor Red
    exit 1
}

# Function to collect API keys
function Get-ApiKeys {
    # First, apply any keys passed as parameters
    foreach ($key in $API_KEYS.Keys) {
        $paramValue = Get-Variable -Name $key -ErrorAction SilentlyContinue
        if ($paramValue -and $paramValue.Value) {
            $API_KEYS[$key] = $paramValue.Value
        }
    }

    # Then prompt for any missing keys if not skipping prompts
    if (-not $skipPrompts) {
        foreach ($key in $API_KEYS.Keys) {
            if (-not $API_KEYS[$key]) {
                $API_KEYS[$key] = Read-Host "Enter value for $key (press Enter to skip)"
            }
        }
    }
}

# Function to replace API key placeholders in config
function Replace-ApiKeyPlaceholders {
    param (
        [hashtable]$config
    )
    
    $jsonConfig = $config | ConvertTo-Json -Depth 10
    foreach ($key in $API_KEYS.Keys) {
        $placeholder = "{$key}"
        if ($jsonConfig.Contains($placeholder)) {
            $jsonConfig = $jsonConfig.Replace($placeholder, $API_KEYS[$key])
        }
    }
    return $jsonConfig | ConvertFrom-Json
}

# Function to update config JSON
function Update-Config {
    param (
        [string]$configFile,
        [PSCustomObject]$newConfig
    )
    
    try {
        $config = Get-Content $configFile | ConvertFrom-Json
        
        # Initialize mcpServers if it doesn't exist
        if (-not $config.PSObject.Properties.Name.Contains("mcpServers")) {
            $config | Add-Member -NotePropertyName "mcpServers" -NotePropertyValue @{}
        }
        
        # Replace API key placeholders and merge config
        $newConfig = Replace-ApiKeyPlaceholders -config $newConfig
        foreach ($server in $newConfig.PSObject.Properties) {
            $config.mcpServers | Add-Member -NotePropertyName $server.Name -NotePropertyValue $server.Value -Force
        }
        
        # Save updated config
        $config | ConvertTo-Json -Depth 10 | Set-Content $configFile
        Write-Host "Config updated successfully for $($server.Name)" -ForegroundColor Green
    }
    catch {
        Write-Host "Error updating config: $_" -ForegroundColor Red
    }
}

# Function to install packages based on prefix
function Install-Package {
    param (
        [string]$package
    )
    
    try {
        if ($package.StartsWith("@")) {
            Write-Host "Installing NPM package: $package" -ForegroundColor Yellow
            npm install -g $package
        }
        else {
            Write-Host "Installing Python package: $package" -ForegroundColor Yellow
            pip install $package
        }
        Write-Host "Successfully installed $package" -ForegroundColor Green
    }
    catch {
        Write-Host "Error installing $package`: $_" -ForegroundColor Red
    }
}

# Collect API keys
Write-Host "Collecting API keys..." -ForegroundColor Yellow
Get-ApiKeys

# Install all packages
Write-Host "Installing packages..." -ForegroundColor Yellow
foreach ($package in $PACKAGES_TO_INSTALL) {
    Install-Package -package $package
}

# Update configurations
Write-Host "Updating configurations..." -ForegroundColor Yellow
Update-Config -configFile $configFile -newConfig ([PSCustomObject]$MCP_CONFIGS)

Write-Host "Setup completed successfully!" -ForegroundColor Green

You can copy this content and save it as setup-claude-mcps.ps1 in the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant