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:
yuanyuanxianganddeepseek-flash committed 2026-10-25 14:31:14 +01:00
1 parent d9a1a9ebcb
commit ae37e812ee
3 files changed
+60 -12

No files matched your search

+4
View File
@@ -134,6 +134,10 @@ Check 'search_hosts 正常返回' ($found.error -eq $null -and (HasPaging $found
$audit = Rpc '' $null 'get_audit_log' @{ limit = 5 }
Check 'get_audit_log 正常返回' ($audit.error -eq $null)
Check 'get_audit_log 带分页字段' (HasPaging $audit.result.structuredContent)
Check 'get_audit_log 条数不超过 limit' (@($audit.result.structuredContent.entries).Count -le 5)
$auditFiltered = Rpc '' $null 'get_audit_log' @{ type = 'zzz-no-such-type'; limit = 5 }
Check 'get_audit_log 过滤未命中返回 0 条' ($auditFiltered.error -eq $null -and @($auditFiltered.result.structuredContent.entries).Count -eq 0)
if (-not $HostId) {
$first = @($sc.hosts)[0]