BUG修复 MCP快捷菜单 无法选中 修复方案,ai修复的
版本:v26.0.3
完整的 bug 链路如下:
-
点击"联网搜索" → quickMenuMcpServer.id 加入 selectedMcpServerIds ✅
-
useEffect 被触发(监听 selectedMcpServerIds 变化) → 从 /ai-mcp-servers/all 接口获取 mcpServers 列表 → 但该接口会故意过滤掉 Quick Menu ID(代码中 if (item.id === isQuickMenuId) return null)
-
过滤逻辑: nextSelectedIds = selectedMcpServerIds.filter(id => availableIdSet.has(id)) → Quick Menu ID 不在 availableIdSet 中 → 被过滤掉!
-
onSelectMcpServers([]) 被调用 → 选中状态立即清空 ❌ → 按钮回到未选中外观
修复内容 文件:packages/client/src/components/ask-assistant-ui/components/input/prompt-input.tsx
在"清理失效 MCP 选择"的 useEffect 中,将 Quick Menu ID 从过滤逻辑中排除:
// 修复前 const nextSelectedIds = selectedMcpServerIds.filter((id) => availableIdSet.has(id)); // 修复后 const quickMenuId = quickMenuMcpServer?.id; const nextSelectedIds = selectedMcpServerIds.filter( (id) => availableIdSet.has(id) || id === quickMenuId, // ← Quick Menu ID 豁免 );
在文件:packages/client/src/components/ask-assistant-ui/components/input/prompt-input.tsx 188行左右
修改后的代码如下
const { data: mcpServers = [], isLoading: isLoadingMcpServers } = useMcpServersAllQuery(
{
isDisabled: false,
},
{
enabled: shouldLoadMcpServers,
},
);
const { data: quickMenuMcpServer } = useMcpServerQuickMenuQuery({
enabled: shouldLoadQuickMenu,
});
useEffect(() => {
if (!shouldLoadMcpServers) return;
if (isLoadingMcpServers) return;
if (selectedMcpServerIds.length === 0) return;
const availableIdSet = new Set(mcpServers.map((s) => s.id));
// Quick Menu MCP server is excluded from the /all endpoint, so we must
// keep its ID in the selection even if it's not in availableIdSet.
const quickMenuId = quickMenuMcpServer?.id;
const nextSelectedIds = selectedMcpServerIds.filter(
(id) => availableIdSet.has(id) || id === quickMenuId,
);
if (nextSelectedIds.length === selectedMcpServerIds.length) return;
onSelectMcpServers(nextSelectedIds);
}, [
shouldLoadMcpServers,
isLoadingMcpServers,
mcpServers,
selectedMcpServerIds,
onSelectMcpServers,
quickMenuMcpServer,
]);
亲测,修改完重新编译后 可以修复 前端 无法选中 MCP快捷菜单 的问题
BuildingAI 开发者大神,建议下个版本修复下