From ed59420a83258d89773d3422089d953e6cb329ed Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 16 Nov 2025 16:50:07 +0800 Subject: [PATCH] feat(mcp): enhance form UX with default apps and JSON formatter - Enable all apps (Claude, Codex, Gemini) by default when adding MCP servers - Improve config label with clearer wording: "Full JSON configuration or use [Config Wizard]" - Add JSON format button to beautify configuration with 2-space indentation - Update tests to reflect new default behavior - Clean up redundant explicit prop passing This provides a more streamlined experience by enabling all apps out of the box and making it easier to format JSON configurations. --- src/components/mcp/McpFormModal.tsx | 46 ++++++++++++++++++++++---- src/components/mcp/UnifiedMcpPanel.tsx | 1 - src/i18n/locales/en.json | 2 ++ src/i18n/locales/zh.json | 2 ++ tests/components/McpFormModal.test.tsx | 23 +++++++++++-- 5 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/components/mcp/McpFormModal.tsx b/src/components/mcp/McpFormModal.tsx index 3361737..5da9460 100644 --- a/src/components/mcp/McpFormModal.tsx +++ b/src/components/mcp/McpFormModal.tsx @@ -1,7 +1,7 @@ import React, { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; -import { Save, Plus, AlertCircle, ChevronDown, ChevronUp } from "lucide-react"; +import { Save, Plus, AlertCircle, ChevronDown, ChevronUp, Wand2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { @@ -27,6 +27,7 @@ import { mcpServerToToml, } from "@/utils/tomlUtils"; import { normalizeTomlText } from "@/utils/textNormalization"; +import { formatJSON } from "@/utils/formatters"; import { useMcpValidation } from "./useMcpValidation"; import { useUpsertMcpServer } from "@/hooks/useMcp"; @@ -37,7 +38,7 @@ interface McpFormModalProps { onClose: () => void; existingIds?: string[]; defaultFormat?: "json" | "toml"; // 默认配置格式(可选,默认为 JSON) - defaultEnabledApps?: AppId[]; // 默认启用到哪些应用(可选,默认为 Claude) + defaultEnabledApps?: AppId[]; // 默认启用到哪些应用(可选,默认为全部应用) } /** @@ -52,7 +53,7 @@ const McpFormModal: React.FC = ({ onClose, existingIds = [], defaultFormat = "json", - defaultEnabledApps = ["claude"], + defaultEnabledApps = ["claude", "codex", "gemini"], }) => { const { t } = useTranslation(); const { formatTomlError, validateTomlConfig, validateJsonConfig } = @@ -251,6 +252,24 @@ const McpFormModal: React.FC = ({ setConfigError(""); }; + const handleFormatJson = () => { + if (!formConfig.trim()) return; + + try { + const formatted = formatJSON(formConfig); + setFormConfig(formatted); + toast.success(t("common.formatSuccess")); + } catch (error) { + const errorMessage = + error instanceof Error ? error.message : String(error); + toast.error( + t("common.formatError", { + error: errorMessage, + }), + ); + } + }; + const handleWizardApply = (title: string, json: string) => { setFormId(title); if (!formName.trim()) { @@ -632,11 +651,11 @@ const McpFormModal: React.FC = ({ {/* 配置输入框(根据格式显示 JSON 或 TOML) */}
-
-