More work on MCP core infrastructure

This commit is contained in:
2026-03-14 01:52:09 -04:00
parent e33bfefec7
commit a29eba3e4d
2 changed files with 26 additions and 8 deletions

View File

@@ -39,12 +39,26 @@ void MCPFetcher::PrintDocs()
} }
void MCPFetcher::SetObj(UObject* InObj) { UMCPServer::AddTouchedObject(InObj); Obj = InObj; ResultPin = nullptr; } void MCPFetcher::SetObj(UObject* InObj)
void MCPFetcher::SetPin(UEdGraphPin* InPin) { ResultPin = InPin; Obj = nullptr; } {
UMCPServer::AddTouchedObject(InObj);
Obj = InObj;
ResultPin = nullptr;
}
void MCPFetcher::SetPin(UEdGraphPin* InPin)
{
ResultPin = InPin;
Obj = nullptr;
}
MCPFetcher& MCPFetcher::SetError() MCPFetcher& MCPFetcher::SetError()
{ {
bError = true; bError = true;
Obj = nullptr;
ResultPin = nullptr;
OriginalAsset = nullptr;
Editor = nullptr;
return *this; return *this;
} }
@@ -60,8 +74,6 @@ MCPFetcher& MCPFetcher::TypeMismatch(const TCHAR* Walker, const TCHAR* Expected)
return *this; return *this;
} }
MCPFetcher& MCPFetcher::Walk(const FString& Path) MCPFetcher& MCPFetcher::Walk(const FString& Path)
{ {
if (bError) return *this; if (bError) return *this;
@@ -102,6 +114,8 @@ MCPFetcher& MCPFetcher::Walk(const FString& Path)
MCPFetcher& MCPFetcher::Asset(const FString& PackagePath) MCPFetcher& MCPFetcher::Asset(const FString& PackagePath)
{ {
if (bError) return *this;
SetObj(LoadObject<UObject>(nullptr, *PackagePath)); SetObj(LoadObject<UObject>(nullptr, *PackagePath));
if (!Obj) if (!Obj)
{ {
@@ -118,7 +132,6 @@ MCPFetcher& MCPFetcher::Asset(const FString& PackagePath)
UMCPServer::Printf(TEXT("ERROR: Could not open editor for '%s'\n"), *PackagePath); UMCPServer::Printf(TEXT("ERROR: Could not open editor for '%s'\n"), *PackagePath);
return SetError(); return SetError();
} }
Editor = Sub->FindEditorForAsset(OriginalAsset, false); Editor = Sub->FindEditorForAsset(OriginalAsset, false);
if (!Editor) if (!Editor)
{ {

View File

@@ -30,8 +30,8 @@ struct FWalker;
// If any step fails, the MCPFetcher will print an error // If any step fails, the MCPFetcher will print an error
// message that can be seen by the MCP's caller. It will // message that can be seen by the MCP's caller. It will
// also set an error flag. Once the error flag is set, all // also set an error flag. Once the error flag is set, all
// further ops become no-ops. At that point, attempting a // further ops become no-ops. After that point, fetching
// Cast will return nullptr. // any data will return nullptr.
// //
class MCPFetcher class MCPFetcher
@@ -62,7 +62,7 @@ public:
// //
MCPFetcher& ToBlueprint(); MCPFetcher& ToBlueprint();
MCPFetcher& ToGraph(); MCPFetcher& ToGraph();
// Return true if there haven't been any errors. // Return true if there haven't been any errors.
// Note that errors always automatically generate // Note that errors always automatically generate
// output to MCPServer::Printf. // output to MCPServer::Printf.
@@ -92,6 +92,11 @@ public:
// loaded, returns nullptr. Does not generate errors. // loaded, returns nullptr. Does not generate errors.
// //
UObject* GetAsset() const { return OriginalAsset; } UObject* GetAsset() const { return OriginalAsset; }
// Get the asset from where it all began: the first
// step in the walk path, as a specified type. Errors
// if it cannot cast to the specified type.
//
template<class T> T* CastAsset() template<class T> T* CastAsset()
{ {
if (!CheckAssetIsA(T::StaticClass())) return nullptr; if (!CheckAssetIsA(T::StaticClass())) return nullptr;