mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-19 17:50:12 +00:00
fix(mcp): accept agents reporting version without v prefix and stop masking tool errors
compareSemver fell back to lexical string ordering when the numeric
segments were equal, so an agent reporting "2.1.0" compared as older than
the gate constant "v2.1.0" (0x32 < 0x76). This wrongly flagged every agent
as unsupported_agent, breaking server.exec and fs.* on all online servers.
Drop the fallback: semverParts already strips the v prefix, so equal
numeric segments mean equal versions.
The error was further masked because tool error responses shipped a
structuredContent {error_code,error} that violates the tool outputSchema
(which requires exit_code/stdout/...). Strict MCP clients validated it and
rejected the whole response with -32602, hiding the real isError text.
Omit structuredContent on error; the cause stays in content[].text.
This commit is contained in:
@@ -27,13 +27,12 @@ func requireAgentSupportsMCP(server *model.Server) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// compareSemver 比较两个 "MAJOR.MINOR.PATCH[-suffix]" 字符串。
|
||||
// 返回 -1/0/1。无法解析时按字符串字典序比较,保证全序但可能不精确——
|
||||
// 对于 "agent 太老" 的快速失败用途已经足够。
|
||||
// compareSemver 比较两个 "MAJOR.MINOR.PATCH[-suffix]" 字符串,返回 -1/0/1。
|
||||
// semverParts 已剥掉可选的 "v" 前缀与 "-/+" 后缀,所以只按三段数字定序:
|
||||
// 数字段相等即视为相等版本。绝不能回退到字符串字典序——agent 上报 "2.1.0"
|
||||
// 而门槛常量是 "v2.1.0",'2'(0x32) < 'v'(0x76) 会把相等版本误判为更旧,
|
||||
// 导致所有 agent 被错误地判为不支持 MCP。
|
||||
func compareSemver(a, b string) int {
|
||||
if a == b {
|
||||
return 0
|
||||
}
|
||||
aparts := semverParts(a)
|
||||
bparts := semverParts(b)
|
||||
for i := 0; i < 3; i++ {
|
||||
@@ -44,12 +43,6 @@ func compareSemver(a, b string) int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
if a < b {
|
||||
return -1
|
||||
}
|
||||
if a > b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user