From a6ee3ba35fb0aeba065edb551ed21e9b3fec8900 Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 11 Oct 2025 11:43:32 +0800 Subject: [PATCH] feat(mcp): enhance wizard with title field and optimize placeholders - Add MCP title field to wizard (required) - Remove working directory (cwd) field and related logic - Update wizard callback to return both title and JSON - Optimize placeholder text for better user guidance: - Command: "npx or uvx" - Args: "arg1\narg2" - Env: "KEY1=value1\nKEY2=value2" - Headers: "Authorization: Bearer your_token_here\n..." - Simplify args label by removing "(one per line)" hint - Update parent component to handle title from wizard --- src/components/mcp/McpFormModal.tsx | 3 +- src/components/mcp/McpWizardModal.tsx | 47 +++++++++++++-------------- src/i18n/locales/en.json | 13 +++----- src/i18n/locales/zh.json | 13 +++----- 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/components/mcp/McpFormModal.tsx b/src/components/mcp/McpFormModal.tsx index 4bfd2f8..f41e8df 100644 --- a/src/components/mcp/McpFormModal.tsx +++ b/src/components/mcp/McpFormModal.tsx @@ -152,7 +152,8 @@ const McpFormModal: React.FC = ({ setJsonError(""); }; - const handleWizardApply = (json: string) => { + const handleWizardApply = (title: string, json: string) => { + setFormId(title); setFormJson(json); setJsonError(validateJson(json)); }; diff --git a/src/components/mcp/McpWizardModal.tsx b/src/components/mcp/McpWizardModal.tsx index 86a8848..6e37a53 100644 --- a/src/components/mcp/McpWizardModal.tsx +++ b/src/components/mcp/McpWizardModal.tsx @@ -7,7 +7,7 @@ import { isLinux } from "../../lib/platform"; interface McpWizardModalProps { isOpen: boolean; onClose: () => void; - onApply: (json: string) => void; + onApply: (title: string, json: string) => void; onNotify?: ( message: string, type: "success" | "error", @@ -75,10 +75,10 @@ const McpWizardModal: React.FC = ({ }) => { const { t } = useTranslation(); const [wizardType, setWizardType] = useState<"stdio" | "http">("stdio"); + const [wizardTitle, setWizardTitle] = useState(""); // stdio 字段 const [wizardCommand, setWizardCommand] = useState(""); const [wizardArgs, setWizardArgs] = useState(""); - const [wizardCwd, setWizardCwd] = useState(""); const [wizardEnv, setWizardEnv] = useState(""); // http 字段 const [wizardUrl, setWizardUrl] = useState(""); @@ -102,10 +102,6 @@ const McpWizardModal: React.FC = ({ .filter((s) => s.length > 0); } - if (wizardCwd.trim()) { - config.cwd = wizardCwd.trim(); - } - if (wizardEnv.trim()) { const env = parseEnvText(wizardEnv); if (Object.keys(env).length > 0) { @@ -129,6 +125,10 @@ const McpWizardModal: React.FC = ({ }; const handleApply = () => { + if (!wizardTitle.trim()) { + onNotify?.(t("mcp.error.idRequired"), "error", 3000); + return; + } if (wizardType === "stdio" && !wizardCommand.trim()) { onNotify?.(t("mcp.error.commandRequired"), "error", 3000); return; @@ -139,16 +139,16 @@ const McpWizardModal: React.FC = ({ } const json = generatePreview(); - onApply(json); + onApply(wizardTitle.trim(), json); handleClose(); }; const handleClose = () => { // 重置表单 setWizardType("stdio"); + setWizardTitle(""); setWizardCommand(""); setWizardArgs(""); - setWizardCwd(""); setWizardEnv(""); setWizardUrl(""); setWizardHeaders(""); @@ -247,6 +247,21 @@ const McpWizardModal: React.FC = ({ + {/* Title */} +
+ + setWizardTitle(e.target.value)} + onKeyDown={handleKeyDown} + placeholder={t("mcp.form.titlePlaceholder")} + className="w-full rounded-lg border border-gray-200 px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-emerald-500/20 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100" + /> +
+ {/* Stdio 类型字段 */} {wizardType === "stdio" && ( <> @@ -280,21 +295,6 @@ const McpWizardModal: React.FC = ({ /> - {/* CWD */} -
- - setWizardCwd(e.target.value)} - onKeyDown={handleKeyDown} - placeholder={t("mcp.wizard.cwdPlaceholder")} - className="w-full rounded-lg border border-gray-200 px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-emerald-500/20 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100" - /> -
- {/* Env */}