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_HTTPS, &CMcpSettingsDlg::OnHttpsToggle)
|
||||||
ON_BN_CLICKED(IDC_MCP_CERT_BROWSE, &CMcpSettingsDlg::OnBrowseCert)
|
ON_BN_CLICKED(IDC_MCP_CERT_BROWSE, &CMcpSettingsDlg::OnBrowseCert)
|
||||||
ON_BN_CLICKED(IDC_MCP_KEY_BROWSE, &CMcpSettingsDlg::OnBrowseKey)
|
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()
|
END_MESSAGE_MAP()
|
||||||
|
|
||||||
CMcpSettingsDlg::CMcpSettingsDlg(CWnd* parent)
|
CMcpSettingsDlg::CMcpSettingsDlg(CWnd* parent)
|
||||||
@@ -129,6 +131,13 @@ BOOL CMcpSettingsDlg::OnInitDialog()
|
|||||||
m_btnEnable.Create(_TR("启用 MCP"),
|
m_btnEnable.Create(_TR("启用 MCP"),
|
||||||
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
|
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
|
||||||
r0, this, IDC_MCP_ENABLE);
|
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_lblPort.Create(_TR("端口"), WS_CHILD | WS_VISIBLE, r0, this, (UINT)-1);
|
||||||
m_editPort.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL,
|
m_editPort.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_AUTOHSCROLL,
|
||||||
r0, this, IDC_MCP_PORT);
|
r0, this, IDC_MCP_PORT);
|
||||||
@@ -184,8 +193,10 @@ BOOL CMcpSettingsDlg::OnInitDialog()
|
|||||||
m_btnBuild.Create(_TR("启用客户端生成(AI 生成客户端文件,要求只读关)"),
|
m_btnBuild.Create(_TR("启用客户端生成(AI 生成客户端文件,要求只读关)"),
|
||||||
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
|
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX,
|
||||||
r0, this, IDC_MCP_BUILD);
|
r0, this, IDC_MCP_BUILD);
|
||||||
m_lblWhitelist.Create(_TR("命令白名单"), WS_CHILD | WS_VISIBLE, r0, this, (UINT)-1);
|
// 命令白名单:保留原有读取/规范化/回存逻辑,仅不在 UI 上显示——
|
||||||
m_editWhitelist.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
|
// 该输入对普通用户过于专业、容易误解。(隐藏控件仍承载配置值)
|
||||||
|
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,
|
ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL,
|
||||||
r0, this, IDC_MCP_WHITELIST);
|
r0, this, IDC_MCP_WHITELIST);
|
||||||
m_btnOK.Create(_TR("确定"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON,
|
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);
|
HFONT hFont = (HFONT)::SendMessage(GetSafeHwnd(), WM_GETFONT, 0, 0);
|
||||||
if (hFont) {
|
if (hFont) {
|
||||||
m_btnEnable.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
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_lblPort.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
||||||
m_editPort.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));
|
m_lblBind.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
||||||
@@ -299,6 +312,41 @@ void CMcpSettingsDlg::OnHttpsToggle()
|
|||||||
UpdateHttpsState();
|
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()
|
void CMcpSettingsDlg::OnBrowseCert()
|
||||||
{
|
{
|
||||||
CString cur;
|
CString cur;
|
||||||
@@ -442,7 +490,31 @@ void CMcpSettingsDlg::LayoutControls(int cx, int cy)
|
|||||||
const int btnH = 26;
|
const int btnH = 26;
|
||||||
|
|
||||||
int y = margin;
|
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;
|
y += 30;
|
||||||
|
|
||||||
m_lblPort.MoveWindow(margin, y, labelW, rowH);
|
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);
|
m_btnBuild.MoveWindow(margin, y, cx - margin * 2, 22);
|
||||||
y += 30;
|
y += 30;
|
||||||
|
|
||||||
const int whitelistH = 90;
|
// 命令白名单控件已隐藏,不占布局空间(逻辑保留,见 OnInitDialog / OnOK)。
|
||||||
m_lblWhitelist.MoveWindow(margin, y, labelW, rowH);
|
// 确定 / 取消按钮紧跟最后一个开关下方,不再锚定到底部,避免出现大段空白。
|
||||||
m_editWhitelist.MoveWindow(margin + labelW, y - 2, cx - margin * 2 - labelW, whitelistH);
|
|
||||||
y += whitelistH + gap;
|
|
||||||
|
|
||||||
// 确定 / 取消按钮紧跟白名单下方,不再锚定到底部,避免白名单与按钮之间出现大段空白。
|
|
||||||
m_btnCancel.MoveWindow(cx - margin - btnW, y, btnW, btnH);
|
m_btnCancel.MoveWindow(cx - margin - btnW, y, btnW, btnH);
|
||||||
m_btnOK.MoveWindow(cx - margin - btnW * 2 - gap, y, btnW, btnH);
|
m_btnOK.MoveWindow(cx - margin - btnW * 2 - gap, y, btnW, btnH);
|
||||||
y += btnH + margin;
|
y += btnH + margin;
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ protected:
|
|||||||
afx_msg void OnHttpsToggle();
|
afx_msg void OnHttpsToggle();
|
||||||
afx_msg void OnBrowseCert();
|
afx_msg void OnBrowseCert();
|
||||||
afx_msg void OnBrowseKey();
|
afx_msg void OnBrowseKey();
|
||||||
|
afx_msg void OnPresetReadonly(); // 「只读模式」预设:勾选只读并关闭依赖只读关闭的开关
|
||||||
|
afx_msg void OnPresetSmart(); // 「智能模式」预设:启用全部工具并关闭只读
|
||||||
|
|
||||||
DECLARE_MESSAGE_MAP()
|
DECLARE_MESSAGE_MAP()
|
||||||
|
|
||||||
@@ -47,9 +49,12 @@ private:
|
|||||||
IDC_MCP_KEY_BROWSE = 1019, // 私钥路径「浏览」按钮
|
IDC_MCP_KEY_BROWSE = 1019, // 私钥路径「浏览」按钮
|
||||||
IDC_MCP_FILEWRITE = 1020, // 「启用文件写入」复选框(删除/改名/建目录,要求只读关)
|
IDC_MCP_FILEWRITE = 1020, // 「启用文件写入」复选框(删除/改名/建目录,要求只读关)
|
||||||
IDC_MCP_BUILD = 1021, // 「启用客户端生成」复选框(build_client,要求只读关)
|
IDC_MCP_BUILD = 1021, // 「启用客户端生成」复选框(build_client,要求只读关)
|
||||||
|
IDC_MCP_PRESET_READONLY = 1022, // 「只读模式」预设按钮
|
||||||
|
IDC_MCP_PRESET_SMART = 1023, // 「智能模式」预设按钮
|
||||||
};
|
};
|
||||||
|
|
||||||
CButton m_btnEnable;
|
CButton m_btnEnable;
|
||||||
|
CButton m_btnPresetReadonly, m_btnPresetSmart; // 「启用 MCP」右侧的一键预设
|
||||||
CStatic m_lblPort, m_lblBind, m_lblToken;
|
CStatic m_lblPort, m_lblBind, m_lblToken;
|
||||||
CEdit m_editPort, m_editBind, m_editToken;
|
CEdit m_editPort, m_editBind, m_editToken;
|
||||||
CButton m_btnReadonly;
|
CButton m_btnReadonly;
|
||||||
|
|||||||
@@ -2265,3 +2265,7 @@ APK
|
|||||||
修复命令已复制到剪贴板。\n\n请按 Win+X 打开「终端(管理员)」,粘贴执行后再重新启动本程序。=Der Reparaturbefehl wurde in die Zwischenablage kopiert.\n\nDruecken Sie Win+X, oeffnen Sie Terminal (Administrator), fuegen Sie den Befehl ein und starten Sie das Programm danach neu.
|
修复命令已复制到剪贴板。\n\n请按 Win+X 打开「终端(管理员)」,粘贴执行后再重新启动本程序。=Der Reparaturbefehl wurde in die Zwischenablage kopiert.\n\nDruecken Sie Win+X, oeffnen Sie Terminal (Administrator), fuegen Sie den Befehl ein und starten Sie das Programm danach neu.
|
||||||
已复制=Kopiert
|
已复制=Kopiert
|
||||||
该 Android 主机未取得 root,无法查看进程列表。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。=Dieser Android-Host hat kein Root, daher ist die Prozessliste nicht verfuegbar.\n\nAb Android 7 ist /proc durch hidepid/SELinux eingeschraenkt; eine normale App kann keine anderen Prozesse auflisten.
|
该 Android 主机未取得 root,无法查看进程列表。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。=Dieser Android-Host hat kein Root, daher ist die Prozessliste nicht verfuegbar.\n\nAb Android 7 ist /proc durch hidepid/SELinux eingeschraenkt; eine normale App kann keine anderen Prozesse auflisten.
|
||||||
|
|
||||||
|
; MCP settings preset buttons
|
||||||
|
只读模式=Nur-Lese-Modus
|
||||||
|
智能模式=Intelligenter Modus
|
||||||
@@ -2276,3 +2276,7 @@ APK
|
|||||||
修复命令已复制到剪贴板。\n\n请按 Win+X 打开「终端(管理员)」,粘贴执行后再重新启动本程序。=The fix command has been copied to the clipboard.\n\nPress Win+X to open Terminal (Admin), paste and run it, then restart this program.
|
修复命令已复制到剪贴板。\n\n请按 Win+X 打开「终端(管理员)」,粘贴执行后再重新启动本程序。=The fix command has been copied to the clipboard.\n\nPress Win+X to open Terminal (Admin), paste and run it, then restart this program.
|
||||||
已复制=Copied
|
已复制=Copied
|
||||||
该 Android 主机未取得 root,无法查看进程列表。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。=This Android host is not rooted, so the process list is unavailable.\n\nAndroid 7+ restricts /proc with hidepid/SELinux, so a normal app cannot enumerate other processes.
|
该 Android 主机未取得 root,无法查看进程列表。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。=This Android host is not rooted, so the process list is unavailable.\n\nAndroid 7+ restricts /proc with hidepid/SELinux, so a normal app cannot enumerate other processes.
|
||||||
|
|
||||||
|
; MCP settings preset buttons
|
||||||
|
只读模式=Read-only mode
|
||||||
|
智能模式=Smart mode
|
||||||
@@ -2269,3 +2269,7 @@ APK
|
|||||||
修复命令已复制到剪贴板。\n\n请按 Win+X 打开「终端(管理员)」,粘贴执行后再重新启动本程序。=修復命令已複製到剪貼簿。\n\n請按 Win+X 開啟「終端機(系統管理員)」,貼上執行後再重新啟動本程式。
|
修复命令已复制到剪贴板。\n\n请按 Win+X 打开「终端(管理员)」,粘贴执行后再重新启动本程序。=修復命令已複製到剪貼簿。\n\n請按 Win+X 開啟「終端機(系統管理員)」,貼上執行後再重新啟動本程式。
|
||||||
已复制=已複製
|
已复制=已複製
|
||||||
该 Android 主机未取得 root,无法查看进程列表。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。=該 Android 主機未取得 root,無法查看處理程序清單。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,一般應用程式無法列舉其他處理程序。
|
该 Android 主机未取得 root,无法查看进程列表。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,普通应用无法枚举其它进程。=該 Android 主機未取得 root,無法查看處理程序清單。\n\nAndroid 7 起 /proc 受 hidepid/SELinux 限制,一般應用程式無法列舉其他處理程序。
|
||||||
|
|
||||||
|
; MCP settings preset buttons
|
||||||
|
只读模式=唯讀模式
|
||||||
|
智能模式=智慧模式
|
||||||
Reference in new issue
Block a user