Feature: add MCP settings presets and hide command whitelist
The MCP settings dialog had grown too many independent tool switches to tick by hand. Add two one-click preset buttons next to the "Enable MCP" checkbox. "Read-only mode" turns MCP on, enables the read-only switch, and unchecks every feature that only works when read-only is off (persistent terminal, remote control, file write, management, dangerous host operations, client build). "Smart mode" turns MCP on, disables read-only, and enables all tool switches, including host management plus dangerous host operations so the OnOK dependency check does not revert it. Stop showing the command whitelist input: it is advanced and is easily bypassed once the persistent terminal is enabled. Its load, normalize and save logic is left untouched, so the persisted McpCmdWhitelist still round-trips unchanged and the server-side whitelist check is unchanged. Add translations for the two new button labels (en_US, zh_TW, de_DE), and size the preset buttons from the current font so translated labels do not clip. Verified with a Debug x64 server build; the dialog was not clicked through. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
545700abaa
commit
5387603c73
5 files changed
+94
-9
No files matched your search
@@ -100,6 +100,8 @@ BEGIN_MESSAGE_MAP(CMcpSettingsDlg, CDialog)
|
||||
ON_BN_CLICKED(IDC_MCP_HTTPS, &CMcpSettingsDlg::OnHttpsToggle)
|
||||
ON_BN_CLICKED(IDC_MCP_CERT_BROWSE, &CMcpSettingsDlg::OnBrowseCert)
|
||||
ON_BN_CLICKED(IDC_MCP_KEY_BROWSE, &CMcpSettingsDlg::OnBrowseKey)
|
||||
ON_BN_CLICKED(IDC_MCP_PRESET_READONLY, &CMcpSettingsDlg::OnPresetReadonly)
|
||||
ON_BN_CLICKED(IDC_MCP_PRESET_SMART, &CMcpSettingsDlg::OnPresetSmart)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
CMcpSettingsDlg::CMcpSettingsDlg(CWnd* parent)
|
||||
@@ -129,6 +131,13 @@ BOOL CMcpSettingsDlg::OnInitDialog()
|
||||
m_btnEnable.Create(_TR("启用 MCP"),
|
||||
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
|
||||
r0, this, IDC_MCP_ENABLE);
|
||||
// 与「启用 MCP」同一行、紧随其后的两个一键预设按钮。
|
||||
m_btnPresetReadonly.Create(_TR("只读模式"),
|
||||
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
|
||||
r0, this, IDC_MCP_PRESET_READONLY);
|
||||
m_btnPresetSmart.Create(_TR("智能模式"),
|
||||
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
|
||||
r0, this, IDC_MCP_PRESET_SMART);
|
||||
m_lblPort.Create(_TR("端口"), WS_CHILD | WS_VISIBLE, r0, this, (UINT)-1);
|
||||
m_editPort.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL,
|
||||
r0, this, IDC_MCP_PORT);
|
||||
@@ -184,8 +193,10 @@ BOOL CMcpSettingsDlg::OnInitDialog()
|
||||
m_btnBuild.Create(_TR("启用客户端生成(AI 生成客户端文件,要求只读关)"),
|
||||
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
|
||||
r0, this, IDC_MCP_BUILD);
|
||||
m_lblWhitelist.Create(_TR("命令白名单"), WS_CHILD | WS_VISIBLE, r0, this, (UINT)-1);
|
||||
m_editWhitelist.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
|
||||
// 命令白名单:保留原有读取/规范化/回存逻辑,仅不在 UI 上显示——
|
||||
// 该输入对普通用户过于专业、容易误解。(隐藏控件仍承载配置值)
|
||||
m_lblWhitelist.Create(_TR("命令白名单"), WS_CHILD, r0, this, (UINT)-1);
|
||||
m_editWhitelist.Create(WS_CHILD | WS_BORDER | WS_TABSTOP |
|
||||
ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL,
|
||||
r0, this, IDC_MCP_WHITELIST);
|
||||
m_btnOK.Create(_TR("确定"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON,
|
||||
@@ -197,6 +208,8 @@ BOOL CMcpSettingsDlg::OnInitDialog()
|
||||
HFONT hFont = (HFONT)::SendMessage(GetSafeHwnd(), WM_GETFONT, 0, 0);
|
||||
if (hFont) {
|
||||
m_btnEnable.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
||||
m_btnPresetReadonly.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
||||
m_btnPresetSmart.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
||||
m_lblPort.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
||||
m_editPort.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
||||
m_lblBind.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
||||
@@ -299,6 +312,41 @@ void CMcpSettingsDlg::OnHttpsToggle()
|
||||
UpdateHttpsState();
|
||||
}
|
||||
|
||||
// 「只读模式」预设:一键切到只读安全的工具组合。
|
||||
// 顺带打开「启用 MCP」(未开则开),勾选「只读模式(禁命令执行)」,
|
||||
// 并关闭所有「要求只读关闭」才生效的开关,避免保存后这些功能处于
|
||||
// 「已勾选但实际无效」的状态。
|
||||
void CMcpSettingsDlg::OnPresetReadonly()
|
||||
{
|
||||
m_btnEnable.SetCheck(BST_CHECKED);
|
||||
m_btnReadonly.SetCheck(BST_CHECKED);
|
||||
m_btnTerminal.SetCheck(BST_UNCHECKED);
|
||||
m_btnRemoteControl.SetCheck(BST_UNCHECKED);
|
||||
m_btnFileWrite.SetCheck(BST_UNCHECKED);
|
||||
m_btnManage.SetCheck(BST_UNCHECKED);
|
||||
m_btnMachineDangerous.SetCheck(BST_UNCHECKED);
|
||||
m_btnBuild.SetCheck(BST_UNCHECKED);
|
||||
}
|
||||
|
||||
// 「智能模式」预设:一键启用全部 MCP 工具。
|
||||
// 顺带打开「启用 MCP」(未开则开);只读模式会禁用命令执行等开关,故一并关闭;
|
||||
// 主机管理与危险主机操作成对打开,否则保存时 OnOK 会因「危险操作依附于主机管理」而回退。
|
||||
void CMcpSettingsDlg::OnPresetSmart()
|
||||
{
|
||||
m_btnEnable.SetCheck(BST_CHECKED);
|
||||
m_btnReadonly.SetCheck(BST_UNCHECKED);
|
||||
m_btnTerminal.SetCheck(BST_CHECKED);
|
||||
m_btnRemoteControl.SetCheck(BST_CHECKED);
|
||||
m_btnFileTransfer.SetCheck(BST_CHECKED);
|
||||
m_btnFileWrite.SetCheck(BST_CHECKED);
|
||||
m_btnManage.SetCheck(BST_CHECKED);
|
||||
m_btnMachine.SetCheck(BST_CHECKED);
|
||||
m_btnMachineDangerous.SetCheck(BST_CHECKED);
|
||||
m_btnChat.SetCheck(BST_CHECKED);
|
||||
m_btnKeylog.SetCheck(BST_CHECKED);
|
||||
m_btnBuild.SetCheck(BST_CHECKED);
|
||||
}
|
||||
|
||||
void CMcpSettingsDlg::OnBrowseCert()
|
||||
{
|
||||
CString cur;
|
||||
@@ -442,7 +490,31 @@ void CMcpSettingsDlg::LayoutControls(int cx, int cy)
|
||||
const int btnH = 26;
|
||||
|
||||
int y = margin;
|
||||
m_btnEnable.MoveWindow(margin, y, cx - margin * 2, 22);
|
||||
// 「启用 MCP」与其后的两个预设按钮同处一行:只读模式 / 智能模式。
|
||||
// 预设按钮宽度按当前语言的按钮文本自适应,避免英文/德文译文被裁切。
|
||||
CString presetText1, presetText2;
|
||||
m_btnPresetReadonly.GetWindowText(presetText1);
|
||||
m_btnPresetSmart.GetWindowText(presetText2);
|
||||
int presetTextW = 0;
|
||||
{
|
||||
CClientDC dc(this);
|
||||
CFont* pFont = GetFont();
|
||||
CFont* pOld = pFont ? dc.SelectObject(pFont) : nullptr;
|
||||
int w1 = dc.GetTextExtent(presetText1).cx;
|
||||
int w2 = dc.GetTextExtent(presetText2).cx;
|
||||
presetTextW = (w1 > w2) ? w1 : w2;
|
||||
if (pOld) dc.SelectObject(pOld);
|
||||
}
|
||||
const int presetBtnW = presetTextW + 24; // 左右内边距
|
||||
const int presetBtnH = 22;
|
||||
const int presetGap = 8;
|
||||
int smartX = cx - margin - presetBtnW;
|
||||
int readonlyX = smartX - presetGap - presetBtnW;
|
||||
int enableW = readonlyX - presetGap - margin;
|
||||
if (enableW < 90) enableW = 90;
|
||||
m_btnEnable.MoveWindow(margin, y, enableW, 22);
|
||||
m_btnPresetReadonly.MoveWindow(readonlyX, y, presetBtnW, presetBtnH);
|
||||
m_btnPresetSmart.MoveWindow(smartX, y, presetBtnW, presetBtnH);
|
||||
y += 30;
|
||||
|
||||
m_lblPort.MoveWindow(margin, y, labelW, rowH);
|
||||
@@ -506,12 +578,8 @@ void CMcpSettingsDlg::LayoutControls(int cx, int cy)
|
||||
m_btnBuild.MoveWindow(margin, y, cx - margin * 2, 22);
|
||||
y += 30;
|
||||
|
||||
const int whitelistH = 90;
|
||||
m_lblWhitelist.MoveWindow(margin, y, labelW, rowH);
|
||||
m_editWhitelist.MoveWindow(margin + labelW, y - 2, cx - margin * 2 - labelW, whitelistH);
|
||||
y += whitelistH + gap;
|
||||
|
||||
// 确定 / 取消按钮紧跟白名单下方,不再锚定到底部,避免白名单与按钮之间出现大段空白。
|
||||
// 命令白名单控件已隐藏,不占布局空间(逻辑保留,见 OnInitDialog / OnOK)。
|
||||
// 确定 / 取消按钮紧跟最后一个开关下方,不再锚定到底部,避免出现大段空白。
|
||||
m_btnCancel.MoveWindow(cx - margin - btnW, y, btnW, btnH);
|
||||
m_btnOK.MoveWindow(cx - margin - btnW * 2 - gap, y, btnW, btnH);
|
||||
y += btnH + margin;
|
||||
|
||||
Reference in new issue
Block a user