Describe the bug
AddCallToolFilter does not allow to handle exception as exception is getting handled and suppressed inside next filter
To Reproduce
Steps to reproduce the behavior:
- Use following code described in filters.md to handle exception
services.AddMcpServer().AddCallToolFilter(next =>async(context,cancellationToken)=>{try{varresult=awaitnext(context,cancellationToken);returnresult;}catch(Exceptionex){returnnewCallToolResult{Content=[newTextContentBlock{Type="text",Text=$"Error: {ex.Message}"}],IsError=true};}}).WithHttpTransport().WithToolsFromAssembly();- Don't configure other filters
- Make call of a tool that throws an exception
- Observe
result object containing CallToolResult object with
IsError = true,
Text = "An error occurred invoking '<redacted>'."
and no exception thrown to catch
Expected behavior
I should be able to handle exception and build my custom CallToolResult
Logs
n/a
Additional context
Version: 0.4.0-preview.1
Describe the bug
AddCallToolFilterdoes not allow to handle exception as exception is getting handled and suppressed insidenextfilterTo Reproduce
Steps to reproduce the behavior:
resultobject containingCallToolResultobject withIsError = true,Text = "An error occurred invoking '<redacted>'."and no exception thrown to catch
Expected behavior
I should be able to handle exception and build my custom
CallToolResultLogs
n/a
Additional context
Version: 0.4.0-preview.1