diff --git a/src-tauri/src/claude_mcp.rs b/src-tauri/src/claude_mcp.rs index 32413f7..ba6f928 100644 --- a/src-tauri/src/claude_mcp.rs +++ b/src-tauri/src/claude_mcp.rs @@ -4,29 +4,21 @@ use std::env; use std::fs; use std::path::{Path, PathBuf}; -use crate::config::{atomic_write, get_claude_config_dir}; +use crate::config::atomic_write; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct McpStatus { - pub settings_local_path: String, - pub settings_local_exists: bool, - pub enable_all_project_mcp_servers: bool, - pub mcp_json_path: String, - pub mcp_json_exists: bool, + pub user_config_path: String, + pub user_config_exists: bool, pub server_count: usize, } -fn claude_dir() -> PathBuf { - get_claude_config_dir() -} - -fn settings_local_path() -> PathBuf { - claude_dir().join("settings.local.json") -} - -fn mcp_json_path() -> PathBuf { - claude_dir().join("mcp.json") +fn user_config_path() -> PathBuf { + // 用户级 MCP 配置文件:~/.claude.json + dirs::home_dir() + .expect("无法获取用户主目录") + .join(".claude.json") } fn read_json_value(path: &Path) -> Result { @@ -50,20 +42,9 @@ fn write_json_value(path: &Path, value: &Value) -> Result<(), String> { } pub fn get_mcp_status() -> Result { - let settings_local = settings_local_path(); - let mcp_path = mcp_json_path(); - - let mut enable = false; - if settings_local.exists() { - let v = read_json_value(&settings_local)?; - enable = v - .get("enableAllProjectMcpServers") - .and_then(|x| x.as_bool()) - .unwrap_or(false); - } - - let (exists, count) = if mcp_path.exists() { - let v = read_json_value(&mcp_path)?; + let path = user_config_path(); + let (exists, count) = if path.exists() { + let v = read_json_value(&path)?; let servers = v.get("mcpServers").and_then(|x| x.as_object()); (true, servers.map(|m| m.len()).unwrap_or(0)) } else { @@ -71,17 +52,14 @@ pub fn get_mcp_status() -> Result { }; Ok(McpStatus { - settings_local_path: settings_local.to_string_lossy().to_string(), - settings_local_exists: settings_local.exists(), - enable_all_project_mcp_servers: enable, - mcp_json_path: mcp_path.to_string_lossy().to_string(), - mcp_json_exists: exists, + user_config_path: path.to_string_lossy().to_string(), + user_config_exists: exists, server_count: count, }) } pub fn read_mcp_json() -> Result, String> { - let path = mcp_json_path(); + let path = user_config_path(); if !path.exists() { return Ok(None); } @@ -90,28 +68,6 @@ pub fn read_mcp_json() -> Result, String> { Ok(Some(content)) } -pub fn set_enable_all_projects(enable: bool) -> Result { - let path = settings_local_path(); - let mut v = if path.exists() { read_json_value(&path)? } else { serde_json::json!({}) }; - - let current = v - .get("enableAllProjectMcpServers") - .and_then(|x| x.as_bool()) - .unwrap_or(false); - if current == enable && path.exists() { - return Ok(false); - } - - if let Some(obj) = v.as_object_mut() { - obj.insert( - "enableAllProjectMcpServers".to_string(), - Value::Bool(enable), - ); - } - write_json_value(&path, &v)?; - Ok(true) -} - pub fn upsert_mcp_server(id: &str, spec: Value) -> Result { if id.trim().is_empty() { return Err("MCP 服务器 ID 不能为空".into()); @@ -132,7 +88,7 @@ pub fn upsert_mcp_server(id: &str, spec: Value) -> Result { return Err("MCP 服务器缺少 command".into()); } - let path = mcp_json_path(); + let path = user_config_path(); let mut root = if path.exists() { read_json_value(&path)? } else { serde_json::json!({}) }; // 确保 mcpServers 对象存在 @@ -163,7 +119,7 @@ pub fn delete_mcp_server(id: &str) -> Result { if id.trim().is_empty() { return Err("MCP 服务器 ID 不能为空".into()); } - let path = mcp_json_path(); + let path = user_config_path(); if !path.exists() { return Ok(false); } @@ -215,4 +171,3 @@ pub fn validate_command_in_path(cmd: &str) -> Result { } Ok(false) } - diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 3b35ef6..b7d1a3b 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -676,11 +676,6 @@ pub async fn read_claude_mcp_config() -> Result, String> { claude_mcp::read_mcp_json() } -/// 设置 enableAllProjectMcpServers 开关 -#[tauri::command] -pub async fn set_claude_mcp_enable_all_projects(enable: bool) -> Result { - claude_mcp::set_enable_all_projects(enable) -} /// 新增或更新一个 MCP 服务器条目 #[tauri::command] diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 7685972..ca6d137 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -425,7 +425,6 @@ pub fn run() { // Claude MCP management commands::get_claude_mcp_status, commands::read_claude_mcp_config, - commands::set_claude_mcp_enable_all_projects, commands::upsert_claude_mcp_server, commands::delete_claude_mcp_server, commands::validate_mcp_command, diff --git a/src/components/mcp/McpPanel.tsx b/src/components/mcp/McpPanel.tsx index 74450b1..439f205 100644 --- a/src/components/mcp/McpPanel.tsx +++ b/src/components/mcp/McpPanel.tsx @@ -77,17 +77,7 @@ const McpPanel: React.FC = ({ onClose, onNotify }) => { reload(); }, []); - const handleToggleEnable = async (enable: boolean) => { - try { - const changed = await window.api.setClaudeMcpEnableAllProjects(enable); - if (changed) { - await reload(); - onNotify?.(t("mcp.notice.restartClaude"), "success", 2000); - } - } catch (e: any) { - onNotify?.(e?.message || t("mcp.error.toggleFailed"), "error", 5000); - } - }; + // 用户级 MCP:不需要项目级启用开关 const resetForm = () => { setEditingId(null); @@ -200,24 +190,13 @@ const McpPanel: React.FC = ({ onClose, onNotify }) => {
{/* Left: status & list */}
-
-
-
- {t("mcp.enableProject")} -
-
- {status?.settingsLocalPath} -
+
+
+ {t("mcp.userLevelPath")} +
+
+ {status?.userConfigPath}
-