Fix(mcp): put listing rows and host ids into text blocks
MCP clients that surface only content[].text saw just count summaries from list_hosts and get_audit_log; the 64-bit host id lived only in structuredContent. Without the id, read_file, get_host_detail and terminal_exec cannot be addressed, so the tools were unusable from those clients. Append a tab-separated table after the summary for every list-shaped local tool: list_hosts (id first, then name/ip/group/os/online/clientType/ last_seen), get_audit_log (time/type/msg), list_files (drives and directory entries) and get_host_detail (compact host JSON; id/ok/detail rows for a batch call). Only the returned page is rendered, cells are flattened to one line, and the truncation note stays on its own line before the table. structuredContent is unchanged and remains the authoritative copy. Tests cover row contents, paging, escaping and truncation ordering; a live run against a Debug client confirmed the id is now visible in text. The MFC server needs no equivalent change: BuildResult already appends the full structuredContent as a second text item, so text-only clients there already receive host ids. Go's envelope emits a single text item, which is why the rows go into it. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
70556391dd
commit
3d18b2119a
5 files changed
+197
-4
No files matched your search
@@ -304,6 +304,10 @@ func TestListFilesDrives(t *testing.T) {
|
||||
if !strings.Contains(c.res.Content[0].Text, "共 2 个驱动器") {
|
||||
t.Fatalf("summary = %q", c.res.Content[0].Text)
|
||||
}
|
||||
if !strings.Contains(c.res.Content[0].Text, "drive\ttypeName\tfileSystem\ttotalMB\tfreeMB") ||
|
||||
!strings.Contains(c.res.Content[0].Text, "C:\\\t本地磁盘\tNTFS\t500000\t123456") {
|
||||
t.Fatalf("text = %q, want drive rows", c.res.Content[0].Text)
|
||||
}
|
||||
|
||||
// A drive-only listing still leaves the sub-conn to be retired.
|
||||
if got := r.next(sub); !bytes.Equal(got, []byte{protocol.CommandBye}) {
|
||||
@@ -376,6 +380,15 @@ func TestListFilesDirectory(t *testing.T) {
|
||||
!strings.Contains(c.res.Content[0].Text, "第 2-3 条") {
|
||||
t.Fatalf("summary = %q", c.res.Content[0].Text)
|
||||
}
|
||||
if !strings.Contains(c.res.Content[0].Text, "name\tisDir\tsize\tmtime") ||
|
||||
!strings.Contains(c.res.Content[0].Text, "a.txt\tfalse\t12345\t1700000000") ||
|
||||
!strings.Contains(c.res.Content[0].Text, "中文文档.docx\tfalse\t5368709120\t1600000000") {
|
||||
t.Fatalf("text = %q, want file rows for the returned page", c.res.Content[0].Text)
|
||||
}
|
||||
// The page window (offset 1) applies to the table as well.
|
||||
if strings.Contains(c.res.Content[0].Text, "子目录") {
|
||||
t.Fatalf("text = %q, offset-skipped entry leaked into the table", c.res.Content[0].Text)
|
||||
}
|
||||
|
||||
if got := r.next(sub); !bytes.Equal(got, []byte{protocol.CommandBye}) {
|
||||
t.Fatalf("retire wire = %v, want COMMAND_BYE", got)
|
||||
@@ -713,6 +726,10 @@ func TestListFilesTruncationNote(t *testing.T) {
|
||||
if !strings.Contains(c.res.Content[0].Text, "只解析了前") {
|
||||
t.Fatalf("summary does not mention the cap: %q", c.res.Content[0].Text)
|
||||
}
|
||||
// The note must stay on its own line, before the table.
|
||||
if !strings.Contains(c.res.Content[0].Text, "。\nname\tisDir\tsize\tmtime\n") {
|
||||
t.Fatalf("truncation note glued to the table: %q", c.res.Content[0].Text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFileListEntryCap(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user