@@ -130,4 +130,52 @@ void callShouldWrapExceptions() {
130130 .hasMessage ("Testing tool error" );
131131 }
132132
133+ @ Test
134+ void callShouldHandleEmptyResponse () {
135+ when (this .tool .name ()).thenReturn ("testTool" );
136+ CallToolResult callResult = mock (CallToolResult .class );
137+ when (callResult .isError ()).thenReturn (false );
138+ when (callResult .content ()).thenReturn (List .of ());
139+ when (this .mcpClient .callTool (any (CallToolRequest .class ))).thenReturn (callResult );
140+
141+ SyncMcpToolCallback callback = new SyncMcpToolCallback (this .mcpClient , this .tool );
142+
143+ String response = callback .call ("{\" param\" :\" value\" }" );
144+
145+ assertThat (response ).isEqualTo ("[]" );
146+ }
147+
148+ @ Test
149+ void callShouldHandleMultipleContentItems () {
150+ when (this .tool .name ()).thenReturn ("testTool" );
151+ CallToolResult callResult = mock (CallToolResult .class );
152+ when (callResult .isError ()).thenReturn (false );
153+ when (callResult .content ()).thenReturn (
154+ List .of (new McpSchema .TextContent ("First content" ), new McpSchema .TextContent ("Second content" )));
155+ when (this .mcpClient .callTool (any (CallToolRequest .class ))).thenReturn (callResult );
156+
157+ SyncMcpToolCallback callback = new SyncMcpToolCallback (this .mcpClient , this .tool );
158+
159+ String response = callback .call ("{\" param\" :\" value\" }" );
160+
161+ assertThat (response ).isNotNull ();
162+ assertThat (response ).isEqualTo ("[{\" text\" :\" First content\" },{\" text\" :\" Second content\" }]" );
163+ }
164+
165+ @ Test
166+ void callShouldHandleNonTextContent () {
167+ when (this .tool .name ()).thenReturn ("testTool" );
168+ CallToolResult callResult = mock (CallToolResult .class );
169+ when (callResult .isError ()).thenReturn (false );
170+ when (callResult .content ()).thenReturn (List .of (new McpSchema .ImageContent (null , "base64data" , "image/png" )));
171+ when (this .mcpClient .callTool (any (CallToolRequest .class ))).thenReturn (callResult );
172+
173+ SyncMcpToolCallback callback = new SyncMcpToolCallback (this .mcpClient , this .tool );
174+
175+ String response = callback .call ("{\" param\" :\" value\" }" );
176+
177+ assertThat (response ).isNotNull ();
178+ assertThat (response ).isEqualTo ("[{\" data\" :\" base64data\" ,\" mimeType\" :\" image/png\" }]" );
179+ }
180+
133181}
0 commit comments