diff --git a/auto-setup.ps1 b/auto-setup.ps1 index 14415d8..66e83c1 100644 --- a/auto-setup.ps1 +++ b/auto-setup.ps1 @@ -16,7 +16,7 @@ param( $ErrorActionPreference = "Stop" # ─── 版本号 (每次更新递增, build.ps1 自动读取) ────── -$BWVersion = "2.0.0" +$BWVersion = "2.0.1" # ─── B4: 单实例保护 (防止双击两次导致竞态) ───────── $mutexCreated = $false @@ -1089,7 +1089,7 @@ if (Test-Path $templateFile) { Set-Content $settingsFile -Value $content -Encoding UTF8 Log-OK "settings.json 已渲染 (ROOT=$claudeRoot, SHELL=$pwshJsonPath)" - # settings.local.template.json + # settings.local.template.json (向后兼容) $localTpl = Join-Path $ClaudeDir "settings.local.template.json" $localSet = Join-Path $ClaudeDir "settings.local.json" if (Test-Path $localTpl) { @@ -1101,6 +1101,35 @@ if (Test-Path $templateFile) { Set-Content $localSet -Value $lc -Encoding UTF8 Log-OK "settings.local.json 已渲染" } + + # ── ~/.claude.json (Claude Code v2.1+ MCP 服务器配置的正确位置) ── + # Claude Code 不再从 settings.json 读取 mcpServers, 必须写入 ~/.claude.json + $claudeJsonFile = Join-Path $env:USERPROFILE ".claude.json" + try { + $settingsObj = ConvertFrom-Json $content + if ($settingsObj.mcpServers) { + $mcpOnly = @{ mcpServers = $settingsObj.mcpServers } + # 如果已有 .claude.json, 合并 mcpServers (保留用户自定义项) + if (Test-Path $claudeJsonFile) { + try { + $existing = Get-Content $claudeJsonFile -Raw -ErrorAction SilentlyContinue | ConvertFrom-Json + if ($existing.mcpServers) { + # 以模板为基础, 保留用户新增的 server + $merged = @{} + foreach ($prop in $existing.mcpServers.PSObject.Properties) { $merged[$prop.Name] = $prop.Value } + foreach ($prop in $settingsObj.mcpServers.PSObject.Properties) { $merged[$prop.Name] = $prop.Value } + $mcpOnly.mcpServers = [PSCustomObject]$merged + } + } catch { <# 解析失败则覆盖 #> } + } + $mcpJson = $mcpOnly | ConvertTo-Json -Depth 10 + Set-Content $claudeJsonFile -Value $mcpJson -Encoding UTF8 + $mcpCount = ($settingsObj.mcpServers.PSObject.Properties | Where-Object { $_.Name -notlike '__*' }).Count + Log-OK ".claude.json 已写入 ($mcpCount 个 MCP 服务器)" + } + } catch { + Bw-Log "WARN" ".claude.json 生成失败: $_" + } } else { Log-Warn "settings.template.json 不存在, 跳过渲染" }