2026-03-08 22:17:14 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "MCPHandler.h"
|
|
|
|
|
#include "MCPAssetFinder.h"
|
|
|
|
|
#include "MCPServer.h"
|
|
|
|
|
#include "MCPUtils.h"
|
|
|
|
|
#include "Engine/Blueprint.h"
|
|
|
|
|
#include "EdGraph/EdGraph.h"
|
|
|
|
|
#include "Kismet2/BlueprintEditorUtils.h"
|
|
|
|
|
#include "UObject/UObjectIterator.h"
|
|
|
|
|
#include "UMCPHandler_RemoveBlueprintInterface.generated.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
UCLASS()
|
|
|
|
|
class UMCPHandler_RemoveBlueprintInterface : public UObject, public IMCPHandler
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
UPROPERTY(meta=(Description="Blueprint name or package path"))
|
|
|
|
|
FString Blueprint;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Description="Interface name to remove"))
|
|
|
|
|
FString InterfaceName;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Optional, Description="If true, keep the function graphs as regular functions"))
|
|
|
|
|
bool PreserveFunctions = false;
|
|
|
|
|
|
|
|
|
|
virtual FString GetDescription() const override
|
|
|
|
|
{
|
|
|
|
|
return TEXT("Remove a Blueprint Interface implementation from a Blueprint. "
|
|
|
|
|
"Optionally preserve the function graphs as regular functions.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void Handle(const FJsonObject* Json, FJsonObject* Result) override
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
MCPAssets<UBlueprint> Assets;
|
|
|
|
|
if (!Assets.Exact(Blueprint).Errors(Result).ENone().ETwo().Load()) return;
|
|
|
|
|
UBlueprint* BP = Assets.Object();
|
|
|
|
|
|
|
|
|
|
// Find the interface in ImplementedInterfaces by name (case-insensitive)
|
|
|
|
|
UClass* FoundInterface = nullptr;
|
|
|
|
|
for (const FBPInterfaceDescription& IfaceDesc : BP->ImplementedInterfaces)
|
|
|
|
|
{
|
|
|
|
|
if (!IfaceDesc.Interface)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString ClassName = IfaceDesc.Interface->GetName();
|
|
|
|
|
if (ClassName.Equals(InterfaceName, ESearchCase::IgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
FoundInterface = IfaceDesc.Interface;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Strip "_C" suffix for comparison
|
|
|
|
|
FString TrimmedName = ClassName;
|
|
|
|
|
if (TrimmedName.EndsWith(TEXT("_C")))
|
|
|
|
|
{
|
|
|
|
|
TrimmedName = TrimmedName.LeftChop(2);
|
|
|
|
|
}
|
|
|
|
|
if (TrimmedName.Equals(InterfaceName, ESearchCase::IgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
FoundInterface = IfaceDesc.Interface;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!FoundInterface)
|
|
|
|
|
{
|
|
|
|
|
// Build helpful error with list of implemented interfaces
|
|
|
|
|
TArray<TSharedPtr<FJsonValue>> IfaceList;
|
|
|
|
|
for (const FBPInterfaceDescription& IfaceDesc : BP->ImplementedInterfaces)
|
|
|
|
|
{
|
|
|
|
|
if (IfaceDesc.Interface)
|
|
|
|
|
{
|
2026-03-10 01:42:43 -04:00
|
|
|
IfaceList.Add(MakeShared<FJsonValueString>(MCPUtils::FormatName(IfaceDesc.Interface)));
|
2026-03-08 22:17:14 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MCPUtils::MakeErrorJson(Result, FString::Printf(
|
|
|
|
|
TEXT("Interface '%s' is not implemented by Blueprint '%s'"),
|
|
|
|
|
*InterfaceName, *Blueprint));
|
|
|
|
|
Result->SetArrayField(TEXT("implementedInterfaces"), IfaceList);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FTopLevelAssetPath InterfacePath = FoundInterface->GetClassPathName();
|
|
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: Removing interface '%s' from Blueprint '%s' (preserveFunctions: %s)"),
|
2026-03-10 01:42:43 -04:00
|
|
|
*MCPUtils::FormatName(FoundInterface), *Blueprint, PreserveFunctions ? TEXT("true") : TEXT("false"));
|
2026-03-08 22:17:14 -04:00
|
|
|
|
|
|
|
|
FBlueprintEditorUtils::RemoveInterface(BP, InterfacePath, PreserveFunctions);
|
|
|
|
|
|
|
|
|
|
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(BP);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: Removed interface '%s' from '%s'"),
|
2026-03-10 01:42:43 -04:00
|
|
|
*MCPUtils::FormatName(FoundInterface), *Blueprint);
|
2026-03-08 22:17:14 -04:00
|
|
|
|
2026-03-10 01:42:43 -04:00
|
|
|
Result->SetStringField(TEXT("interfaceName"), MCPUtils::FormatName(FoundInterface));
|
2026-03-08 22:17:14 -04:00
|
|
|
}
|
|
|
|
|
};
|