2026-03-08 22:17:14 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
2026-03-13 23:41:59 -04:00
|
|
|
#include "MCPServer.h"
|
2026-03-08 22:17:14 -04:00
|
|
|
#include "MCPHandler.h"
|
2026-03-13 14:26:04 -04:00
|
|
|
#include "MCPAssets.h"
|
2026-03-08 22:17:14 -04:00
|
|
|
#include "MCPUtils.h"
|
|
|
|
|
#include "Engine/Blueprint.h"
|
|
|
|
|
#include "Engine/World.h"
|
|
|
|
|
#include "Engine/Level.h"
|
|
|
|
|
#include "Engine/LevelScriptBlueprint.h"
|
|
|
|
|
#include "EdGraph/EdGraphNode.h"
|
|
|
|
|
#include "K2Node_CallFunction.h"
|
|
|
|
|
#include "K2Node_Event.h"
|
|
|
|
|
#include "K2Node_CustomEvent.h"
|
|
|
|
|
#include "K2Node_VariableGet.h"
|
|
|
|
|
#include "K2Node_VariableSet.h"
|
2026-03-12 00:44:17 -04:00
|
|
|
#include "Blueprint_SearchContents.generated.h"
|
2026-03-08 22:17:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
2026-03-15 19:32:09 -04:00
|
|
|
UCLASS()
|
2026-03-12 00:44:17 -04:00
|
|
|
class UMCP_Blueprint_SearchContents : public UObject, public IMCPHandler
|
2026-03-08 22:17:14 -04:00
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
UPROPERTY(meta=(Description="Search query string to match against node titles, function names, event names, and variable names"))
|
|
|
|
|
FString Query;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Optional, Description="Filter results to blueprints whose path contains this substring"))
|
|
|
|
|
FString Path;
|
|
|
|
|
|
|
|
|
|
UPROPERTY(meta=(Optional, Description="Maximum number of results to return (default 50, max 200)"))
|
|
|
|
|
int32 MaxResults = 0;
|
|
|
|
|
|
|
|
|
|
virtual FString GetDescription() const override
|
|
|
|
|
{
|
|
|
|
|
return TEXT("Search across all Blueprint graphs for nodes matching a query string.");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 23:41:59 -04:00
|
|
|
virtual void Handle() override
|
2026-03-08 22:17:14 -04:00
|
|
|
{
|
2026-03-10 07:17:42 -04:00
|
|
|
int32 Limit = (MaxResults > 0) ? FMath::Clamp(MaxResults, 1, 200) : 50;
|
|
|
|
|
int32 Count = 0;
|
2026-03-08 22:17:14 -04:00
|
|
|
|
2026-03-10 07:17:42 -04:00
|
|
|
// Search one blueprint's nodes for the query string.
|
|
|
|
|
auto SearchBlueprint = [&](UBlueprint* BP, bool bIsLevelBP)
|
2026-03-08 22:17:14 -04:00
|
|
|
{
|
|
|
|
|
for (UEdGraphNode* Node : MCPUtils::AllNodes(BP))
|
|
|
|
|
{
|
2026-03-10 07:17:42 -04:00
|
|
|
if (Count >= Limit) return;
|
2026-03-08 22:17:14 -04:00
|
|
|
|
|
|
|
|
FString Title = Node->GetNodeTitle(ENodeTitleType::FullTitle).ToString();
|
|
|
|
|
|
|
|
|
|
FString FuncName, EventName, VarName;
|
|
|
|
|
if (auto* CF = Cast<UK2Node_CallFunction>(Node))
|
|
|
|
|
{
|
|
|
|
|
FuncName = CF->FunctionReference.GetMemberName().ToString();
|
|
|
|
|
}
|
|
|
|
|
else if (auto* Ev = Cast<UK2Node_Event>(Node))
|
|
|
|
|
{
|
|
|
|
|
EventName = Ev->EventReference.GetMemberName().ToString();
|
|
|
|
|
}
|
|
|
|
|
else if (auto* CE = Cast<UK2Node_CustomEvent>(Node))
|
|
|
|
|
{
|
|
|
|
|
EventName = CE->CustomFunctionName.ToString();
|
|
|
|
|
}
|
|
|
|
|
else if (auto* VG = Cast<UK2Node_VariableGet>(Node))
|
|
|
|
|
{
|
|
|
|
|
VarName = VG->GetVarName().ToString();
|
|
|
|
|
}
|
|
|
|
|
else if (auto* VS = Cast<UK2Node_VariableSet>(Node))
|
|
|
|
|
{
|
|
|
|
|
VarName = VS->GetVarName().ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bMatch = Title.Contains(Query, ESearchCase::IgnoreCase) ||
|
|
|
|
|
(!FuncName.IsEmpty() && FuncName.Contains(Query, ESearchCase::IgnoreCase)) ||
|
|
|
|
|
(!EventName.IsEmpty() && EventName.Contains(Query, ESearchCase::IgnoreCase)) ||
|
|
|
|
|
(!VarName.IsEmpty() && VarName.Contains(Query, ESearchCase::IgnoreCase));
|
|
|
|
|
|
2026-03-10 07:17:42 -04:00
|
|
|
if (!bMatch) continue;
|
|
|
|
|
|
|
|
|
|
Count++;
|
2026-03-13 23:41:59 -04:00
|
|
|
UMCPServer::Printf(TEXT("blueprint: %s\n"), *MCPUtils::FormatName(BP));
|
|
|
|
|
UMCPServer::Printf(TEXT(" graph: %s\n"), *MCPUtils::FormatName(Node->GetGraph()));
|
|
|
|
|
UMCPServer::Printf(TEXT(" node: %s\n"), *MCPUtils::FormatName(Node));
|
|
|
|
|
UMCPServer::Printf(TEXT(" class: %s\n"), *MCPUtils::FormatName(Node->GetClass()));
|
|
|
|
|
if (!FuncName.IsEmpty()) UMCPServer::Printf(TEXT(" function: %s\n"), *FuncName);
|
|
|
|
|
if (!EventName.IsEmpty()) UMCPServer::Printf(TEXT(" event: %s\n"), *EventName);
|
|
|
|
|
if (!VarName.IsEmpty()) UMCPServer::Printf(TEXT(" variable: %s\n"), *VarName);
|
|
|
|
|
if (bIsLevelBP) UMCPServer::Print(TEXT(" level-blueprint: true\n"));
|
|
|
|
|
UMCPServer::Print(TEXT("\n"));
|
2026-03-08 22:17:14 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-10 07:17:42 -04:00
|
|
|
// Search regular blueprints
|
2026-03-08 22:17:14 -04:00
|
|
|
MCPAssets<UBlueprint> AllBlueprints;
|
2026-03-10 07:17:42 -04:00
|
|
|
if (!Path.IsEmpty()) AllBlueprints.Substring(Path);
|
|
|
|
|
AllBlueprints.Load();
|
|
|
|
|
for (UBlueprint* BP : AllBlueprints.Objects())
|
2026-03-08 22:17:14 -04:00
|
|
|
{
|
2026-03-10 07:17:42 -04:00
|
|
|
if (Count >= Limit) break;
|
|
|
|
|
SearchBlueprint(BP, false);
|
2026-03-08 22:17:14 -04:00
|
|
|
}
|
|
|
|
|
|
2026-03-10 07:17:42 -04:00
|
|
|
// Search level blueprints
|
|
|
|
|
MCPAssets<UWorld> AllWorlds;
|
|
|
|
|
if (!Path.IsEmpty()) AllWorlds.Substring(Path);
|
|
|
|
|
AllWorlds.Load();
|
|
|
|
|
for (UWorld* World : AllWorlds.Objects())
|
2026-03-08 22:17:14 -04:00
|
|
|
{
|
2026-03-10 07:17:42 -04:00
|
|
|
if (Count >= Limit) break;
|
2026-03-08 22:17:14 -04:00
|
|
|
if (!World || !World->PersistentLevel) continue;
|
|
|
|
|
ULevelScriptBlueprint* LevelBP = World->PersistentLevel->GetLevelScriptBlueprint(false);
|
|
|
|
|
if (!LevelBP) continue;
|
2026-03-10 07:17:42 -04:00
|
|
|
SearchBlueprint(LevelBP, true);
|
2026-03-08 22:17:14 -04:00
|
|
|
}
|
|
|
|
|
|
2026-03-13 23:41:59 -04:00
|
|
|
UMCPServer::Printf(TEXT("Results: %d\n"), Count);
|
|
|
|
|
if (Count >= Limit) UMCPServer::Printf(TEXT("(limit %d reached, use MaxResults to increase)\n"), Limit);
|
2026-03-08 22:17:14 -04:00
|
|
|
}
|
|
|
|
|
};
|