# Tool Development gengine's tool system is extensible. You can add new operations to existing domain tools or create entirely new domain tools. This page covers the `FMCPToolBase` interface, validation helpers, annotation factory methods, registration, test patterns, and a complete working example. ## FMCPToolBase Every tool handler inherits from `FMCPToolBase` and implements two methods: `GetInfo()` and `Execute()`. ```cpp // Source/Gengine/Private/MCP/MCPToolBase.h struct FMCPToolInfo { FString Name; FString Description; TArray Params; TArray Annotations; EMCPSafetyTier SafetyRequirement; }; class FMCPToolBase { public: virtual ~FMCPToolBase() = default; /** Return static metadata — called once at registration. */ virtual FMCPToolInfo GetInfo() const = 0; /** Execute the operation. Called on the game thread. */ virtual FMCPResult Execute(const FJsonObject& Params) = 0; /** Optional: override to check safety annotations at dispatch time. */ virtual bool HasAnnotation(EMCPAnnotation Annotation) const; /** Optional: override to declare the minimum safety tier required. */ virtual EMCPSafetyTier GetSafetyRequirement() const; }; ``` ## Implementing GetInfo() `GetInfo()` declares the tool's name, description, parameter schema, annotations, and safety tier. This data feeds tool discovery — the AI reads it during the MCP initialize handshake. ```cpp FMCPToolInfo FMCPTool_TextureAudit::GetInfo() const { FMCPToolInfo Info; Info.Name = TEXT("texture_audit"); Info.Description = TEXT("Audit texture assets in a content path for oversized dimensions or missing compression settings."); Info.SafetyRequirement = EMCPSafetyTier::ReadOnly; Info.Annotations = { EMCPAnnotation::ReadOnly }; // Required parameter Info.Params.Add(FMCPParamDef::Required( TEXT("path"), TEXT("Content path to audit, e.g. /Game/Textures/"), EMCPParamType::String )); // Optional parameter with default Info.Params.Add(FMCPParamDef::Optional( TEXT("max_dimension"), TEXT("Flag textures larger than this dimension (width or height). Default: 2048."), EMCPParamType::Integer )); Info.Params.Add(FMCPParamDef::Optional( TEXT("recursive"), TEXT("Include subdirectories. Default: false."), EMCPParamType::Bool )); return Info; } ``` ### Parameter definition helpers | Helper | Usage | |--------|-------| | `FMCPParamDef::Required(name, desc, type)` | Mandatory parameter — validator rejects calls that omit it | | `FMCPParamDef::Optional(name, desc, type)` | Optional parameter — validator passes calls that omit it | ### Param types | `EMCPParamType` | JSON type | |-----------------|-----------| | `String` | `string` | | `Integer` | `number` (integer) | | `Float` | `number` (float) | | `Bool` | `boolean` | | `Object` | `object` | | `Array` | `array` | ## Implementing Execute() `Execute()` runs on the **game thread**. Keep it non-blocking — use `AsyncTask` for heavy work and return a task handle. ```cpp FMCPResult FMCPTool_TextureAudit::Execute(const FJsonObject& Params) { // 1. Extract and validate parameters FString ContentPath; if (!Params.TryGetStringField(TEXT("path"), ContentPath)) { return FMCPResult::Error(TEXT("Missing required parameter: path")); } // Validate path — no traversal, no absolute paths if (!FMCPParamValidator::IsValidContentPath(ContentPath)) { return FMCPResult::Error(TEXT("Invalid content path")); } int32 MaxDimension = 2048; Params.TryGetNumberField(TEXT("max_dimension"), MaxDimension); bool bRecursive = false; Params.TryGetBoolField(TEXT("recursive"), bRecursive); // 2. Do the work using UE APIs (game thread — safe to call asset registry) FAssetRegistryModule& AssetReg = FModuleManager::LoadModuleChecked(TEXT("AssetRegistry")); FARFilter Filter; Filter.PackagePaths.Add(*ContentPath); Filter.ClassPaths.Add(UTexture2D::StaticClass()->GetClassPathName()); Filter.bRecursivePaths = bRecursive; TArray Assets; AssetReg.Get().GetAssets(Filter, Assets); // 3. Build result TArray> Violations; for (const FAssetData& Asset : Assets) { UTexture2D* Tex = Cast(Asset.GetAsset()); if (!Tex) continue; const int32 Width = Tex->GetSizeX(); const int32 Height = Tex->GetSizeY(); if (Width > MaxDimension || Height > MaxDimension) { TSharedPtr Entry = MakeShared(); Entry->SetStringField(TEXT("path"), Asset.GetObjectPathString()); Entry->SetNumberField(TEXT("width"), Width); Entry->SetNumberField(TEXT("height"), Height); Entry->SetStringField(TEXT("issue"), TEXT("Exceeds max dimension")); Violations.Add(MakeShared(Entry)); } } TSharedPtr ResultObj = MakeShared(); ResultObj->SetNumberField(TEXT("total_checked"), Assets.Num()); ResultObj->SetNumberField(TEXT("violations_found"), Violations.Num()); ResultObj->SetArrayField(TEXT("violations"), Violations); return FMCPResult::Success(ResultObj); } ``` ### Result helpers | Method | Usage | |--------|-------| | `FMCPResult::Success(JsonObject)` | Operation completed, return structured data | | `FMCPResult::Success(FString)` | Operation completed, return plain text | | `FMCPResult::Error(FString)` | Operation failed, return error message | | `FMCPResult::ValidationError(FString)` | Parameter was invalid — triggers 400-style response | ## Validator Helpers Use `FMCPParamValidator` static methods for common checks rather than rolling your own: ```cpp // Path safety FMCPParamValidator::IsValidContentPath(FString Path) // /Game/... format, no traversal FMCPParamValidator::IsValidActorName(FString Name) // no special chars, no traversal FMCPParamValidator::IsValidAssetName(FString Name) // alphanumeric + underscores // Numeric safety FMCPParamValidator::IsFiniteFloat(float Value) // not NaN, not Inf FMCPParamValidator::IsValidIntRange(int32 Value, int32 Min, int32 Max) // String safety FMCPParamValidator::ContainsInjectionPatterns(FString S) //