#if TOOLS using Godot; namespace Rokojori.Tools { using Rokojori; public static class ReadResourceRoute { public static JSONObject ToolDefinition() { var pathSchema = new JSONObject(); pathSchema.Set( "type", "string" ); pathSchema.Set( "description", "res:// path to the resource (.tres/.res)" ); var properties = new JSONObject(); properties.Set( "path", pathSchema ); var required = new JSONArray(); required.Push( "path" ); var schema = new JSONObject(); schema.Set( "type", "object" ); schema.Set( "properties", properties ); schema.Set( "required", required ); var tool = new JSONObject(); tool.Set( "name", "read_resource" ); tool.Set( "description", "Read a Resource's stored properties as JSON." ); tool.Set( "inputSchema", schema ); return tool; } public static ToolCallOutcome Execute( JSONObject arguments ) { var path = JsonUtil.GetStringOrNull( arguments, "path" ); if ( string.IsNullOrEmpty( path ) ) { return ToolCallOutcome.Error( "Missing required argument: path" ); } if ( ! ResourceLoader.Exists( path, "" ) ) { return ToolCallOutcome.Error( "Resource not found: " + path ); } var resource = ResourceLoader.Load( path ); if ( resource == null ) { return ToolCallOutcome.Error( "Failed to load resource: " + path ); } var data = new JSONObject(); data.Set( "path", path ); data.Set( "type", resource.GetClass() ); data.Set( "properties", PropertyReflection.ToJson( resource ) ); return ToolCallOutcome.Ok( JSON.Stringify( data ) ); } } } #endif