Feature: Turn client failure reports into branchable MCP errors
Wire the four new failure tokens into MessageHandle and translate them in the tool builders, so the three previously silent failures now return a code an agent can branch on: list_services on a non-elevated client is -32010 in well under a second instead of a 20 s timeout, list_files and list_registry distinguish a missing path or key (-32009) from an empty one, and download_file no longer waits for the stall watchdog when the remote path does not exist. Access denied gets its own code, -32010, and the win32 code is kept in the message for every case. TakeRegError fills both registry wait flags in one packet because a failing client sends no subkey or value packet at all. OnDownloadError sets the session error without cancelling the file-manager sub-connection, which stays owned by ClearFileTransfer. ListRemoteTopLevelNames treats "not found" as "directory not created yet" so uploading into a fresh directory keeps working now that the client reports it. Also converge the error codes that were overloaded: a multi-monitor host is a capability limit, not a parameter mistake, so remote_open reports -32005 instead of -32008. The tool wait timeout moves from a compile-time constant to McpToolTimeoutMs in settings.ini (default 20000, clamped to 1-600 s), which makes it possible to tune without a rebuild. The smoke test gains the three reproducible negatives. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
315a0855dc
commit
3b1626f415
4 files changed
+211
-25
No files matched your search
@@ -250,6 +250,31 @@ if (-not $SkipHost) {
|
||||
Check '批量 results 覆盖全部 id' (@($bs.results).Count -eq 2 -and [int]$bs.succeeded -eq 1 -and [int]$bs.failed -eq 1)
|
||||
}
|
||||
|
||||
# ===== 4b. 结构化失败(新客户端:TOKEN_*_ERROR → -32009/-32010) =====
|
||||
# 老客户端没有这些回报包,对应工具会退化成「成功 + 空列表」或超时——
|
||||
# 所以这三条只对「新客户端」成立;失败时先确认目标机客户端是否已升级。
|
||||
if (-not $SkipHost -and $drive) {
|
||||
Write-Host "`n[4b] 结构化失败"
|
||||
$ghostDir = $drive.TrimEnd('\') + '\mcp_smoke_no_such_dir_xyz'
|
||||
$lf = Rpc '' $null 'list_files' @{ id = $HostId; path = $ghostDir }
|
||||
Check 'list_files 不存在路径返回 -32009' `
|
||||
($lf.error -and [int]$lf.error.code -eq -32009) ([string]$lf.error.message)
|
||||
|
||||
$lr = Rpc '' $null 'list_registry' @{ id = $HostId; path = 'HKEY_LOCAL_MACHINE\SOFTWARE\MCPSmokeNoSuchKey_xyz' }
|
||||
Check 'list_registry 不存在键返回 -32009' `
|
||||
($lr.error -and [int]$lr.error.code -eq -32009) ([string]$lr.error.message)
|
||||
|
||||
if (@($tools | Where-Object { $_.name -eq 'download_file' }).Count -gt 0) {
|
||||
$dlDir = Join-Path $env:TEMP 'mcp_smoke_dl'
|
||||
$dl = Rpc '' $null 'download_file' @{ id = $HostId; remote_path = ($ghostDir + '\a.txt'); local_dir = $dlDir }
|
||||
Check 'download_file 不存在路径返回 -32009' `
|
||||
($dl.error -and [int]$dl.error.code -eq -32009) ([string]$dl.error.message)
|
||||
Remove-Item -LiteralPath $dlDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
Write-Host " download_file 未开启(McpFileTransfer),跳过下载负例。" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
# ===== 5. 策略拒绝(-32006) =====
|
||||
# 只在某个开关确实关闭时才有意义,所以先读 get_server_status 的 switches 再挑一个关着的功能。
|
||||
# 全部开启时跳过(不算失败)——这条不是每次都能测,但测到时能证明拒绝路径与审计都还在。
|
||||
|
||||
Reference in new issue
Block a user