mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-19 09:40: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:
@@ -50,3 +50,28 @@ func TestRequireAgentSupportsMCPDefersWhenAgentNeverReported(t *testing.T) {
|
||||
require.NoError(t, requireAgentSupportsMCP(&model.Server{Host: nil}),
|
||||
"Host==nil means agent never reported its build; defer the version decision to the CallAgent timeout layer")
|
||||
}
|
||||
|
||||
func TestCompareSemverIgnoresVPrefixMismatch(t *testing.T) {
|
||||
cases := []struct {
|
||||
a, b string
|
||||
want int
|
||||
}{
|
||||
{"2.1.0", "v2.1.0", 0},
|
||||
{"v2.1.0", "2.1.0", 0},
|
||||
{"2.1.0", "2.1.0", 0},
|
||||
{"2.1.0", "v2.1.1", -1},
|
||||
{"v2.1.2", "2.1.0", 1},
|
||||
{"2.2.0", "v2.1.9", 1},
|
||||
}
|
||||
for _, c := range cases {
|
||||
require.Equalf(t, c.want, compareSemver(c.a, c.b),
|
||||
"compareSemver(%q,%q): the only difference is the optional 'v' prefix and/or numeric ordering; "+
|
||||
"a bare lexical fallback wrongly orders %q < %q", c.a, c.b, c.a, c.b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequireAgentSupportsMCPAcceptsBarePrefixReport(t *testing.T) {
|
||||
agent := &model.Server{Host: &model.Host{Version: "2.1.0"}}
|
||||
require.NoError(t, requireAgentSupportsMCP(agent),
|
||||
"agents report Host.Version without the 'v' prefix (e.g. \"2.1.0\"); it must compare equal to MCPMinAgentVersion \"v2.1.0\" and be accepted")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user