Feature: Add offline hosts, batch reads and MCP hardening

Expose hosts the server already knows about. list_all_hosts enumerates
both live contexts and the historical records in the client list, with
authStatus as a three-state string instead of a boolean. search_hosts
now honours online=false instead of returning an empty list, while the
default stays online-only so existing callers see the same results.
get_host_detail falls back to the last known record for an offline host
rather than failing with -32002.

Let read-only tools take an ids array of up to 50 hosts in one call.
The batch path reuses the single-host dispatcher and pages per host, so
behaviour cannot drift; write tools reject ids with -32602 so a mistake
cannot fan out across machines.

Add get_keylog behind its own McpKeylog switch. It drives the client's
existing keylogger sub-connection, accumulates the streamed text for a
bounded window and byte cap, then closes the sub-connection and returns
UTF-8 lines. The client pushes its buffered history first, so a result
contains both history and fresh keystrokes; the tool description says so.

Harden the endpoint. Failed bearer checks are counted per source IP and
ten failures within a minute block the IP for fifteen minutes. Auth
failures and tool calls append to logs\mcp_audit.log with metadata only:
no token, no arguments, no response bodies, and rotation at 5 MB. Loopback
sources are audited but never blocked, because the built-in frp tunnel
makes every remote request arrive from 127.0.0.1 and banning that address
would lock out legitimate clients along with the attacker.

Give list-style tools one pagination contract (limit/offset plus
total/totalAll/hasMore) and fix the generated schemas so id and ids are
genuine alternatives: the stale required:[id] left over from the
single-host schema would otherwise reject ids-only calls.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-10-25 12:44:45 +01:00
1 parent cc0e4bbd7a
commit ac5b174b5f
12 files changed
+1191 -86

No files matched your search

+36
View File
@@ -68,4 +68,40 @@ void AuditManageAction(CMy2015RemoteDlg* parent, uint64_t devId,
void AuditChatAction(CMy2015RemoteDlg* parent, uint64_t devId,
const std::string& tool, const std::string& detail);
// ===== 列表输出治理 =====
//
// 列表类工具统一走 limit/offset:默认 limit=100,硬上限 1000,offset 默认 0。
// structuredContent 里同时给出 total/totalAll/offset/limit/hasMore,与
// McpMachine.cpp 的 host_list_*/list_network_connections 保持同一套字段,
// 调用方据此翻页,而不是让一次返回把上下文撑爆。
struct PageWindow {
int offset = 0;
int limit = 100;
int total = 0; // ApplyPageWindow 填入:切片前的总条数(本工具无二次过滤,故等于 totalAll)
int totalAll = 0;
int returned = 0; // 本次实际返回条数
bool hasMore = false; // 窗口之后还有条目(供调用方判断是否继续翻页)
};
// 读 args 里的 limit/offset(缺省/非法/非正数按默认值,limit 超上限截断到上限)。
PageWindow ResolvePageWindow(const Json::Value& args, int defaultLimit = 100, int maxLimit = 1000);
// 按窗口切片:out = all[offset, offset+limit),并回填 w.total/totalAll/returned/hasMore。
void ApplyPageWindow(const Json::Value& all, PageWindow& w, Json::Value& out);
// 把 total/totalAll/offset/limit/hasMore 写进 structuredContent。
void WritePageFields(Json::Value& structuredContent, const PageWindow& w);
// 往 inputSchema 的 properties 追加 limit / offset 两个字段。
void AppendPagingProps(Json::Value& props, int defaultLimit = 100, int maxLimit = 1000);
// 往 inputSchema 的 properties 追加 ids(只读工具的批量入口,最多 50 个 id)。
void AppendBatchIdsProp(Json::Value& props);
// 把 inputSchema 的必填约束改成「id 或 ids 二选一」。
void MakeIdOrIdsRequired(Json::Value& schema);
// 统一的提示文字,例如「共 283 个进程,本次返回第 1-100 条(还有更多,可用 offset 继续取)。」
std::string PageSummary(const PageWindow& w, const char* unit);
} // namespace McpInternal