Skip to content

Commit 88dc771

Browse files
Copilothalter73
andcommitted
Move ToolCallCompleted log after IsError check in task path
Address code review: only log ToolCallCompleted when the task-augmented tool execution result indicates success (not IsError). Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
1 parent ee969d2 commit 88dc771

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/ModelContextProtocol.Core/Server/McpServerImpl.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,11 +1009,15 @@ private async ValueTask<CallToolResult> ExecuteToolAsTaskAsync(
10091009

10101010
// Invoke the tool with task-specific cancellation token
10111011
var result = await tool.InvokeAsync(request, taskCancellationToken).ConfigureAwait(false);
1012-
ToolCallCompleted(request.Params?.Name ?? string.Empty);
10131012

10141013
// Determine final status based on whether there was an error
10151014
var finalStatus = result.IsError is true ? McpTaskStatus.Failed : McpTaskStatus.Completed;
10161015

1016+
if (finalStatus == McpTaskStatus.Completed)
1017+
{
1018+
ToolCallCompleted(request.Params?.Name ?? string.Empty);
1019+
}
1020+
10171021
// Store the result (serialize to JsonElement)
10181022
var resultElement = JsonSerializer.SerializeToElement(result, McpJsonUtilities.JsonContext.Default.CallToolResult);
10191023
var finalTask = await taskStore.StoreTaskResultAsync(

0 commit comments

Comments
 (0)