Skip to content

Commit c21c860

Browse files
committed
feat: Remove pagination from GetHierarchy method and simplify prefab retrieval
1 parent 14e3847 commit c21c860

File tree

2 files changed

+6
-41
lines changed

2 files changed

+6
-41
lines changed

MCPForUnity/Editor/Tools/Prefabs/ManagePrefabs.cs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using System.IO;
54
using MCPForUnity.Editor.Helpers;
65
using Newtonsoft.Json.Linq;
@@ -26,10 +25,6 @@ public static class ManagePrefabs
2625
private const string ACTION_GET_HIERARCHY = "get_hierarchy";
2726
private const string SupportedActions = ACTION_OPEN_STAGE + ", " + ACTION_CLOSE_STAGE + ", " + ACTION_SAVE_OPEN_STAGE + ", " + ACTION_CREATE_FROM_GAMEOBJECT + ", " + ACTION_GET_INFO + ", " + ACTION_GET_HIERARCHY;
2827

29-
// Pagination constants
30-
private const int DefaultPageSize = 50;
31-
private const int MaxPageSize = 500;
32-
3328
public static object HandleCommand(JObject @params)
3429
{
3530
if (@params == null)
@@ -556,6 +551,7 @@ private static object GetInfo(JObject @params)
556551

557552
/// <summary>
558553
/// Gets the hierarchical structure of a prefab asset.
554+
/// Returns all objects in the prefab for full client-side filtering and search.
559555
/// </summary>
560556
private static object GetHierarchy(JObject @params)
561557
{
@@ -571,11 +567,6 @@ private static object GetHierarchy(JObject @params)
571567
return new ErrorResponse($"Invalid prefab path '{prefabPath}'. Path traversal sequences are not allowed.");
572568
}
573569

574-
// Parse pagination parameters
575-
var pagination = PaginationRequest.FromParams(@params, defaultPageSize: DefaultPageSize);
576-
int pageSize = Mathf.Clamp(pagination.PageSize, 1, MaxPageSize);
577-
int cursor = pagination.Cursor;
578-
579570
// Load prefab contents in background (without opening stage UI)
580571
GameObject prefabContents = PrefabUtility.LoadPrefabContents(sanitizedPath);
581572
if (prefabContents == null)
@@ -585,29 +576,16 @@ private static object GetHierarchy(JObject @params)
585576

586577
try
587578
{
588-
// Build hierarchy items
579+
// Build complete hierarchy items (no pagination)
589580
var allItems = BuildHierarchyItems(prefabContents.transform);
590-
int totalCount = allItems.Count;
591-
592-
// Apply pagination
593-
int startIndex = Mathf.Min(cursor, totalCount);
594-
int endIndex = Mathf.Min(startIndex + pageSize, totalCount);
595-
var paginatedItems = allItems.Skip(startIndex).Take(endIndex - startIndex).ToList();
596-
597-
bool truncated = endIndex < totalCount;
598-
string nextCursor = truncated ? endIndex.ToString() : null;
599581

600582
return new SuccessResponse(
601-
$"Successfully retrieved prefab hierarchy. Found {totalCount} objects.",
583+
$"Successfully retrieved prefab hierarchy. Found {allItems.Count} objects.",
602584
new
603585
{
604586
prefabPath = sanitizedPath,
605-
cursor = cursor.ToString(),
606-
pageSize = pageSize,
607-
nextCursor = nextCursor,
608-
truncated = truncated,
609-
total = totalCount,
610-
items = paginatedItems
587+
total = allItems.Count,
588+
items = allItems
611589
}
612590
);
613591
}

Server/src/services/tools/manage_prefabs.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from services.registry import mcp_for_unity_tool
77
from services.tools import get_unity_instance_from_context
8-
from services.tools.utils import coerce_bool, coerce_int
8+
from services.tools.utils import coerce_bool
99
from transport.unity_transport import send_with_unity_instance
1010
from transport.legacy.unity_connection import async_send_command_with_retry
1111
from services.tools.preflight import preflight
@@ -53,8 +53,6 @@ async def manage_prefabs(
5353
allow_overwrite: Annotated[bool, "Allow replacing existing prefab."] | None = None,
5454
search_inactive: Annotated[bool, "Include inactive GameObjects in search."] | None = None,
5555
unlink_if_instance: Annotated[bool, "Unlink from existing prefab before creating new one."] | None = None,
56-
page_size: Annotated[int | str, "Items per page for get_hierarchy (default: 50, max: 500)."] | None = None,
57-
cursor: Annotated[int | str, "Pagination cursor for get_hierarchy."] | None = None,
5856
) -> dict[str, Any]:
5957
# Validate required parameters
6058
required = REQUIRED_PARAMS.get(action, [])
@@ -81,10 +79,6 @@ async def manage_prefabs(
8179
}
8280

8381
try:
84-
# Coerce pagination parameters
85-
coerced_page_size = coerce_int(page_size, default=None)
86-
coerced_cursor = coerce_int(cursor, default=None)
87-
8882
# Build parameters dictionary
8983
params: dict[str, Any] = {"action": action}
9084

@@ -116,13 +110,6 @@ async def manage_prefabs(
116110
if unlink_if_instance_val is not None:
117111
params["unlinkIfInstance"] = unlink_if_instance_val
118112

119-
# Handle pagination parameters
120-
if coerced_page_size is not None:
121-
params["pageSize"] = coerced_page_size
122-
123-
if coerced_cursor is not None:
124-
params["cursor"] = coerced_cursor
125-
126113
# Send command to Unity
127114
response = await send_with_unity_instance(
128115
async_send_command_with_retry, unity_instance, "manage_prefabs", params

0 commit comments

Comments
 (0)