Fix: Expose tool payloads in the content text block
List and query tools put only a human summary in content and kept the real payload in structuredContent. Clients that hand just content to the model (WorkBuddy does) therefore never saw a host id: search_hosts answered "1 host matched" and every follow-up tool was out of reach, and guessed ids 1-3100 could never work because host ids are 64-bit snowflake values. BuildResult now appends the serialized structuredContent as a second text block, as the MCP spec recommends for tools with structured output. The append sits in the single result choke point, so every tool in McpServer, McpMachine and McpChat gains it, including future ones; empty action results such as remote_mouse keep their bare "ok". Tools whose text already carries the payload expose only the difference: exec_command and terminal_exec add exit_code, get_keylog adds counters, get_activity_history exposes records without the duplicated raw dump, and the hosts file reader drops its copy of the content. The override rides in a $ key that BuildResult consumes and removes, so responses change only by the extra block. Verified on a Debug instance: list_all_hosts, search_hosts, get_server_status and list_registry return parseable JSON in content[1] with ids intact, and tools/mcp_smoke.ps1 -SkipHost passes 27/27 with four new assertions. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
a7dd86ff0f
commit
27d40f5678
6 files changed
+153
-5
No files matched your search
@@ -86,6 +86,18 @@ function HasPaging($obj) {
|
||||
return $true
|
||||
}
|
||||
|
||||
# 结果外露(docs/Mcp_Design.md §14):content 末尾必须有一个可解析的 JSON 文本块,
|
||||
# 内容与 structuredContent 对应。只读 content 的客户端(WorkBuddy)靠它拿到 id。
|
||||
function HasJsonText($rpc) {
|
||||
if ($null -eq $rpc -or $null -eq $rpc.result) { return $false }
|
||||
$c = @($rpc.result.content)
|
||||
if ($c.Count -lt 2) { return $false }
|
||||
$last = $c[$c.Count - 1]
|
||||
if ($last.type -ne 'text' -or [string]::IsNullOrEmpty($last.text)) { return $false }
|
||||
try { $null = $last.text | ConvertFrom-Json } catch { return $false }
|
||||
return $true
|
||||
}
|
||||
|
||||
Write-Host "MCP smoke test -> $Base"
|
||||
if (-not $Token) {
|
||||
Write-Host "缺少 token:请设置环境变量 YAMA_MCP_TOKEN 或传 -Token。" -ForegroundColor Red
|
||||
@@ -153,9 +165,15 @@ Check 'list_online_hosts 过滤后 totalAll 仍是全部在线数' ([int]$noMatc
|
||||
|
||||
$all = Rpc '' $null 'list_all_hosts' @{ limit = 5 }
|
||||
Check 'list_all_hosts 带分页字段' (HasPaging $all.result.structuredContent)
|
||||
Check 'list_all_hosts 的 content 附带结构化 JSON' (HasJsonText $all)
|
||||
$allJson = $null
|
||||
if (HasJsonText $all) { $allJson = $all.result.content[-1].text | ConvertFrom-Json }
|
||||
Check 'content 的 JSON 里能取到主机 id(串联下一跳)' ($null -eq $allJson -or
|
||||
@($allJson.hosts).Count -eq 0 -or [string]$allJson.hosts[0].id -ne '')
|
||||
|
||||
$found = Rpc '' $null 'search_hosts' @{ query = ''; limit = 5 }
|
||||
Check 'search_hosts 正常返回' ($found.error -eq $null -and (HasPaging $found.result.structuredContent))
|
||||
Check 'search_hosts 的 content 附带结构化 JSON' (HasJsonText $found)
|
||||
|
||||
$audit = Rpc '' $null 'get_audit_log' @{ limit = 5 }
|
||||
Check 'get_audit_log 正常返回' ($audit.error -eq $null)
|
||||
@@ -172,6 +190,7 @@ if ($Base -match ':(\d+)(/|$)') { $basePort = [int]$Matches[1] }
|
||||
Check 'get_server_status 版本/端口/开关齐全' `
|
||||
([string]$st.version -ne '' -and [int]$st.port -eq $basePort -and $null -ne $st.switches -and $null -ne $st.sessions)
|
||||
Check 'get_server_status 不含 token' (($st | ConvertTo-Json -Depth 6) -notmatch '(?i)token')
|
||||
Check 'get_server_status 的 content 附带结构化 JSON' (HasJsonText $status)
|
||||
|
||||
if (-not $HostId) {
|
||||
$first = @($sc.hosts)[0]
|
||||
|
||||
Reference in new issue
Block a user