From 246fdf3f33d48b7361f9623f1566a020c894a32c Mon Sep 17 00:00:00 2001 From: yuchou87 Date: Sat, 21 Feb 2026 13:40:55 +0800 Subject: [PATCH] fix(mcp): guard against nil result from CallTool CallTool can return (nil, nil) if the underlying MCP library misbehaves. Without a nil check, result.IsError would panic. Return an explicit error ToolResult instead. --- pkg/tools/mcp_tool.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/tools/mcp_tool.go b/pkg/tools/mcp_tool.go index c29ab8525..6bd3d75e3 100644 --- a/pkg/tools/mcp_tool.go +++ b/pkg/tools/mcp_tool.go @@ -119,6 +119,11 @@ func (t *MCPTool) Execute(ctx context.Context, args map[string]interface{}) *Too return ErrorResult(fmt.Sprintf("MCP tool execution failed: %v", err)).WithError(err) } + if result == nil { + nilErr := fmt.Errorf("MCP tool returned nil result without error") + return ErrorResult("MCP tool execution failed: nil result").WithError(nilErr) + } + // Handle error result from server if result.IsError { errMsg := extractContentText(result.Content)