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.
This commit is contained in:
parent
fb2b594060
commit
246fdf3f33
1 changed files with 5 additions and 0 deletions
|
|
@ -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)
|
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
|
// Handle error result from server
|
||||||
if result.IsError {
|
if result.IsError {
|
||||||
errMsg := extractContentText(result.Content)
|
errMsg := extractContentText(result.Content)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue