Feature: Page and filter the MCP audit log tool
get_audit_log used to hand back every entry in the main window's message mirror on each call. The mirror is a 1000-entry ring buffer, so a busy server returned a lot of text the caller never looked at, and there was no way to ask for just the MCP entries or just the ones mentioning a particular subject. The tool now takes the same limit/offset pair as the other list tools and two optional substring filters: type matches the type column and keyword matches the message text, both case-insensitive. Filtering runs before paging, so total counts the matches while totalAll keeps the size of the whole mirror, and the summary line adds the pre-filter count when a filter is in use so a typo is easy to spot. The GBK to UTF-8 conversion moved into the filter loop so the comparison happens between strings in the same encoding, still under the dialog's critical section. The output schema gains total/totalAll/offset/limit/hasMore, and the smoke test now asserts the paging fields, the limit bound and an empty result for a filter that cannot match, bringing it to 23 checks. Verified on the Debug instance: limit=2 returns entries 1-2 then 3-4 with hasMore set, offset=999 reports the out-of-range text, type=mcp matches the "MCP命令执行" entry, type=提示 matches both hint types and keyword=监听 matches the listening-port line. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
d9a1a9ebcb
commit
ae37e812ee
3 files changed
+60
-12
No files matched your search
@@ -1122,6 +1122,7 @@ Json::Value BuildAuditLogOutputSchema() {
|
||||
items["properties"] = itemProps;
|
||||
entriesProp["items"] = items;
|
||||
props["entries"] = entriesProp;
|
||||
AppendPageOutputProps(props);
|
||||
|
||||
Json::Value schema(Json::objectValue);
|
||||
schema["type"] = "object";
|
||||
@@ -1528,11 +1529,21 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "get_audit_log";
|
||||
tool["description"] = u8"获取 YAMA 服务端主界面的消息/审计日志(主机上线/下线、操作结果、告警等)。返回列表内当前全部条目(最多 1000 条,新在前)。只读、纯内存。";
|
||||
tool["description"] = u8"获取 YAMA 服务端主界面的消息/审计日志(主机上线/下线、操作结果、告警等),按 limit/offset 分页(新在前,服务端只保留最近 1000 条)。可选 type 按类型列做不区分大小写的子串过滤(如 MCP、主机),keyword 按正文字串过滤;过滤在分页之前生效,total 为命中条数、totalAll 为镜像里的全部条数。只读、纯内存。";
|
||||
|
||||
Json::Value inputSchema(Json::objectValue);
|
||||
inputSchema["type"] = "object";
|
||||
inputSchema["properties"] = Json::Value(Json::objectValue);
|
||||
Json::Value props(Json::objectValue);
|
||||
Json::Value typeProp(Json::objectValue);
|
||||
typeProp["type"] = "string";
|
||||
typeProp["description"] = u8"类型列的子串过滤,不区分大小写(如 MCP、主机上线)。省略则不过滤。";
|
||||
props["type"] = typeProp;
|
||||
Json::Value kwProp(Json::objectValue);
|
||||
kwProp["type"] = "string";
|
||||
kwProp["description"] = u8"正文子串过滤,不区分大小写(如 445、timeout)。省略则不过滤。";
|
||||
props["keyword"] = kwProp;
|
||||
AppendPagingProps(props);
|
||||
inputSchema["properties"] = props;
|
||||
inputSchema["required"] = Json::Value(Json::arrayValue);
|
||||
tool["inputSchema"] = inputSchema;
|
||||
|
||||
@@ -2700,33 +2711,51 @@ std::string BuildGetClientLog(const Json::Value& id, const Json::Value& args, CM
|
||||
}
|
||||
|
||||
// tools/call:get_audit_log(服务端本地消息日志,读取 UI 日志列表的线程安全镜像)
|
||||
std::string BuildGetAuditLog(const Json::Value& id, CMy2015RemoteDlg* parent) {
|
||||
Json::Value entries(Json::arrayValue);
|
||||
std::string BuildGetAuditLog(const Json::Value& id, const Json::Value& args, CMy2015RemoteDlg* parent) {
|
||||
std::string fType = GetStringArg(args, "type");
|
||||
std::string fKeyword = GetStringArg(args, "keyword");
|
||||
|
||||
Json::Value all(Json::arrayValue);
|
||||
int rawCount = 0;
|
||||
if (parent) {
|
||||
EnterCriticalSection(&parent->m_cs);
|
||||
// m_MessageLog 新在前、旧在后(与界面一致),直接顺序输出。
|
||||
// 镜像本身有 1000 条环形上限(MAX_MESSAGE_COUNT),过滤与分页都在内存里做,代价可忽略。
|
||||
for (const auto& e : parent->m_MessageLog) {
|
||||
std::string ty = ToUtf8(e.type.c_str(), 936);
|
||||
std::string tm = ToUtf8(e.time.c_str(), 936);
|
||||
std::string ms = ToUtf8(e.msg.c_str(), 936);
|
||||
rawCount++;
|
||||
if (!fType.empty() && !ContainsCI(ty, fType)) continue;
|
||||
if (!fKeyword.empty() && !ContainsCI(ms, fKeyword)) continue;
|
||||
Json::Value item(Json::objectValue);
|
||||
item["type"] = ToUtf8(e.type.c_str(), 936);
|
||||
item["time"] = ToUtf8(e.time.c_str(), 936);
|
||||
item["msg"] = ToUtf8(e.msg.c_str(), 936);
|
||||
entries.append(item);
|
||||
item["type"] = ty;
|
||||
item["time"] = tm;
|
||||
item["msg"] = ms;
|
||||
all.append(item);
|
||||
}
|
||||
LeaveCriticalSection(&parent->m_cs);
|
||||
}
|
||||
|
||||
int count = (int)entries.size();
|
||||
PageWindow page = ResolvePageWindow(args);
|
||||
Json::Value entries;
|
||||
ApplyPageWindow(all, page, entries);
|
||||
page.totalAll = rawCount; // 过滤前的总条数:total 是命中数,totalAll 是镜像里全部条数
|
||||
|
||||
Json::Value result(Json::objectValue);
|
||||
Json::Value structuredContent(Json::objectValue);
|
||||
structuredContent["entries"] = entries;
|
||||
WritePageFields(structuredContent, page);
|
||||
result["structuredContent"] = structuredContent;
|
||||
|
||||
std::string text = PageSummary(page, u8"条日志");
|
||||
if (!fType.empty() || !fKeyword.empty())
|
||||
text += std::string(u8"过滤前共 ") + std::to_string(rawCount) + std::string(u8" 条。");
|
||||
|
||||
Json::Value content(Json::arrayValue);
|
||||
Json::Value item(Json::objectValue);
|
||||
item["type"] = "text";
|
||||
item["text"] = count > 0 ? std::string(u8"共 ") + std::to_string(count) + std::string(u8" 条日志。")
|
||||
: std::string(u8"当前无日志。");
|
||||
item["text"] = text;
|
||||
content.append(item);
|
||||
result["content"] = content;
|
||||
result["isError"] = false;
|
||||
@@ -5814,7 +5843,7 @@ std::string DispatchSingleHostTool(const Json::Value& id, const std::string& too
|
||||
if (toolName == "list_services") return BuildListServices(id, args, parent);
|
||||
if (toolName == "get_client_log") return BuildGetClientLog(id, args, parent);
|
||||
if (toolName == "get_keylog") return BuildGetKeylog(id, args, parent);
|
||||
if (toolName == "get_audit_log") return BuildGetAuditLog(id, parent);
|
||||
if (toolName == "get_audit_log") return BuildGetAuditLog(id, args, parent);
|
||||
if (toolName == "list_registry") return BuildListRegistry(id, args, parent);
|
||||
if (toolName == "exec_command") return BuildExecCommand(id, args, parent);
|
||||
if (toolName == "terminal_open") return BuildTerminalOpen(id, args, parent);
|
||||
|
||||
Reference in new issue
Block a user