Feature: Add instructions, capability reporting and filters to MCP
P10-A is the first batch of the next MCP phase: the server now tells a model
how it expects to be driven instead of leaving the rules to be inferred from
per-tool descriptions.
initialize carries the instructions field that MCP 2025-06-18 defines, in
five sections: where host ids come from, which switch hides which tool, what
each error code implies for the next action, typical orchestrations, and
safety. Every statement was checked against the implementation rather than
derived from the tool descriptions, and four did not survive: the host_*
family only supports name/pid filters in part (named per tool now), read-only
mode does not hide host_set_remark and host_set_watch_level (they touch only
the local host store and are refused with -32006 when called), -32003 is one
lock keyed by device id rather than one per capability, and there is no
"screen stream" tool to pick instead of get_screenshot. The string is built
from u8 literals because the project compiles with /execution-charset:.936.
get_host_detail returns a capabilities object (platform, screenPreview,
remoteControl, fileTransferV2, c2cPaths, registry), each flag tied to a gate
that already exists in the dispatcher, so a model no longer discovers a
host's limits by calling and reading -32005. remoteControl mirrors the two
conditions remote_* actually applies (Windows or Linux, and not
multi-monitor), not the preview bit. Making the flags honest exposed
list_registry rejecting only LNX and MAC, so an APK host passed and then
waited out the timeout; it now uses the same is-Windows predicate the bit is
computed from. That predicate existed as identical local copies in
McpMachine.cpp and McpChat.cpp and now lives in McpInternal.
list_processes and list_windows take an optional name and pid, filtered on
the server before the page window is applied, with total counting matches
and totalAll still reporting the unfiltered count. The two tools get their
own schema builder so list_services does not advertise a filter it would
silently ignore, and the pid descriptions differ because a pid means the
process itself for one tool and its owner for the other.
get_keylog gains set_offline and clear, the two commands the client already
implements on the keyboard sub-connection but nothing on the MCP side ever
sent, plus offlineRecord from the ready packet's byte 1. Both writes are
gated on McpReadonly=0 and validated before COMMAND_KEYBOARD goes out, so a
refused call cannot leave a running keyboard session behind; the tool's
annotations change from read-only to writable and destructive, and the
server instructions gain the matching sentence.
Four capabilities are exposed twice through two different sub-connection
chains, so each pair's descriptions now say which one to reach for first and
when the other is the only option: the host_* trio carries more fields and
filters on the server, the list_* trio is the McpMachine=0 fallback, and
operate_window is the only one that can close a window. No tool was merged:
the split is what lets McpMachine be switched off on its own. search_file's
description drops the stale MAX_PATH-overflow warning (fixed in 8f718d9) for
the behaviour that remains - the client silently skips any entry whose full
path does not fit, so a drive-root scan misses deep results and reaches the
10000-entry cap sooner.
Verified per commit by building the Debug x64 server, starting it on a spare
port so the running Release instance could not answer instead, and reading
the fields back out of real responses as UTF-8; tools/list shows 54 tools
with the edited descriptions present. Bin/settings.ini was restored
byte-exact and the Release instance was left alone. The smoke test gained
assertions for all four additions: instructions has to parse out of
initialize, capabilities is compared against the reported platform (registry
true exactly for the Windows client types, remoteControl false on macOS and
Android), the filters query a real entry back by name and by pid while
totalAll stays put, and offlineRecord accepts both a boolean and its absence
for old clients. That script ran 28 checks clean against this build, with
the host-scoped assertions exercised against synthetic responses on a
separate harness (12 of 12, including the negative cases).
Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
4a3cded174
commit
bb55f52b29
6 files changed
+331
-44
No files matched your search
@@ -113,13 +113,7 @@ std::string OptStr(const Json::Value& args, const char* key) {
|
||||
return Trim(GetStringArg(args, key));
|
||||
}
|
||||
|
||||
// Utf8ToCpExact / IsValidUtf8 由 McpInternal 提供(McpChat.cpp 共用)。
|
||||
|
||||
bool IsWindowsClient(context* ctx) {
|
||||
if (!ctx) return false;
|
||||
CString t = ctx->GetAdditionalData(RES_CLIENT_TYPE);
|
||||
return !(t == "LNX" || t == "MAC" || t == "APK");
|
||||
}
|
||||
// Utf8ToCpExact / IsValidUtf8 / IsWindowsClient 由 McpInternal 提供(McpChat.cpp 共用)。
|
||||
|
||||
std::string EndpointAddr(const std::string& ep) {
|
||||
size_t c = ep.rfind(':');
|
||||
@@ -2733,7 +2727,7 @@ void AppendTools(Json::Value& tools) {
|
||||
props["name"] = PropStr(u8"按进程名子串过滤");
|
||||
props["arch"] = PropStrEnum(u8"按架构过滤", { "x86", "x64" });
|
||||
AddTool(tools, "host_list_processes",
|
||||
u8"列出在线 Windows 主机的进程(主机管理「进程」标签页)。返回 PID、架构、窗口标题、路径、优先级、线程数、用户、工作集与文件大小。",
|
||||
u8"列出在线 Windows 主机的进程(主机管理「进程」标签页)。返回 PID、架构、窗口标题、路径、优先级、线程数、用户、工作集与文件大小。首选:与 list_processes 同源但字段更全,并支持服务端过滤(pid / name / arch),仅在它没有出现在 tools/list 里(McpMachine=0)时退回 list_processes。",
|
||||
ReadInputSchemaBatch(props), MakeListOutputSchema("processes", ProcessItemSchema()));
|
||||
}
|
||||
{
|
||||
@@ -2741,7 +2735,7 @@ void AppendTools(Json::Value& tools) {
|
||||
props["pid"] = PropInt(u8"按所属进程 PID 过滤");
|
||||
props["title"] = PropStr(u8"按窗口标题子串过滤");
|
||||
AddTool(tools, "host_list_windows",
|
||||
u8"列出在线 Windows 主机上当前可见的顶层窗口(主机管理「窗口」标签页)。只包含可见窗口,故隐藏后窗口会从结果中消失。hwnd 可用于 host_control_window。",
|
||||
u8"列出在线 Windows 主机上当前可见的顶层窗口(主机管理「窗口」标签页)。只包含可见窗口,故隐藏后窗口会从结果中消失。hwnd 可用于 host_control_window 或 operate_window。首选:支持服务端过滤(pid / title),仅在它没有出现在 tools/list 里(McpMachine=0)时退回 list_windows。",
|
||||
ReadInputSchemaBatch(props), MakeListOutputSchema("windows", WindowItemSchema()));
|
||||
}
|
||||
{
|
||||
@@ -2786,7 +2780,7 @@ void AppendTools(Json::Value& tools) {
|
||||
props["status"] = PropStr(u8"按状态子串过滤,如 Running");
|
||||
props["start_type"] = PropStr(u8"按启动类型子串过滤,如 Auto");
|
||||
AddTool(tools, "host_list_win32_services",
|
||||
u8"列出在线 Windows 主机的 Win32 服务(主机管理「服务」标签页之一)。返回显示名、描述、状态、启动类型、登录身份、服务名与可执行路径;服务名可用于 host_control_service。",
|
||||
u8"列出在线 Windows 主机的 Win32 服务(主机管理「服务」标签页之一)。返回显示名、描述、状态、启动类型、登录身份、服务名与可执行路径;服务名可用于 host_control_service。首选:支持服务端过滤(name / status),仅在它没有出现在 tools/list 里(McpMachine=0)时退回 list_services。",
|
||||
ReadInputSchemaBatch(props), MakeListOutputSchema("services", ServiceItemSchema()));
|
||||
}
|
||||
{
|
||||
@@ -2861,7 +2855,7 @@ void AppendTools(Json::Value& tools) {
|
||||
hwnd["description"] = u8"窗口句柄,取 host_list_windows 的 hwnd;整数或 0x 前缀字符串";
|
||||
props["hwnd"] = hwnd;
|
||||
AddTool(tools, "host_control_window",
|
||||
u8"对在线 Windows 主机的窗口执行可恢复操作:restore(还原)/hide(隐藏)/maximize(最大化)/minimize(最小化)。动作后重新枚举可见窗口复核:hide 后 hwnd 应消失,其余动作后仍应存在。不提供关闭窗口。",
|
||||
u8"对在线 Windows 主机的窗口执行可恢复操作:restore(还原)/hide(隐藏)/maximize(最大化)/minimize(最小化)。hwnd 取 host_list_windows 或 list_windows 返回的 hwnd。动作后重新枚举可见窗口复核:hide 后 hwnd 应消失,其余动作后仍应存在。不提供关闭窗口——需要 close / show 时改用 operate_window。",
|
||||
MakeSchema(props, { "id", "action", "hwnd" }),
|
||||
ActionOutputSchema());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user