Skip to content

Commit ad644b4

Browse files
committed
fix: mcp test
1 parent 2755c56 commit ad644b4

2 files changed

Lines changed: 92 additions & 27 deletions

File tree

agentscope-extensions/agentscope-extensions-higress/src/test/java/io/agentscope/extensions/higress/HigressMcpClientWrapperTest.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ void testListTools_WithToolSearch() {
151151

152152
Map<String, Object> structuredContent = Map.of("tools", List.of(tool));
153153
McpSchema.CallToolResult callToolResult =
154-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
154+
McpSchema.CallToolResult.builder()
155+
.isError(false)
156+
.structuredContent(structuredContent)
157+
.build();
155158

156159
when(mockDelegateClient.callTool(eq("x_higress_tool_search"), any()))
157160
.thenReturn(Mono.just(callToolResult));
@@ -170,7 +173,7 @@ void testListTools_WithToolSearch() {
170173
@Test
171174
void testListTools_WithToolSearch_Error() {
172175
McpSchema.CallToolResult errorResult =
173-
new McpSchema.CallToolResult(Collections.emptyList(), true, null);
176+
McpSchema.CallToolResult.builder().isError(true).build();
174177

175178
when(mockDelegateClient.callTool(eq("x_higress_tool_search"), any()))
176179
.thenReturn(Mono.just(errorResult));
@@ -183,9 +186,9 @@ void testListTools_WithToolSearch_Error() {
183186
@Test
184187
void testCallTool_Success() {
185188
Map<String, Object> args = Map.of("param1", "value1");
186-
McpSchema.TextContent content = new McpSchema.TextContent(null, null, "result");
189+
McpSchema.TextContent content = new McpSchema.TextContent("result");
187190
McpSchema.CallToolResult expectedResult =
188-
new McpSchema.CallToolResult(List.of(content), false, null);
191+
McpSchema.CallToolResult.builder().isError(false).build();
189192

190193
when(mockDelegateClient.callTool(eq("my_tool"), eq(args)))
191194
.thenReturn(Mono.just(expectedResult));
@@ -202,7 +205,7 @@ void testCallTool_Success() {
202205
void testCallTool_Error() {
203206
Map<String, Object> args = Map.of("param1", "value1");
204207
McpSchema.CallToolResult errorResult =
205-
new McpSchema.CallToolResult(Collections.emptyList(), true, null);
208+
McpSchema.CallToolResult.builder().isError(true).build();
206209

207210
when(mockDelegateClient.callTool(eq("my_tool"), eq(args)))
208211
.thenReturn(Mono.just(errorResult));
@@ -231,7 +234,10 @@ void testSearchTools_WithQuery() {
231234
Map<String, Object> tool = Map.of("name", "tool1", "description", "Desc", "title", "Title");
232235
Map<String, Object> structuredContent = Map.of("tools", List.of(tool));
233236
McpSchema.CallToolResult callToolResult =
234-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
237+
McpSchema.CallToolResult.builder()
238+
.isError(false)
239+
.structuredContent(structuredContent)
240+
.build();
235241

236242
when(mockDelegateClient.callTool(eq("x_higress_tool_search"), any()))
237243
.thenReturn(Mono.just(callToolResult));
@@ -249,7 +255,10 @@ void testSearchTools_WithQueryAndTopK() {
249255
Map<String, Object> tool = Map.of("name", "tool1", "description", "Desc", "title", "Title");
250256
Map<String, Object> structuredContent = Map.of("tools", List.of(tool));
251257
McpSchema.CallToolResult callToolResult =
252-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
258+
McpSchema.CallToolResult.builder()
259+
.isError(false)
260+
.structuredContent(structuredContent)
261+
.build();
253262

254263
when(mockDelegateClient.callTool(eq("x_higress_tool_search"), any()))
255264
.thenAnswer(
@@ -307,7 +316,10 @@ void testListTools_WithToolSearch_CachesTools() {
307316
"inputSchema", Map.of("type", "object"));
308317
Map<String, Object> structuredContent = Map.of("tools", List.of(tool));
309318
McpSchema.CallToolResult callToolResult =
310-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
319+
McpSchema.CallToolResult.builder()
320+
.isError(false)
321+
.structuredContent(structuredContent)
322+
.build();
311323

312324
when(mockDelegateClient.callTool(eq("x_higress_tool_search"), any()))
313325
.thenReturn(Mono.just(callToolResult));
@@ -356,7 +368,10 @@ void testConvertToMcpTool_WithInputSchema() {
356368

357369
Map<String, Object> structuredContent = Map.of("tools", List.of(tool));
358370
McpSchema.CallToolResult callToolResult =
359-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
371+
McpSchema.CallToolResult.builder()
372+
.isError(false)
373+
.structuredContent(structuredContent)
374+
.build();
360375

361376
when(mockDelegateClient.callTool(eq("x_higress_tool_search"), any()))
362377
.thenReturn(Mono.just(callToolResult));
@@ -386,7 +401,10 @@ void testConvertToMcpTool_WithoutInputSchema() {
386401

387402
Map<String, Object> structuredContent = Map.of("tools", List.of(tool));
388403
McpSchema.CallToolResult callToolResult =
389-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
404+
McpSchema.CallToolResult.builder()
405+
.isError(false)
406+
.structuredContent(structuredContent)
407+
.build();
390408

391409
when(mockDelegateClient.callTool(eq("x_higress_tool_search"), any()))
392410
.thenReturn(Mono.just(callToolResult));
@@ -415,7 +433,10 @@ void testConvertToMcpTool_WithEmptyProperties() {
415433

416434
Map<String, Object> structuredContent = Map.of("tools", List.of(tool));
417435
McpSchema.CallToolResult callToolResult =
418-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
436+
McpSchema.CallToolResult.builder()
437+
.isError(false)
438+
.structuredContent(structuredContent)
439+
.build();
419440

420441
when(mockDelegateClient.callTool(eq("x_higress_tool_search"), any()))
421442
.thenReturn(Mono.just(callToolResult));

agentscope-extensions/agentscope-extensions-higress/src/test/java/io/agentscope/extensions/higress/HigressToolSearchResultTest.java

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void testParse_NullResult() {
4242
@Test
4343
void testParse_ErrorResult() {
4444
McpSchema.CallToolResult callToolResult =
45-
new McpSchema.CallToolResult(Collections.emptyList(), true, null);
45+
McpSchema.CallToolResult.builder().isError(true).build();
4646

4747
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
4848

@@ -54,7 +54,7 @@ void testParse_ErrorResult() {
5454
@Test
5555
void testParse_EmptyContent() {
5656
McpSchema.CallToolResult callToolResult =
57-
new McpSchema.CallToolResult(Collections.emptyList(), false, null);
57+
McpSchema.CallToolResult.builder().isError(false).build();
5858

5959
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
6060

@@ -80,7 +80,10 @@ void testParse_FromStructuredContent() {
8080
structuredContent.put("tools", List.of(tool1));
8181

8282
McpSchema.CallToolResult callToolResult =
83-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
83+
McpSchema.CallToolResult.builder()
84+
.isError(false)
85+
.structuredContent(structuredContent)
86+
.build();
8487

8588
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
8689

@@ -111,7 +114,10 @@ void testParse_FromStructuredContent_MultipleTools() {
111114
structuredContent.put("tools", List.of(tool1, tool2));
112115

113116
McpSchema.CallToolResult callToolResult =
114-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
117+
McpSchema.CallToolResult.builder()
118+
.isError(false)
119+
.structuredContent(structuredContent)
120+
.build();
115121

116122
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
117123

@@ -129,7 +135,10 @@ void testParse_FromTextContent() {
129135

130136
McpSchema.TextContent textContent = new McpSchema.TextContent(jsonText);
131137
McpSchema.CallToolResult callToolResult =
132-
new McpSchema.CallToolResult(List.of(textContent), false, null);
138+
McpSchema.CallToolResult.builder()
139+
.content(List.of(textContent))
140+
.isError(false)
141+
.build();
133142

134143
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
135144

@@ -142,7 +151,10 @@ void testParse_FromTextContent() {
142151
void testParse_FromTextContent_InvalidJson() {
143152
McpSchema.TextContent textContent = new McpSchema.TextContent("invalid json");
144153
McpSchema.CallToolResult callToolResult =
145-
new McpSchema.CallToolResult(List.of(textContent), false, null);
154+
McpSchema.CallToolResult.builder()
155+
.content(List.of(textContent))
156+
.isError(false)
157+
.build();
146158

147159
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
148160

@@ -154,7 +166,10 @@ void testParse_FromTextContent_InvalidJson() {
154166
void testParse_FromTextContent_EmptyText() {
155167
McpSchema.TextContent textContent = new McpSchema.TextContent("");
156168
McpSchema.CallToolResult callToolResult =
157-
new McpSchema.CallToolResult(List.of(textContent), false, null);
169+
McpSchema.CallToolResult.builder()
170+
.content(List.of(textContent))
171+
.isError(false)
172+
.build();
158173

159174
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
160175

@@ -165,7 +180,10 @@ void testParse_FromTextContent_EmptyText() {
165180
void testParse_FromTextContent_NullText() {
166181
McpSchema.TextContent textContent = new McpSchema.TextContent((String) null);
167182
McpSchema.CallToolResult callToolResult =
168-
new McpSchema.CallToolResult(List.of(textContent), false, null);
183+
McpSchema.CallToolResult.builder()
184+
.content(List.of(textContent))
185+
.isError(false)
186+
.build();
169187

170188
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
171189

@@ -190,7 +208,11 @@ void testParse_StructuredContentPriorityOverContent() {
190208
McpSchema.TextContent textContent = new McpSchema.TextContent(jsonText);
191209

192210
McpSchema.CallToolResult callToolResult =
193-
new McpSchema.CallToolResult(List.of(textContent), false, structuredContent);
211+
McpSchema.CallToolResult.builder()
212+
.content(List.of(textContent))
213+
.structuredContent(structuredContent)
214+
.isError(false)
215+
.build();
194216

195217
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
196218

@@ -211,7 +233,11 @@ void testParse_InvalidStructuredContent_FallbackToContent() {
211233
McpSchema.TextContent textContent = new McpSchema.TextContent(jsonText);
212234

213235
McpSchema.CallToolResult callToolResult =
214-
new McpSchema.CallToolResult(List.of(textContent), false, structuredContent);
236+
McpSchema.CallToolResult.builder()
237+
.content(List.of(textContent))
238+
.structuredContent(structuredContent)
239+
.isError(false)
240+
.build();
215241

216242
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
217243

@@ -238,7 +264,10 @@ void testParse_StructuredContent_FilterNonMapItems() {
238264
structuredContent.put("tools", toolsList);
239265

240266
McpSchema.CallToolResult callToolResult =
241-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
267+
McpSchema.CallToolResult.builder()
268+
.isError(false)
269+
.structuredContent(structuredContent)
270+
.build();
242271

243272
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
244273

@@ -257,7 +286,10 @@ void testGetToolNames() {
257286
structuredContent.put("tools", List.of(tool1, tool2, tool3));
258287

259288
McpSchema.CallToolResult callToolResult =
260-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
289+
McpSchema.CallToolResult.builder()
290+
.isError(false)
291+
.structuredContent(structuredContent)
292+
.build();
261293

262294
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
263295

@@ -272,7 +304,10 @@ void testToString_Success() {
272304
structuredContent.put("tools", List.of(tool));
273305

274306
McpSchema.CallToolResult callToolResult =
275-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
307+
McpSchema.CallToolResult.builder()
308+
.isError(false)
309+
.structuredContent(structuredContent)
310+
.build();
276311

277312
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
278313

@@ -311,7 +346,10 @@ void testToolInfo_AllFields() {
311346
Map<String, Object> structuredContent = Map.of("tools", List.of(tool));
312347

313348
McpSchema.CallToolResult callToolResult =
314-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
349+
McpSchema.CallToolResult.builder()
350+
.isError(false)
351+
.structuredContent(structuredContent)
352+
.build();
315353

316354
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
317355
HigressToolSearchResult.ToolInfo toolInfo = result.getTools().get(0);
@@ -336,7 +374,10 @@ void testToolInfo_NullSchemas() {
336374
Map<String, Object> structuredContent = Map.of("tools", List.of(tool));
337375

338376
McpSchema.CallToolResult callToolResult =
339-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
377+
McpSchema.CallToolResult.builder()
378+
.isError(false)
379+
.structuredContent(structuredContent)
380+
.build();
340381

341382
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
342383
HigressToolSearchResult.ToolInfo toolInfo = result.getTools().get(0);
@@ -351,7 +392,10 @@ void testParse_EmptyToolsList() {
351392
Map<String, Object> structuredContent = Map.of("tools", Collections.emptyList());
352393

353394
McpSchema.CallToolResult callToolResult =
354-
new McpSchema.CallToolResult(Collections.emptyList(), false, structuredContent);
395+
McpSchema.CallToolResult.builder()
396+
.isError(false)
397+
.structuredContent(structuredContent)
398+
.build();
355399

356400
HigressToolSearchResult result = HigressToolSearchResult.parse(callToolResult);
357401

0 commit comments

Comments
 (0)