diff --git a/README.md b/README.md index 8c63ed7..07ab0b4 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ devcontainer-mcp local Docker demo

-> Works with **GitHub Copilot**, **Claude**, **Cursor**, and any MCP-compatible client. +> Works with **GitHub Copilot**, **Claude**, **Cursor**, **opencode**, and any MCP-compatible client. ## The Problem diff --git a/install.ps1 b/install.ps1 index f71da2e..86cbdda 100644 --- a/install.ps1 +++ b/install.ps1 @@ -111,6 +111,7 @@ $skillDirs = @( "$env:USERPROFILE\.copilot\skills\devcontainer-mcp" "$env:USERPROFILE\.claude\skills\devcontainer-mcp" "$env:USERPROFILE\.agents\skills\devcontainer-mcp" + "$env:USERPROFILE\.config\opencode\skills\devcontainer-mcp" ) foreach ($dir in $skillDirs) { @@ -362,6 +363,48 @@ if (Test-Path "$env:USERPROFILE\.cursor") { Set-McpConfig "$env:USERPROFILE\.cursor\mcp.json" "Cursor" } +# opencode — uses a distinct schema (mcp key, type: "local", combined +# command array, enabled: true) and lives at ~/.config/opencode/opencode.json. +function Set-OpencodeMcpConfig { + $ConfigPath = "$env:USERPROFILE\.config\opencode\opencode.json" + $opencodeEntry = [PSCustomObject]@{ + type = "local" + command = @("wsl", $WslBinaryPath, "serve") + enabled = $true + } + + try { + if (Test-Path $ConfigPath) { + $content = Get-Content -Raw $ConfigPath | ConvertFrom-Json + if (-not $content.mcp) { + $content | Add-Member -NotePropertyName "mcp" -NotePropertyValue ([PSCustomObject]@{}) + } + if ($content.mcp.PSObject.Properties.Name -contains "devcontainer-mcp") { + Write-Ok "opencode — already configured" + return + } + $content.mcp | Add-Member -NotePropertyName "devcontainer-mcp" -NotePropertyValue $opencodeEntry + $content | ConvertTo-Json -Depth 10 | Set-Content $ConfigPath -Encoding UTF8 + Write-Ok "opencode — added to $ConfigPath" + } else { + $dir = Split-Path $ConfigPath -Parent + if ($dir) { New-Item -ItemType Directory -Path $dir -Force | Out-Null } + $config = [PSCustomObject]@{ + '$schema' = "https://opencode.ai/config.json" + mcp = [PSCustomObject]@{ + "devcontainer-mcp" = $opencodeEntry + } + } + $config | ConvertTo-Json -Depth 10 | Set-Content $ConfigPath -Encoding UTF8 + Write-Ok "opencode — created $ConfigPath" + } + } catch { + Write-Warn "opencode — could not update $ConfigPath" + } +} + +Set-OpencodeMcpConfig + # --------------------------------------------------------------------------- # Done # --------------------------------------------------------------------------- diff --git a/install.sh b/install.sh index d6f8fc2..da18c0f 100755 --- a/install.sh +++ b/install.sh @@ -106,6 +106,7 @@ SKILL_DIRS=( "${HOME}/.copilot/skills/devcontainer-mcp" "${HOME}/.claude/skills/devcontainer-mcp" "${HOME}/.agents/skills/devcontainer-mcp" + "${HOME}/.config/opencode/skills/devcontainer-mcp" ) echo "" @@ -346,6 +347,51 @@ else: fi } +# opencode uses a different config schema (mcp key, type: "local", combined +# command array, enabled: true) and a different file path. +configure_opencode_mcp() { + local config_file="${HOME}/.config/opencode/opencode.json" + local bin_path="${INSTALL_DIR}/devcontainer-mcp" + + if [ ! -f "$config_file" ]; then + mkdir -p "$(dirname "$config_file")" + cat > "$config_file" << OPENCODEEOF +{ + "\$schema": "https://opencode.ai/config.json", + "mcp": { + "devcontainer-mcp": { + "type": "local", + "command": ["${bin_path}", "serve"], + "enabled": true + } + } +} +OPENCODEEOF + echo " ✓ opencode — created ${config_file}" + elif command -v python3 >/dev/null 2>&1; then + python3 -c " +import json +path = '${config_file}' +with open(path) as f: + data = json.load(f) +servers = data.setdefault('mcp', {}) +if 'devcontainer-mcp' not in servers: + servers['devcontainer-mcp'] = { + 'type': 'local', + 'command': ['${bin_path}', 'serve'], + 'enabled': True, + } + with open(path, 'w') as f: + json.dump(data, f, indent=2) + print(' ✓ opencode — added to ${config_file}') +else: + print(' ✓ opencode — already configured') +" 2>/dev/null || echo " ⚠ opencode — could not update ${config_file}" + else + echo " ⚠ opencode — exists but python3 not available to merge" + fi +} + echo "" echo "==> Configuring MCP clients..." @@ -372,5 +418,8 @@ fi # Claude Code — ~/.claude.json configure_mcp_client "${HOME}/.claude.json" "Claude Code" +# opencode — ~/.config/opencode/opencode.json (uses different schema) +configure_opencode_mcp + echo "" echo "Done! devcontainer-mcp is ready to use."