Feature: Add get_audit_log MCP tool

Expose the server main-window audit log (host online/offline, operation
results, alerts) as a read-only, no-arg, in-memory MCP tool. The log lives
in m_CList_Message, a CListCtrl that is only safe to touch on the UI
thread, so add a thread-safe mirror m_MessageLog (guarded by m_cs) and keep
it in sync at the four item-mutation sites: ShowMessage, OnShowErrMessage,
OnMsglogDelete and OnMsglogClear. The tool reads the mirror directly under
m_cs and returns up to MAX_MESSAGE_COUNT (1000) entries, newest first.

Co-Authored-By: deepseek-v4-pro
This commit is contained in:
yuanyuanxiang
2026-08-21 20:33:59 +02:00
parent 8de5c00a39
commit 8815c4f896
3 changed files with 126 additions and 0 deletions

View File

@@ -1796,6 +1796,19 @@ VOID CMy2015RemoteDlg::ShowMessage(CString strType, CString strMsg)
m_CList_Message.SetItemText(0, 2, strMsg);
m_CList_Message.SetItemData(0, (DWORD_PTR)MsgColorLevel(strType, strMsg));
// 同步线程安全镜像,供 MCP get_audit_log 读取CListCtrl 仅 UI 线程可见)。
{
EnterCriticalSection(&m_cs);
LogMessage entry;
entry.type = strType.GetString();
entry.time = strTime.GetString();
entry.msg = strMsg.GetString();
m_MessageLog.insert(m_MessageLog.begin(), entry);
if ((int)m_MessageLog.size() > MAX_MESSAGE_COUNT)
m_MessageLog.pop_back();
LeaveCriticalSection(&m_cs);
}
CString strStatusMsg;
EnterCriticalSection(&m_cs);
@@ -1875,6 +1888,18 @@ LRESULT CMy2015RemoteDlg::OnShowErrMessage(WPARAM wParam, LPARAM lParam)
m_CList_Message.SetItemText(0, 1, strTime);
m_CList_Message.SetItemText(0, 2, strText);
m_CList_Message.SetItemData(0, (DWORD_PTR)MsgColorLevel(strTitle, strText));
// 同步线程安全镜像,供 MCP get_audit_log 读取CListCtrl 仅 UI 线程可见)。
{
EnterCriticalSection(&m_cs);
LogMessage entry;
entry.type = strTitle.GetString();
entry.time = strTime.GetString();
entry.msg = strText.GetString();
m_MessageLog.insert(m_MessageLog.begin(), entry);
if ((int)m_MessageLog.size() > MAX_MESSAGE_COUNT)
m_MessageLog.pop_back();
LeaveCriticalSection(&m_cs);
}
if(title)delete title;
if(text)delete text;
@@ -9656,6 +9681,13 @@ void CMy2015RemoteDlg::OnMsglogDelete()
for (auto it = selected.rbegin(); it != selected.rend(); ++it) {
m_CList_Message.DeleteItem(*it);
}
// 同步线程安全镜像(新在前,索引与 CListCtrl 一一对应;同样倒序避免索引变化)
EnterCriticalSection(&m_cs);
for (auto it = selected.rbegin(); it != selected.rend(); ++it) {
if (*it >= 0 && (size_t)*it < m_MessageLog.size())
m_MessageLog.erase(m_MessageLog.begin() + *it);
}
LeaveCriticalSection(&m_cs);
}
void CMy2015RemoteDlg::OnMsglogCopy() {
@@ -9693,6 +9725,10 @@ void CMy2015RemoteDlg::OnMsglogCopy() {
void CMy2015RemoteDlg::OnMsglogClear()
{
m_CList_Message.DeleteAllItems();
// 同步线程安全镜像,供 MCP get_audit_log 读取。
EnterCriticalSection(&m_cs);
m_MessageLog.clear();
LeaveCriticalSection(&m_cs);
}
void CMy2015RemoteDlg::OnMsglogSearch()