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:
naiba
2026-05-31 16:18:57 +00:00
parent 9b5199ac6c
commit bb38a9d4d2
4 changed files with 100 additions and 16 deletions
@@ -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")
}