-
Notifications
You must be signed in to change notification settings - Fork 535
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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
{
var result = await next(context, cancellationToken);
return result;
}
catch (Exception ex)
{
return new CallToolResult
{
Content = [new TextContentBlock { 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 containingCallToolResult
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
minihat25, Jaben, koheatel, wrobtom and ianisms
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working