feat(mcp): import Codex MCP from ~/.codex/config.toml

- Support both TOML schemas: [mcp.servers.<id>] and [mcp_servers.<id>]
- Non-destructive merge of imported servers (enabled=true only)
- Preserve existing TOML schema when syncing (prefer mcp_servers)
- Remove both mcp and mcp_servers when no enabled items

feat(ui): auto-import Codex MCP on panel init (app=codex)

chore(tauri): add import_mcp_from_codex command and register

chore(types): expose window.api.importMcpFromCodex and typings

fix(ui): remove unused variable for typecheck
This commit is contained in:
Jason
2025-10-10 14:59:02 +08:00
parent 428369cae0
commit 6cf7dacd0e
9 changed files with 214 additions and 27 deletions

View File

@@ -51,9 +51,11 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
useEffect(() => {
const setup = async () => {
try {
// Claude从 ~/.claude.json 导入已存在的 MCP设为 enabled=true
// 初始化导入:按应用类型从对应客户端导入已有 MCP设为 enabled=true
if (appType === "claude") {
await window.api.importMcpFromClaude();
} else if (appType === "codex") {
await window.api.importMcpFromCodex();
}
// 读取现有 config.json 内容
@@ -86,7 +88,11 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
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.upsertMcpServerInConfig(
appType,
id,
preset.server as McpServer,
);
}
await window.api.setMcpEnabled(appType, id, enabled);
await reload();
@@ -177,7 +183,8 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
{/* Header */}
<div className="flex-shrink-0 flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-800">
<h3 className="text-lg font-semibold text-gray-900 dark:text-gray-100">
{t("mcp.title")} · {t(appType === "claude" ? "apps.claude" : "apps.codex")}
{t("mcp.title")} ·{" "}
{t(appType === "claude" ? "apps.claude" : "apps.codex")}
</h3>
<div className="flex items-center gap-3">
@@ -252,10 +259,6 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify, appType }) => {
{/* 预设(未安装) */}
{notInstalledPresets.map((p) => {
const s = {
...(p.server as McpServer),
enabled: false,
} as McpServer;
return (
<div
key={`preset-${p.id}`}