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:
@@ -41,7 +41,9 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [formId, setFormId] = useState(editingId || "");
|
const [formId, setFormId] = useState(editingId || "");
|
||||||
const [formDescription, setFormDescription] = useState("");
|
const [formDescription, setFormDescription] = useState(
|
||||||
|
(initialData as any)?.description || ""
|
||||||
|
);
|
||||||
const [formJson, setFormJson] = useState(
|
const [formJson, setFormJson] = useState(
|
||||||
initialData ? JSON.stringify(initialData, null, 2) : "",
|
initialData ? JSON.stringify(initialData, null, 2) : "",
|
||||||
);
|
);
|
||||||
@@ -140,6 +142,11 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
server.enabled = initialData.enabled;
|
server.enabled = initialData.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存 description 到 server 对象
|
||||||
|
if (formDescription.trim()) {
|
||||||
|
(server as any).description = formDescription.trim();
|
||||||
|
}
|
||||||
|
|
||||||
// 显式等待父组件保存流程,以便正确处理成功/失败
|
// 显式等待父组件保存流程,以便正确处理成功/失败
|
||||||
await onSave(formId.trim(), server);
|
await onSave(formId.trim(), server);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@@ -29,10 +29,8 @@ const McpListItem: React.FC<McpListItemProps> = ({
|
|||||||
// 默认启用
|
// 默认启用
|
||||||
const enabled = server.enabled !== false;
|
const enabled = server.enabled !== false;
|
||||||
|
|
||||||
// 构建详细信息文本
|
// 只显示 description,没有则留空
|
||||||
const details = ([server.type, server.command, ...(server.args || [])]
|
const description = (server as any).description || "";
|
||||||
.filter(Boolean) as string[])
|
|
||||||
.join(" · ");
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn(cardStyles.interactive, "!p-4")}>
|
<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">
|
<h3 className="font-medium text-gray-900 dark:text-gray-100 mb-1">
|
||||||
{id}
|
{id}
|
||||||
</h3>
|
</h3>
|
||||||
<p className="text-sm text-gray-500 dark:text-gray-400 truncate">
|
{description && (
|
||||||
{details}
|
<p className="text-sm text-gray-500 dark:text-gray-400 truncate">
|
||||||
</p>
|
{description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 右侧:操作按钮 */}
|
{/* 右侧:操作按钮 */}
|
||||||
|
|||||||
@@ -251,9 +251,6 @@ const McpPanel: React.FC<McpPanelProps> = ({ onClose, onNotify }) => {
|
|||||||
...(p.server as McpServer),
|
...(p.server as McpServer),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
} as McpServer;
|
} as McpServer;
|
||||||
const details = [s.type, s.command, ...(s.args || [])].join(
|
|
||||||
" · ",
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={`preset-${p.id}`}
|
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">
|
<h3 className="font-medium text-gray-900 dark:text-gray-100 mb-1">
|
||||||
{p.id}
|
{p.id}
|
||||||
</h3>
|
</h3>
|
||||||
<p className="text-sm text-gray-500 dark:text-gray-400 truncate">
|
{p.description && (
|
||||||
{details}
|
<p className="text-sm text-gray-500 dark:text-gray-400 truncate">
|
||||||
</p>
|
{p.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user