Create MCPUtils
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "BlueprintMCPServer.h"
|
||||
#include "MCPUtils.h"
|
||||
#include "Engine/Blueprint.h"
|
||||
#include "EdGraph/EdGraph.h"
|
||||
#include "EdGraph/EdGraphNode.h"
|
||||
@@ -161,7 +162,7 @@ bool FBlueprintMCPServer::SaveSnapshotToDisk(const FString& SnapshotId, const FG
|
||||
}
|
||||
Root->SetObjectField(TEXT("graphs"), GraphsObj);
|
||||
|
||||
FString JsonString = JsonToString(Root);
|
||||
FString JsonString = MCPUtils::JsonToString(Root);
|
||||
bool bSuccess = FFileHelper::SaveStringToFile(JsonString, *FilePath, FFileHelper::EEncodingOptions::ForceUTF8WithoutBOM);
|
||||
if (bSuccess)
|
||||
{
|
||||
@@ -259,7 +260,7 @@ void FBlueprintMCPServer::HandleSnapshotGraph(const FJsonObject* Json, FJsonObje
|
||||
FString BlueprintName = Json->GetStringField(TEXT("blueprint"));
|
||||
if (BlueprintName.IsEmpty())
|
||||
{
|
||||
return MakeErrorJson(Result, TEXT("Missing required field: blueprint"));
|
||||
return MCPUtils::MakeErrorJson(Result, TEXT("Missing required field: blueprint"));
|
||||
}
|
||||
|
||||
FString GraphFilter;
|
||||
@@ -270,7 +271,7 @@ void FBlueprintMCPServer::HandleSnapshotGraph(const FJsonObject* Json, FJsonObje
|
||||
UBlueprint* BP = LoadBlueprintByName(BlueprintName, LoadError);
|
||||
if (!BP)
|
||||
{
|
||||
return MakeErrorJson(Result, LoadError);
|
||||
return MCPUtils::MakeErrorJson(Result, LoadError);
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: Creating snapshot for blueprint '%s'"), *BlueprintName);
|
||||
@@ -299,7 +300,7 @@ void FBlueprintMCPServer::HandleSnapshotGraph(const FJsonObject* Json, FJsonObje
|
||||
|
||||
if (GraphsToCapture.Num() == 0 && !GraphFilter.IsEmpty())
|
||||
{
|
||||
return MakeErrorJson(Result, FString::Printf(TEXT("Graph '%s' not found in blueprint '%s'"), *GraphFilter, *BlueprintName));
|
||||
return MCPUtils::MakeErrorJson(Result, FString::Printf(TEXT("Graph '%s' not found in blueprint '%s'"), *GraphFilter, *BlueprintName));
|
||||
}
|
||||
|
||||
int32 TotalConnections = 0;
|
||||
@@ -347,7 +348,7 @@ void FBlueprintMCPServer::HandleDiffGraph(const FJsonObject* Json, FJsonObject*
|
||||
FString SnapshotId = Json->GetStringField(TEXT("snapshotId"));
|
||||
if (BlueprintName.IsEmpty() || SnapshotId.IsEmpty())
|
||||
{
|
||||
return MakeErrorJson(Result, TEXT("Missing required fields: blueprint, snapshotId"));
|
||||
return MCPUtils::MakeErrorJson(Result, TEXT("Missing required fields: blueprint, snapshotId"));
|
||||
}
|
||||
|
||||
FString GraphFilter;
|
||||
@@ -360,7 +361,7 @@ void FBlueprintMCPServer::HandleDiffGraph(const FJsonObject* Json, FJsonObject*
|
||||
{
|
||||
if (!LoadSnapshotFromDisk(SnapshotId, LoadedSnapshot))
|
||||
{
|
||||
return MakeErrorJson(Result, FString::Printf(TEXT("Snapshot '%s' not found in memory or on disk"), *SnapshotId));
|
||||
return MCPUtils::MakeErrorJson(Result, FString::Printf(TEXT("Snapshot '%s' not found in memory or on disk"), *SnapshotId));
|
||||
}
|
||||
SnapshotPtr = &LoadedSnapshot;
|
||||
}
|
||||
@@ -370,7 +371,7 @@ void FBlueprintMCPServer::HandleDiffGraph(const FJsonObject* Json, FJsonObject*
|
||||
UBlueprint* BP = LoadBlueprintByName(BlueprintName, LoadError);
|
||||
if (!BP)
|
||||
{
|
||||
return MakeErrorJson(Result, LoadError);
|
||||
return MCPUtils::MakeErrorJson(Result, LoadError);
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: Diffing blueprint '%s' against snapshot '%s'"), *BlueprintName, *SnapshotId);
|
||||
@@ -560,7 +561,7 @@ void FBlueprintMCPServer::HandleRestoreGraph(const FJsonObject* Json, FJsonObjec
|
||||
FString SnapshotId = Json->GetStringField(TEXT("snapshotId"));
|
||||
if (BlueprintName.IsEmpty() || SnapshotId.IsEmpty())
|
||||
{
|
||||
return MakeErrorJson(Result, TEXT("Missing required fields: blueprint, snapshotId"));
|
||||
return MCPUtils::MakeErrorJson(Result, TEXT("Missing required fields: blueprint, snapshotId"));
|
||||
}
|
||||
|
||||
FString GraphFilter;
|
||||
@@ -579,7 +580,7 @@ void FBlueprintMCPServer::HandleRestoreGraph(const FJsonObject* Json, FJsonObjec
|
||||
{
|
||||
if (!LoadSnapshotFromDisk(SnapshotId, LoadedSnapshot))
|
||||
{
|
||||
return MakeErrorJson(Result, FString::Printf(TEXT("Snapshot '%s' not found in memory or on disk"), *SnapshotId));
|
||||
return MCPUtils::MakeErrorJson(Result, FString::Printf(TEXT("Snapshot '%s' not found in memory or on disk"), *SnapshotId));
|
||||
}
|
||||
SnapshotPtr = &LoadedSnapshot;
|
||||
}
|
||||
@@ -589,7 +590,7 @@ void FBlueprintMCPServer::HandleRestoreGraph(const FJsonObject* Json, FJsonObjec
|
||||
UBlueprint* BP = LoadBlueprintByName(BlueprintName, LoadError);
|
||||
if (!BP)
|
||||
{
|
||||
return MakeErrorJson(Result, LoadError);
|
||||
return MCPUtils::MakeErrorJson(Result, LoadError);
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: Restoring connections from snapshot '%s' for blueprint '%s' (dryRun=%s)"),
|
||||
@@ -659,8 +660,8 @@ void FBlueprintMCPServer::HandleRestoreGraph(const FJsonObject* Json, FJsonObjec
|
||||
|
||||
// Find source and target nodes
|
||||
UEdGraph* SourceGraph = nullptr;
|
||||
UEdGraphNode* SourceNode = FindNodeByGuid(BP, Conn.SourceNodeGuid, &SourceGraph);
|
||||
UEdGraphNode* TargetNode = FindNodeByGuid(BP, Conn.TargetNodeGuid);
|
||||
UEdGraphNode* SourceNode = MCPUtils::FindNodeByGuid(BP, Conn.SourceNodeGuid, &SourceGraph);
|
||||
UEdGraphNode* TargetNode = MCPUtils::FindNodeByGuid(BP, Conn.TargetNodeGuid);
|
||||
|
||||
if (!SourceNode)
|
||||
{
|
||||
@@ -746,7 +747,7 @@ void FBlueprintMCPServer::HandleRestoreGraph(const FJsonObject* Json, FJsonObjec
|
||||
bool bSaved = false;
|
||||
if (!bDryRun && Reconnected > 0)
|
||||
{
|
||||
bSaved = SaveBlueprintPackage(BP);
|
||||
bSaved = MCPUtils::SaveBlueprintPackage(BP);
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: Restore complete — %d reconnected, %d failed, saved=%s"),
|
||||
@@ -777,7 +778,7 @@ void FBlueprintMCPServer::HandleFindDisconnectedPins(const FJsonObject* Json, FJ
|
||||
|
||||
if (BlueprintName.IsEmpty() && PathFilter.IsEmpty() && SnapshotId.IsEmpty())
|
||||
{
|
||||
return MakeErrorJson(Result, TEXT("Provide at least one of: blueprint, filter, or snapshotId"));
|
||||
return MCPUtils::MakeErrorJson(Result, TEXT("Provide at least one of: blueprint, filter, or snapshotId"));
|
||||
}
|
||||
|
||||
// Optionally load snapshot for definite-break detection
|
||||
@@ -1074,7 +1075,7 @@ void FBlueprintMCPServer::HandleAnalyzeRebuildImpact(const FJsonObject* Json, FJ
|
||||
FString ModuleName = Json->GetStringField(TEXT("moduleName"));
|
||||
if (ModuleName.IsEmpty())
|
||||
{
|
||||
return MakeErrorJson(Result, TEXT("Missing required field: moduleName"));
|
||||
return MCPUtils::MakeErrorJson(Result, TEXT("Missing required field: moduleName"));
|
||||
}
|
||||
|
||||
// Optional struct name filter
|
||||
|
||||
Reference in New Issue
Block a user