mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
feat(mcp): add import button to import MCP servers from apps
- Add import_mcp_from_apps command that reuses existing import logic - Add Import button in MCP panel header (consistent with Skills) - Fix import count to only return truly new servers (not already in DB) - Update translations for import success/no-import messages (zh/en/ja)
This commit is contained in:
@@ -192,3 +192,13 @@ pub async fn toggle_mcp_app(
|
||||
let app_ty = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
||||
McpService::toggle_app(&state, &server_id, app_ty, enabled).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// 从所有应用导入 MCP 服务器(复用已有的导入逻辑)
|
||||
#[tauri::command]
|
||||
pub async fn import_mcp_from_apps(state: State<'_, AppState>) -> Result<usize, String> {
|
||||
let mut total = 0;
|
||||
total += McpService::import_from_claude(&state).unwrap_or(0);
|
||||
total += McpService::import_from_codex(&state).unwrap_or(0);
|
||||
total += McpService::import_from_gemini(&state).unwrap_or(0);
|
||||
Ok(total)
|
||||
}
|
||||
|
||||
@@ -637,6 +637,7 @@ pub fn run() {
|
||||
commands::upsert_mcp_server,
|
||||
commands::delete_mcp_server,
|
||||
commands::toggle_mcp_app,
|
||||
commands::import_mcp_from_apps,
|
||||
// Prompt management
|
||||
commands::get_prompts,
|
||||
commands::upsert_prompt,
|
||||
|
||||
@@ -206,6 +206,8 @@ impl McpService {
|
||||
// 调用原有的导入逻辑(从 mcp.rs)
|
||||
let count = crate::mcp::import_from_claude(&mut temp_config)?;
|
||||
|
||||
let mut new_count = 0;
|
||||
|
||||
// 如果有导入的服务器,保存到数据库
|
||||
if count > 0 {
|
||||
if let Some(servers) = &temp_config.mcp.servers {
|
||||
@@ -217,6 +219,8 @@ impl McpService {
|
||||
merged.apps.claude = true;
|
||||
merged
|
||||
} else {
|
||||
// 真正的新服务器
|
||||
new_count += 1;
|
||||
server.clone()
|
||||
};
|
||||
|
||||
@@ -229,7 +233,7 @@ impl McpService {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(count)
|
||||
Ok(new_count)
|
||||
}
|
||||
|
||||
/// 从 Codex 导入 MCP(v3.7.0 已更新为统一结构)
|
||||
@@ -240,6 +244,8 @@ impl McpService {
|
||||
// 调用原有的导入逻辑(从 mcp.rs)
|
||||
let count = crate::mcp::import_from_codex(&mut temp_config)?;
|
||||
|
||||
let mut new_count = 0;
|
||||
|
||||
// 如果有导入的服务器,保存到数据库
|
||||
if count > 0 {
|
||||
if let Some(servers) = &temp_config.mcp.servers {
|
||||
@@ -251,6 +257,8 @@ impl McpService {
|
||||
merged.apps.codex = true;
|
||||
merged
|
||||
} else {
|
||||
// 真正的新服务器
|
||||
new_count += 1;
|
||||
server.clone()
|
||||
};
|
||||
|
||||
@@ -263,7 +271,7 @@ impl McpService {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(count)
|
||||
Ok(new_count)
|
||||
}
|
||||
|
||||
/// 从 Gemini 导入 MCP(v3.7.0 已更新为统一结构)
|
||||
@@ -274,6 +282,8 @@ impl McpService {
|
||||
// 调用原有的导入逻辑(从 mcp.rs)
|
||||
let count = crate::mcp::import_from_gemini(&mut temp_config)?;
|
||||
|
||||
let mut new_count = 0;
|
||||
|
||||
// 如果有导入的服务器,保存到数据库
|
||||
if count > 0 {
|
||||
if let Some(servers) = &temp_config.mcp.servers {
|
||||
@@ -285,6 +295,8 @@ impl McpService {
|
||||
merged.apps.gemini = true;
|
||||
merged
|
||||
} else {
|
||||
// 真正的新服务器
|
||||
new_count += 1;
|
||||
server.clone()
|
||||
};
|
||||
|
||||
@@ -297,6 +309,6 @@ impl McpService {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(count)
|
||||
Ok(new_count)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user