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
+3 -4
View File
@@ -327,13 +327,12 @@ func handleToolsCall(c *gin.Context, req *jsonRPCRequest, tok *model.APIToken) {
})
return
}
// 错误结果不带 structuredContent:严格客户端会拿它去校验工具声明的
// outputSchema(要求 exit_code/stdout/... 等成功字段),缺字段就整条
// 响应报 -32602,把真正的 isError 文本掩盖掉。错误信息走 content[].text。
writeJSONRPCResult(c, req.ID, mcpToolCallResult{
Content: []mcpContent{{Type: "text", Text: errMsg}},
IsError: true,
StructuredContent: map[string]string{
"error_code": errCode,
"error": errMsg,
},
})
}