feat(mcp): pre-fill wizard with existing configuration
Allow MCP wizard to load and edit existing server configuration: - Parse current config (JSON/TOML) and pass to wizard as initial data - Auto-detect server type (stdio/http) and populate form fields - Convert objects (env/headers) to multi-line text format for editing - Improves UX by avoiding manual re-entry of existing settings
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from "react";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { X, Save, AlertCircle, ChevronDown, ChevronUp } from "lucide-react";
|
||||
import { McpServer, McpServerSpec } from "../../types";
|
||||
@@ -117,6 +117,31 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
||||
// 判断是否使用 TOML 格式
|
||||
const useToml = appType === "codex";
|
||||
|
||||
const wizardInitialSpec = useMemo(() => {
|
||||
const fallback = initialData?.server;
|
||||
if (!formConfig.trim()) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
if (useToml) {
|
||||
try {
|
||||
return tomlToMcpServer(formConfig);
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(formConfig);
|
||||
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
||||
return parsed as McpServerSpec;
|
||||
}
|
||||
return fallback;
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}, [formConfig, initialData, useToml]);
|
||||
|
||||
// 预设选择状态(仅新增模式显示;-1 表示自定义)
|
||||
const [selectedPreset, setSelectedPreset] = useState<number | null>(
|
||||
isEditing ? null : -1,
|
||||
@@ -661,6 +686,8 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
||||
onClose={() => setIsWizardOpen(false)}
|
||||
onApply={handleWizardApply}
|
||||
onNotify={onNotify}
|
||||
initialTitle={formId}
|
||||
initialServer={wizardInitialSpec}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user