Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,45 @@ await Invoke_Request_To_Server(
});
}

[Fact]
public async Task Invoke_Invalid_Tool_Returns_Error()
{
await Invoke_Request_To_Server(
method: "tools/call",
new ServerCapabilities
{
Tools = new()
{
CallToolHandler = (request, ct) =>
{
// Simulate the behavior when an invalid tool is called
return ValueTask.FromResult(new CallToolResult
{
Content = [new TextContentBlock { Text = $"The tool {request.Params?.Name} was not found" }],
IsError = true
});
},
ListToolsHandler = (request, ct) => throw new NotImplementedException(),
}
},
requestParams: JsonSerializer.SerializeToNode(new
{
name = "non_existent_tool",
arguments = new { }
}),
configureOptions: null,
assertResult: response =>
{
var result = JsonSerializer.Deserialize<CallToolResult>(response);
Assert.NotNull(result);
Assert.True(result.IsError, "Expected error response for non-existent tool");
Assert.NotEmpty(result.Content);

var textContent = Assert.IsType<TextContentBlock>(result.Content[0]);
Assert.Contains("The tool non_existent_tool was not found", textContent.Text);
});
}


private async Task Invoke_Request_To_Server(string method, ServerCapabilities? serverCapabilities, Action<McpServerOptions>? configureOptions, Action<JsonNode?> assertResult)
{
Expand Down