60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "UObject/Interface.h"
|
|
#include "UObject/Object.h"
|
|
#include "Dom/JsonObject.h"
|
|
#include "MCPHandler.generated.h"
|
|
|
|
// Marker struct for handler parameters that accept a JSON object.
|
|
// PopulateFromJson stashes the actual JSON object into the Json field.
|
|
USTRUCT()
|
|
struct FMCPJsonObject
|
|
{
|
|
GENERATED_BODY()
|
|
TSharedPtr<FJsonObject> Json;
|
|
};
|
|
|
|
// 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;
|
|
};
|
|
|
|
// Interface for self-registering MCP tool handlers.
|
|
//
|
|
// 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
|
|
//
|
|
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.
|
|
virtual FString GetDescription() const = 0;
|
|
|
|
// Called after parameter fields have been populated from JSON.
|
|
// 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) {}
|
|
};
|