fix(mcp): initialize McpRoot with v3.7.0 unified structure by default

Problem:
- On first launch, McpRoot::default() created `servers: None`
- McpService::get_all_servers() would incorrectly return error "old structure detected"
- This confused new users who had no legacy MCP data

Root Cause:
- Derived Default trait sets Option<T> fields to None
- New installations should start with v3.7.0 structure immediately

Solution:
- Explicitly implement Default for McpRoot
- Initialize `servers: Some(HashMap::new())` for v3.7.0+ structure
- Legacy fields (claude/codex/gemini) remain empty, only used for deserializing old configs

Impact:
- First-time users get correct v3.7.0 structure immediately
- migrate_mcp_to_unified() correctly detects already-migrated state
- No false "old structure" errors on fresh installs
This commit is contained in:
Jason
2025-11-14 22:55:46 +08:00
parent 2f18d6ec00
commit 09f80d82bc

View File

@@ -86,7 +86,7 @@ impl McpConfig {
}
/// MCP 根配置v3.7.0 新旧结构并存)
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct McpRoot {
/// 统一的 MCP 服务器存储v3.7.0+
#[serde(skip_serializing_if = "Option::is_none")]
@@ -101,6 +101,19 @@ pub struct McpRoot {
pub gemini: McpConfig,
}
impl Default for McpRoot {
fn default() -> Self {
Self {
// v3.7.0+ 默认使用新的统一结构(空 HashMap
servers: Some(HashMap::new()),
// 旧结构保持空,仅用于反序列化旧配置时的迁移
claude: McpConfig::default(),
codex: McpConfig::default(),
gemini: McpConfig::default(),
}
}
}
/// Prompt 配置:单客户端维度
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PromptConfig {