2.4 KiB
UMCPHandler_RestoreAsset - Refactoring Notes
What was changed
-
Switched from JSON to plain-text output. The handler now overrides
Handle(Json, FStringBuilderBase&)instead ofHandle(Json, FJsonObject*). Error messages useResult.Appendf("ERROR: ...")instead ofMCPUtils::MakeErrorJson. Success output is a single concise line. -
Removed unnecessary includes. Stripped out
MCPAssetFinder.h,Engine/Blueprint.h,Kismet2/BlueprintEditorUtils.h,UObject/SavePackage.h,AssetRegistry/AssetRegistryModule.h,AssetRegistry/IAssetRegistry.h,AssetToolsModule.h, andIAssetTools.h-- none of these were used by the handler. -
Added reload failure reporting. The original handler silently ignored
ReloadPackagesfailures. Now it checksbReloadedand reports a WARNING with the error message if the reload fails. The file is still restored on disk in that case, so it's a warning rather than an error. -
Improved error message for copy failure. Changed from showing the raw disk path to showing the package path, which is what the caller knows and cares about.
What looks good
- The handler is simple and focused: it does one thing (restore from backup) and does it clearly.
- The flow is linear with early returns, keeping nesting shallow.
- No UE_LOG calls were present in the original, so none needed removal.
What was left alone / areas of uncertainty
-
No use of MCPFetcher or MCPAssetFinder. This handler operates on raw file paths (
.uassetand.uasset.bak), not on loaded UObjects. MCPFetcher and MCPAssetFinder are designed for navigating loaded assets and the asset registry, which doesn't apply here. The handler correctly usesFPackageName::LongPackageNameToFilenameto convert the package path to a disk path. -
No FormatName/Identifies usage. The handler's input is a package path string (e.g.
/Game/Widgets/WB_Hotkeys), not an object reference that would benefit from FormatName. The output just echoes the package path, which is the natural identifier for this operation. -
Batching was not added. Restoring multiple assets at once seems like an unusual operation -- typically you restore one asset at a time. Could be reconsidered if there's a use case.
-
The
ReloadPackagescall usesAssumePositivefor the interaction mode. This suppresses any editor dialogs. This seems correct for an MCP handler (no human is watching), but I left it as-is since I'm not 100% sure about the implications.