Skip to content

Commit bebef8a

Browse files
author
Tarek Mahmoud Sayed
committed
Make RemoveKnownTools validate-then-commit for atomicity
Validate all tool names for null before removing any, matching the all-or-nothing pattern used in AddKnownTools.
1 parent c437f60 commit bebef8a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/ModelContextProtocol.Core/Client/McpClientImpl.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,15 @@ public override void RemoveKnownTools(IEnumerable<string> toolNames)
692692
{
693693
Throw.IfNull(toolNames);
694694

695-
foreach (var name in toolNames)
695+
var snapshot = toolNames as IReadOnlyCollection<string> ?? [.. toolNames];
696+
697+
foreach (var name in snapshot)
696698
{
697699
Throw.IfNull(name);
700+
}
698701

702+
foreach (var name in snapshot)
703+
{
699704
_registeredToolNames.TryRemove(name, out _);
700705
_toolCache.TryRemove(name, out _);
701706
}

0 commit comments

Comments
 (0)