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 @@ -130,4 +130,52 @@ void callShouldWrapExceptions() {
.hasMessage("Testing tool error");
}

@Test
void callShouldHandleEmptyResponse() {
when(this.tool.name()).thenReturn("testTool");
CallToolResult callResult = mock(CallToolResult.class);
when(callResult.isError()).thenReturn(false);
when(callResult.content()).thenReturn(List.of());
when(this.mcpClient.callTool(any(CallToolRequest.class))).thenReturn(callResult);

SyncMcpToolCallback callback = new SyncMcpToolCallback(this.mcpClient, this.tool);

String response = callback.call("{\"param\":\"value\"}");

assertThat(response).isEqualTo("[]");
}

@Test
void callShouldHandleMultipleContentItems() {
when(this.tool.name()).thenReturn("testTool");
CallToolResult callResult = mock(CallToolResult.class);
when(callResult.isError()).thenReturn(false);
when(callResult.content()).thenReturn(
List.of(new McpSchema.TextContent("First content"), new McpSchema.TextContent("Second content")));
when(this.mcpClient.callTool(any(CallToolRequest.class))).thenReturn(callResult);

SyncMcpToolCallback callback = new SyncMcpToolCallback(this.mcpClient, this.tool);

String response = callback.call("{\"param\":\"value\"}");

assertThat(response).isNotNull();
assertThat(response).isEqualTo("[{\"text\":\"First content\"},{\"text\":\"Second content\"}]");
}

@Test
void callShouldHandleNonTextContent() {
when(this.tool.name()).thenReturn("testTool");
CallToolResult callResult = mock(CallToolResult.class);
when(callResult.isError()).thenReturn(false);
when(callResult.content()).thenReturn(List.of(new McpSchema.ImageContent(null, "base64data", "image/png")));
when(this.mcpClient.callTool(any(CallToolRequest.class))).thenReturn(callResult);

SyncMcpToolCallback callback = new SyncMcpToolCallback(this.mcpClient, this.tool);

String response = callback.call("{\"param\":\"value\"}");

assertThat(response).isNotNull();
assertThat(response).isEqualTo("[{\"data\":\"base64data\",\"mimeType\":\"image/png\"}]");
}

}