Skip to content

Commit b15e7b2

Browse files
committed
Remove unnecessary .ToList() snapshot from RewriteRefPointers
Address review feedback: the assignment completes before the foreach enumerator is created, and recursive calls only mutate descendant objects, so snapshotting via .ToList() is not needed. This makes the JsonObject and JsonArray iteration consistent.
1 parent cfe2b3d commit b15e7b2

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/ModelContextProtocol.Core/Server/AIFunctionMcpServerTool.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,9 @@ private static void RewriteRefPointers(JsonNode? node)
581581
}
582582
}
583583

584-
// ToList() creates a snapshot because the $ref assignment above may invalidate the enumerator.
585-
foreach (var property in obj.ToList())
584+
// Safe to iterate without snapshot: the $ref assignment above completes before
585+
// this enumerator is created, and recursive calls only mutate descendant objects.
586+
foreach (var property in obj)
586587
{
587588
RewriteRefPointers(property.Value);
588589
}

0 commit comments

Comments
 (0)