refactor(mcp): switch to user-level config ~/.claude.json and remove project-level logic
- Read/write ~/.claude.json (preserve unknown fields) for mcpServers - Remove settings.local.json and mcp.json handling - Drop enableAllProjectMcpServers command and UI toggle - Update types, Tauri APIs, and MCP panel to reflect new status fields - Keep atomic write and command validation behaviors
This commit is contained in:
@@ -77,17 +77,7 @@ const McpPanel: React.FC<McpPanelProps> = ({ 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<McpPanelProps> = ({ onClose, onNotify }) => {
|
||||
<div className="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
{/* Left: status & list */}
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<div className="text-sm text-gray-500 dark:text-gray-400">
|
||||
{t("mcp.enableProject")}
|
||||
</div>
|
||||
<div className="text-xs text-gray-400 dark:text-gray-500">
|
||||
{status?.settingsLocalPath}
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<div className="text-sm text-gray-500 dark:text-gray-400">
|
||||
{t("mcp.userLevelPath")}
|
||||
</div>
|
||||
<div className="text-xs text-gray-400 dark:text-gray-500 break-all">
|
||||
{status?.userConfigPath}
|
||||
</div>
|
||||
<label className="inline-flex items-center cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="sr-only peer"
|
||||
checked={!!status?.enableAllProjectMcpServers}
|
||||
onChange={(e) => handleToggleEnable(e.target.checked)}
|
||||
/>
|
||||
<div className="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-emerald-500 relative" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 mb-3">
|
||||
@@ -233,12 +212,6 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify }) => {
|
||||
>
|
||||
<Wrench size={16} /> {t("mcp.template.fetch")}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => window.api.openConfigFolder("claude")}
|
||||
className="inline-flex items-center gap-2 px-3 py-2 text-sm font-medium rounded-md bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-200 dark:hover:bg-gray-700"
|
||||
>
|
||||
{t("mcp.openFolder")}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="border border-gray-200 dark:border-gray-800 rounded-lg overflow-hidden">
|
||||
@@ -246,11 +219,7 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify }) => {
|
||||
<span>
|
||||
{t("mcp.serverList")} ({status?.serverCount || 0})
|
||||
</span>
|
||||
{status?.mcpJsonExists ? (
|
||||
<span className="text-gray-400">{status?.mcpJsonPath}</span>
|
||||
) : (
|
||||
<span className="text-gray-400">mcp.json</span>
|
||||
)}
|
||||
<span className="text-gray-400">{status?.userConfigPath}</span>
|
||||
</div>
|
||||
<div className="max-h-64 overflow-auto divide-y divide-gray-200 dark:divide-gray-800">
|
||||
{loading && (
|
||||
@@ -403,4 +372,3 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify }) => {
|
||||
};
|
||||
|
||||
export default McpPanel;
|
||||
|
||||
|
||||
@@ -251,8 +251,7 @@
|
||||
},
|
||||
"mcp": {
|
||||
"title": "MCP Management",
|
||||
"enableProject": "Enable project-level MCP servers",
|
||||
"openFolder": "Open ~/.claude",
|
||||
"userLevelPath": "User-level MCP path",
|
||||
"serverList": "Servers",
|
||||
"loading": "Loading...",
|
||||
"empty": "No MCP servers",
|
||||
@@ -281,7 +280,6 @@
|
||||
"templateAdded": "Template added"
|
||||
},
|
||||
"error": {
|
||||
"toggleFailed": "Failed to update toggle",
|
||||
"idRequired": "Please enter identifier",
|
||||
"commandRequired": "Please enter command",
|
||||
"saveFailed": "Save failed",
|
||||
|
||||
@@ -251,8 +251,7 @@
|
||||
},
|
||||
"mcp": {
|
||||
"title": "MCP 管理",
|
||||
"enableProject": "启用项目级 MCP 服务器",
|
||||
"openFolder": "打开 ~/.claude",
|
||||
"userLevelPath": "用户级 MCP 配置路径",
|
||||
"serverList": "服务器列表",
|
||||
"loading": "加载中...",
|
||||
"empty": "暂无 MCP 服务器",
|
||||
@@ -281,7 +280,6 @@
|
||||
"templateAdded": "已添加模板"
|
||||
},
|
||||
"error": {
|
||||
"toggleFailed": "更新开关失败",
|
||||
"idRequired": "请填写标识",
|
||||
"commandRequired": "请填写命令",
|
||||
"saveFailed": "保存失败",
|
||||
|
||||
@@ -279,7 +279,7 @@ export const tauriAPI = {
|
||||
}
|
||||
},
|
||||
|
||||
// Claude MCP:获取状态(settings.local.json + mcp.json)
|
||||
// Claude MCP:获取状态(用户级 ~/.claude.json)
|
||||
getClaudeMcpStatus: async (): Promise<McpStatus> => {
|
||||
try {
|
||||
return await invoke<McpStatus>("get_claude_mcp_status");
|
||||
@@ -289,7 +289,7 @@ export const tauriAPI = {
|
||||
}
|
||||
},
|
||||
|
||||
// Claude MCP:读取 mcp.json 文本
|
||||
// Claude MCP:读取 ~/.claude.json 文本
|
||||
readClaudeMcpConfig: async (): Promise<string | null> => {
|
||||
try {
|
||||
return await invoke<string | null>("read_claude_mcp_config");
|
||||
@@ -299,16 +299,6 @@ export const tauriAPI = {
|
||||
}
|
||||
},
|
||||
|
||||
// Claude MCP:设置项目级启用开关
|
||||
setClaudeMcpEnableAllProjects: async (enable: boolean): Promise<boolean> => {
|
||||
try {
|
||||
return await invoke<boolean>("set_claude_mcp_enable_all_projects", { enable });
|
||||
} catch (error) {
|
||||
console.error("写入 settings.local.json 失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Claude MCP:新增/更新服务器定义
|
||||
upsertClaudeMcpServer: async (
|
||||
id: string,
|
||||
|
||||
@@ -65,10 +65,7 @@ export interface McpServer {
|
||||
|
||||
// MCP 配置状态
|
||||
export interface McpStatus {
|
||||
settingsLocalPath: string;
|
||||
settingsLocalExists: boolean;
|
||||
enableAllProjectMcpServers: boolean;
|
||||
mcpJsonPath: string;
|
||||
mcpJsonExists: boolean;
|
||||
userConfigPath: string;
|
||||
userConfigExists: boolean;
|
||||
serverCount: number;
|
||||
}
|
||||
|
||||
1
src/vite-env.d.ts
vendored
1
src/vite-env.d.ts
vendored
@@ -64,7 +64,6 @@ declare global {
|
||||
// Claude MCP
|
||||
getClaudeMcpStatus: () => Promise<McpStatus>;
|
||||
readClaudeMcpConfig: () => Promise<string | null>;
|
||||
setClaudeMcpEnableAllProjects: (enable: boolean) => Promise<boolean>;
|
||||
upsertClaudeMcpServer: (
|
||||
id: string,
|
||||
spec: Record<string, any>,
|
||||
|
||||
Reference in New Issue
Block a user