fix(mcp): properly save and display description field

- Initialize formDescription from initialData.description when editing
- Save formDescription to server object before submitting
- Display only description in list items, hide technical details
- Show empty space when description is not available
This commit is contained in:
Jason
2025-10-09 23:13:33 +08:00
parent 29b8d5edde
commit eb8d9352c8
3 changed files with 20 additions and 14 deletions

View File

@@ -41,7 +41,9 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
}) => {
const { t } = useTranslation();
const [formId, setFormId] = useState(editingId || "");
const [formDescription, setFormDescription] = useState("");
const [formDescription, setFormDescription] = useState(
(initialData as any)?.description || ""
);
const [formJson, setFormJson] = useState(
initialData ? JSON.stringify(initialData, null, 2) : "",
);
@@ -140,6 +142,11 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
server.enabled = initialData.enabled;
}
// 保存 description 到 server 对象
if (formDescription.trim()) {
(server as any).description = formDescription.trim();
}
// 显式等待父组件保存流程,以便正确处理成功/失败
await onSave(formId.trim(), server);
} catch (error: any) {

View File

@@ -29,10 +29,8 @@ const McpListItem: React.FC<McpListItemProps> = ({
// 默认启用
const enabled = server.enabled !== false;
// 构建详细信息文本
const details = ([server.type, server.command, ...(server.args || [])]
.filter(Boolean) as string[])
.join(" · ");
// 只显示 description没有则留空
const description = (server as any).description || "";
return (
<div className={cn(cardStyles.interactive, "!p-4")}>
@@ -50,9 +48,11 @@ const McpListItem: React.FC<McpListItemProps> = ({
<h3 className="font-medium text-gray-900 dark:text-gray-100 mb-1">
{id}
</h3>
<p className="text-sm text-gray-500 dark:text-gray-400 truncate">
{details}
</p>
{description && (
<p className="text-sm text-gray-500 dark:text-gray-400 truncate">
{description}
</p>
)}
</div>
{/* 右侧:操作按钮 */}

View File

@@ -251,9 +251,6 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify }) => {
...(p.server as McpServer),
enabled: false,
} as McpServer;
const details = [s.type, s.command, ...(s.args || [])].join(
" · ",
);
return (
<div
key={`preset-${p.id}`}
@@ -273,9 +270,11 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify }) => {
<h3 className="font-medium text-gray-900 dark:text-gray-100 mb-1">
{p.id}
</h3>
<p className="text-sm text-gray-500 dark:text-gray-400 truncate">
{details}
</p>
{p.description && (
<p className="text-sm text-gray-500 dark:text-gray-400 truncate">
{p.description}
</p>
)}
</div>
</div>
</div>