fix: avoid printing base64 data for screenshot tools

This commit is contained in:
lilong.129
2025-07-11 14:02:30 +08:00
parent b7e4b38442
commit bd26884566
+19 -10
View File
@@ -156,9 +156,13 @@ func (dExt *XTDriver) ExecuteAction(ctx context.Context, action option.MobileAct
// For regular actions, collect session data and return it directly // For regular actions, collect session data and return it directly
sessionData := dExt.GetSession().GetData(true) // reset after getting data sessionData := dExt.GetSession().GetData(true) // reset after getting data
log.Debug().Str("tool", string(tool.Name())). // Log execution result, but avoid printing base64 data for screenshot tools
Interface("result", result.Content). logger := log.Debug().Str("tool", string(tool.Name()))
Msg("executed action via MCP tool") if tool.Name() != option.ACTION_ScreenShot {
logger.Interface("result", result.Content)
}
logger.Msg("executed action via MCP tool")
return sessionData, nil return sessionData, nil
} }
@@ -241,22 +245,27 @@ func (dExt *XTDriver) CallMCPTool(ctx context.Context,
log.Debug().Err(err). log.Debug().Err(err).
Str("server", serverName). Str("server", serverName).
Str("tool", toolName). Str("tool", toolName).
Msg("MCP hook call failed") Msg("call MCP tool failed")
return nil, err return nil, err
} }
if result.IsError { if result.IsError {
log.Debug(). logger := log.Debug().
Str("server", serverName). Str("server", serverName).
Str("tool", toolName). Str("tool", toolName)
Interface("content", result.Content).
Msg("MCP hook returned error") // Avoid printing base64 data for screenshot tools
return nil, fmt.Errorf("MCP hook returned error") if toolName != string(option.ACTION_ScreenShot) {
logger.Interface("content", result.Content)
}
logger.Msg("call MCP tool failed")
return nil, fmt.Errorf("call MCP tool %s failed", toolName)
} }
log.Debug(). log.Debug().
Str("server", serverName). Str("server", serverName).
Str("tool", toolName). Str("tool", toolName).
Msg("MCP hook called successfully") Msg("call MCP tool successfully")
return result, nil return result, nil
} }