-
Notifications
You must be signed in to change notification settings - Fork 619
Log tool call name on success, not just failure #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add a LoggerMessage-based ToolCallCompleted log at Information level that captures the tool name on successful tool call completion, matching the existing ToolCallError pattern for failures. Also add the log call to the task-augmented tool execution path. Add test Logs_Tool_Name_On_Successful_Call to verify the new log message. Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
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>
tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsToolsTests.cs
Show resolved
Hide resolved
halter73
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include CallToolResult.IsError in the log.
Address reviewer feedback: - Include CallToolResult.IsError as a parameter in the ToolCallCompleted log message (@halter73) - Always log ToolCallCompleted when InvokeAsync doesn't throw, including when IsError=true (@halter73) - Skip ToolCallCompleted in outer handler for task-augmented calls to avoid double-logging; the async ExecuteToolAsTaskAsync logs separately - Add ReturnIsError tool for testing IsError=true without throwing - Add Logs_Tool_Name_With_IsError_When_Tool_Returns_Error test - Add TaskPath_Logs_Tool_Name_On_Successful_Call test - Add TaskPath_Logs_Tool_Name_With_IsError_When_Tool_Returns_Error test - Add TaskPath_Logs_Error_When_Tool_Throws test - Update tool count assertions for new ReturnIsError tool Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
Done in c18f406. The log message is now |
tests/ModelContextProtocol.Tests/Server/ToolTaskSupportTests.cs
Outdated
Show resolved
Hide resolved
|
@copilot Please address my comment about using |
Use GetTaskResultAsync to wait for task completion instead of arbitrary Task.Delay(500) calls, making tests deterministic and faster. Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
Add GetPromptCompleted/GetPromptError and ReadResourceCompleted/ ReadResourceError LoggerMessage methods, symmetric with the existing tool logging. Wrap prompt and resource filter pipelines with try/catch to log when handlers succeed or throw unhandled exceptions. Add tests: - Logs_Prompt_Name_On_Successful_Call - Logs_Prompt_Name_When_Prompt_Throws - Logs_Resource_Uri_On_Successful_Read - Logs_Resource_Uri_When_Resource_Throws Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
Both addressed: |
ToolCallCompletedlog message inMcpServerImpl.csthat captures the tool name andIsErroron tool call completionCallToolResult.IsErroras a parameter in theToolCallCompletedlogToolCallCompletedwhen InvokeAsync doesn't throw, even withIsError=trueToolCallCompletedin outer handler for task-augmented calls to avoid double-loggingGetTaskResultAsyncinstead ofTask.Delay(@halter73)GetPromptCompleted/GetPromptError) with tests (@halter73)ReadResourceCompleted/ReadResourceError) with tests (@halter73)Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.