fix(mcp): resolve compilation errors and add backward compatibility
## Compilation Fixes - Add deprecated compatibility methods to McpService: * get_servers() - filters servers by app * set_enabled() - delegates to toggle_app() * sync_enabled() - syncs enabled servers for specific app * import_from_claude/codex/gemini() - wraps mcp:: functions - Fix toml_edit type conversion in sync_single_server_to_codex(): * Add json_server_to_toml_table() helper function * Manually construct toml_edit::Table instead of invalid serde conversion - Fix get_codex_config_path() calls (returns PathBuf, not Result) - Update upsert_mcp_server_in_config() to work with unified structure: * Converts old per-app API to unified McpServer structure * Preserves existing server data when updating * Supports sync_other_side parameter for multi-app enable - Update delete_mcp_server_in_config() to ignore app parameter ## Backward Compatibility - All old v3.6.x commands continue to work with deprecation warnings - Frontend migration can be done incrementally - Old commands transparently use new unified backend ## Status ✅ Backend compiles successfully (cargo check passes) ⚠️ 16 warnings (8 deprecation + 8 unused functions - expected)
This commit is contained in:
@@ -186,4 +186,82 @@ impl McpService {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// 兼容层:支持旧的 v3.6.x 命令(已废弃,将在 v4.0 移除)
|
||||
// ========================================================================
|
||||
|
||||
/// [已废弃] 获取指定应用的 MCP 服务器(兼容旧 API)
|
||||
#[deprecated(since = "3.7.0", note = "Use get_all_servers instead")]
|
||||
pub fn get_servers(
|
||||
state: &AppState,
|
||||
app: AppType,
|
||||
) -> Result<HashMap<String, serde_json::Value>, AppError> {
|
||||
let all_servers = Self::get_all_servers(state)?;
|
||||
let mut result = HashMap::new();
|
||||
|
||||
for (id, server) in all_servers {
|
||||
if server.apps.is_enabled_for(&app) {
|
||||
result.insert(id, server.server);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// [已废弃] 设置 MCP 服务器在指定应用的启用状态(兼容旧 API)
|
||||
#[deprecated(since = "3.7.0", note = "Use toggle_app instead")]
|
||||
pub fn set_enabled(
|
||||
state: &AppState,
|
||||
app: AppType,
|
||||
id: &str,
|
||||
enabled: bool,
|
||||
) -> Result<bool, AppError> {
|
||||
Self::toggle_app(state, id, app, enabled)?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// [已废弃] 同步启用的 MCP 到指定应用(兼容旧 API)
|
||||
#[deprecated(since = "3.7.0", note = "Use sync_all_enabled instead")]
|
||||
pub fn sync_enabled(state: &AppState, app: AppType) -> Result<(), AppError> {
|
||||
let servers = Self::get_all_servers(state)?;
|
||||
|
||||
for server in servers.values() {
|
||||
if server.apps.is_enabled_for(&app) {
|
||||
Self::sync_server_to_app(state, server, &app)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// [已废弃] 从 Claude 导入 MCP(兼容旧 API)
|
||||
#[deprecated(since = "3.7.0", note = "Import will be handled differently in unified structure")]
|
||||
pub fn import_from_claude(state: &AppState) -> Result<usize, AppError> {
|
||||
let mut cfg = state.config.write()?;
|
||||
let count = mcp::import_from_claude(&mut cfg)?;
|
||||
drop(cfg);
|
||||
state.save()?;
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
/// [已废弃] 从 Codex 导入 MCP(兼容旧 API)
|
||||
#[deprecated(since = "3.7.0", note = "Import will be handled differently in unified structure")]
|
||||
pub fn import_from_codex(state: &AppState) -> Result<usize, AppError> {
|
||||
let mut cfg = state.config.write()?;
|
||||
let count = mcp::import_from_codex(&mut cfg)?;
|
||||
drop(cfg);
|
||||
state.save()?;
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
/// [已废弃] 从 Gemini 导入 MCP(兼容旧 API)
|
||||
#[deprecated(since = "3.7.0", note = "Import will be handled differently in unified structure")]
|
||||
pub fn import_from_gemini(state: &AppState) -> Result<usize, AppError> {
|
||||
let mut cfg = state.config.write()?;
|
||||
let count = mcp::import_from_gemini(&mut cfg)?;
|
||||
drop(cfg);
|
||||
state.save()?;
|
||||
Ok(count)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user