refactor(mcp): remove installed preset badge and env-related preset logic

- Move MCP presets into Add modal, no auto-seeding into list
- Replace env-required presets with context7 (no env needed)
- Remove requiresEnv checks/prompts from list and form
- Keep Docs button; maintain clean list UI
This commit is contained in:
Jason
2025-10-10 22:34:38 +08:00
parent e88562be98
commit 4543664ba2
4 changed files with 137 additions and 79 deletions

View File

@@ -6,9 +6,8 @@ import McpListItem from "./McpListItem";
import McpFormModal from "./McpFormModal";
import { ConfirmDialog } from "../ConfirmDialog";
import { extractErrorMessage } from "../../utils/errorUtils";
import { mcpPresets } from "../../config/mcpPresets";
import McpToggle from "./McpToggle";
import { buttonStyles, cardStyles, cn } from "../../lib/styles";
// 预设相关逻辑已迁移到“新增 MCP”面板列表此处无需引用
import { buttonStyles } from "../../lib/styles";
import { AppType } from "../../lib/tauri-api";
interface McpPanelProps {
@@ -51,29 +50,14 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
useEffect(() => {
const setup = async () => {
try {
// 初始化导入:按应用类型从对应客户端导入已有 MCP(设为 enabled=true
// 初始化:仅从对应客户端导入已有 MCP,不做“预设落库”
if (appType === "claude") {
await window.api.importMcpFromClaude();
} else if (appType === "codex") {
await window.api.importMcpFromCodex();
}
// 读取现有 config.json 内容
const cfg = await window.api.getMcpConfig(appType);
const existing = cfg.servers || {};
// 将预设落库为禁用(若缺失)
const missing = mcpPresets.filter((p) => !existing[p.id]);
for (const p of missing) {
const seed: McpServer = {
...(p.server as McpServer),
enabled: false,
source: "preset",
} as unknown as McpServer;
await window.api.upsertMcpServerInConfig(appType, p.id, seed);
}
} catch (e) {
console.warn("MCP 初始化导入/落库失败(忽略继续)", e);
console.warn("MCP 初始化导入失败(忽略继续)", e);
} finally {
await reload();
}
@@ -84,16 +68,8 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
const handleToggle = async (id: string, enabled: boolean) => {
try {
const server = servers[id];
if (!server) {
const preset = mcpPresets.find((p) => p.id === id);
if (!preset) return;
await window.api.upsertMcpServerInConfig(
appType,
id,
preset.server as McpServer,
);
}
// 启用/禁用已存在的条目
await window.api.setMcpEnabled(appType, id, enabled);
await reload();
onNotify?.(
@@ -221,11 +197,7 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
</div>
) : (
(() => {
const notInstalledPresets = mcpPresets.filter(
(p) => !servers[p.id],
);
const hasAny =
serverEntries.length > 0 || notInstalledPresets.length > 0;
const hasAny = serverEntries.length > 0;
if (!hasAny) {
return (
<div className="text-center py-12">
@@ -259,37 +231,7 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
/>
))}
{/* 预设(未安装) */}
{notInstalledPresets.map((p) => {
return (
<div
key={`preset-${p.id}`}
className={cn(
cardStyles.interactive,
"!p-4 opacity-95",
)}
>
<div className="flex items-center gap-4">
<div className="flex-shrink-0">
<McpToggle
enabled={false}
onChange={(en) => handleToggle(p.id, en)}
/>
</div>
<div className="flex-1 min-w-0">
<h3 className="font-medium text-gray-900 dark:text-gray-100 mb-1">
{p.id}
</h3>
{p.description && (
<p className="text-sm text-gray-500 dark:text-gray-400 truncate">
{p.description}
</p>
)}
</div>
</div>
</div>
);
})}
{/* 预设已移至“新增 MCP”面板中展示与套用 */}
</div>
);
})()