Files
integration/Plugins/BlueprintMCP/Source/BlueprintMCP/Public/MCPHandler.h

60 lines
1.7 KiB
C
Raw Normal View History

#pragma once
#include "CoreMinimal.h"
2026-03-09 00:21:39 -04:00
#include "UObject/Interface.h"
#include "UObject/Object.h"
#include "Dom/JsonObject.h"
#include "MCPHandler.generated.h"
2026-03-06 02:50:02 -05:00
// Marker struct for handler parameters that accept a JSON object.
// PopulateFromJson stashes the actual JSON object into the Json field.
USTRUCT()
2026-03-06 02:50:02 -05:00
struct FMCPJsonObject
{
GENERATED_BODY()
TSharedPtr<FJsonObject> Json;
};
2026-03-06 02:50:02 -05:00
// Marker struct for handler parameters that accept a JSON array.
// PopulateFromJson stashes the actual JSON array into the Array field.
USTRUCT()
struct FMCPJsonArray
{
GENERATED_BODY()
TArray<TSharedPtr<FJsonValue>> Array;
};
2026-03-06 14:28:24 -05:00
// Interface for self-registering MCP tool handlers.
//
2026-03-06 14:28:24 -05:00
// Implementing classes declare their parameters as UPROPERTY fields, which are
// automatically populated from the incoming JSON request and used to
// generate the tool's JSON Schema for MCP tools/list.
//
// Class metadata:
// ToolName - the MCP tool name (e.g. "spawn_node")
//
// Property metadata:
// Optional - marks a parameter as not required
//
2026-03-06 14:28:24 -05:00
UINTERFACE(MinimalAPI, meta=(CannotImplementInterfaceInBlueprint))
class UMCPHandler : public UInterface
{
GENERATED_BODY()
};
class BLUEPRINTMCP_API IMCPHandler
{
GENERATED_BODY()
public:
// Human-readable tool description for MCP tools/list.
2026-03-06 14:28:24 -05:00
virtual FString GetDescription() const = 0;
// Called after parameter fields have been populated from JSON.
2026-03-08 21:28:47 -04:00
// Override the FStringBuilderBase version for plain-text responses, or the
// FJsonObject version for JSON responses. The dispatcher calls the text
// version first; if the builder remains empty, it falls back to JSON.
virtual void Handle(const FJsonObject* Json, FStringBuilderBase& Result) {}
virtual void Handle(const FJsonObject* Json, FJsonObject* Result) {}
};