Skip to content

Commit 211f66c

Browse files
committed
Add suggestions from AI tools. Fix some default parameters creating testcase with AI
1 parent 54ad7c5 commit 211f66c

25 files changed

Lines changed: 785 additions & 145 deletions
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Cerberus Copyright (C) 2013 - 2025 cerberustesting
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This file is part of Cerberus.
6+
*
7+
* Cerberus is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Cerberus is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.cerberus.core.api.dto.ai;
21+
22+
import lombok.Getter;
23+
import lombok.Setter;
24+
25+
@Getter
26+
@Setter
27+
public class AISuggestionDTO {
28+
29+
private String id;
30+
private String label;
31+
private String value;
32+
private String type; // confirm, cancel, prompt, action
33+
34+
public AISuggestionDTO() {
35+
}
36+
37+
public AISuggestionDTO(String id, String label, String value, String type) {
38+
this.id = id;
39+
this.label = label;
40+
this.value = value;
41+
this.type = type;
42+
}
43+
44+
}

source/src/main/java/org/cerberus/core/mcp/impl/application/CreateApplicationTool.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
180180
if("".equals(appSessionID)){
181181
webSocketEventSender.sendToAppSession(appSessionID, WebSocketStatic.CHANNEL_TOOL_START, Map.of("toolName", TOOL_NAME ));
182182
}
183-
184183
mcpLogUtils.call(TOOL_NAME, "application_create", String.format("MCP tool %s called with application=%s type=%s system=%s", TOOL_NAME, applicationName, type, system));
185184

186185
if (applicationName.isBlank()) {
@@ -199,10 +198,15 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
199198
// If the SYSTEM invariant does not exist, require explicit user confirmation before creating it.
200199
if (!invariantService.isInvariantExist(Invariant.IDNAME_SYSTEM, system)) {
201200
if (!confirmSystemCreation) {
202-
return MCPToolUtils.errorText(
203-
"System '" + system + "' does not exist as a SYSTEM invariant. " +
204-
"Ask the user to confirm its creation, then re-call with confirmSystemCreation=true."
205-
);
201+
return MCPToolUtils.successJson(Map.of(
202+
"status", "confirmation_required",
203+
"message", "System '" + system + "' does not exist as a SYSTEM invariant.",
204+
"data", Map.of(
205+
"application", applicationName,
206+
"type", type,
207+
"system", system
208+
)
209+
));
206210
}
207211
Invariant systemInvariant = new Invariant();
208212
systemInvariant.setIdName(Invariant.IDNAME_SYSTEM);
@@ -256,6 +260,7 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
256260

257261
return MCPToolUtils.successJson(Map.of(
258262
"status", "created",
263+
"message", "Application created successfully.",
259264
"application", applicationMapper.toDTO(application)
260265
));
261266
}

source/src/main/java/org/cerberus/core/mcp/impl/countryenvironmentparameters/CreateCountryEnvironmentParametersTool.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.modelcontextprotocol.server.McpServerFeatures;
2323
import io.modelcontextprotocol.spec.McpSchema;
24+
import org.cerberus.core.api.dto.application.CountryEnvironmentParametersDTOV001;
2425
import org.cerberus.core.api.dto.application.CountryEnvironmentParametersMapperV001;
2526
import org.cerberus.core.crud.entity.CountryEnvironmentParameters;
2627
import org.cerberus.core.crud.service.ICountryEnvironmentParametersService;
@@ -234,9 +235,14 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
234235
return MCPToolUtils.errorText("Unable to create country environment parameter: " + answer.getMessageDescription());
235236
}
236237

238+
CountryEnvironmentParametersDTOV001 dto = mapper.toDTO(cep);
239+
// Strip secret1/secret2 before returning the entry to the MCP client.
240+
dto.setSecret1(null);
241+
dto.setSecret2(null);
242+
237243
return MCPToolUtils.successJson(Map.of(
238244
"status", "created",
239-
"entry", mapper.toDTO(cep)
245+
"entry", dto
240246
));
241247
}
242248

source/src/main/java/org/cerberus/core/mcp/impl/countryenvironmentparameters/DeleteCountryEnvironmentParametersTool.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
161161
CountryEnvironmentParameters cep = readAnswer.getItem();
162162
// Snapshot the DTO before deletion — the entity is gone after the service call.
163163
CountryEnvironmentParametersDTOV001 dto = mapper.toDTO(cep);
164+
// Strip secret1/secret2 before returning the entry to the MCP client.
165+
dto.setSecret1(null);
166+
dto.setSecret2(null);
164167

165168
Answer deleteAnswer = countryEnvironmentParametersService.delete(cep);
166169

source/src/main/java/org/cerberus/core/mcp/impl/countryenvironmentparameters/GetCountryEnvironmentParametersTool.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.modelcontextprotocol.server.McpServerFeatures;
2323
import io.modelcontextprotocol.spec.McpSchema;
24+
import org.cerberus.core.api.dto.application.CountryEnvironmentParametersDTOV001;
2425
import org.cerberus.core.api.dto.application.CountryEnvironmentParametersMapperV001;
2526
import org.cerberus.core.crud.entity.CountryEnvironmentParameters;
2627
import org.cerberus.core.crud.service.ICountryEnvironmentParametersService;
@@ -152,7 +153,12 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
152153
return MCPToolUtils.errorText("Country environment parameter does not exist: system=" + system + " country=" + country + " environment=" + environment + " application=" + application);
153154
}
154155

155-
return MCPToolUtils.successJson(mapper.toDTO(answer.getItem()));
156+
CountryEnvironmentParametersDTOV001 dto = mapper.toDTO(answer.getItem());
157+
// Strip secret1/secret2 before returning the entry to the MCP client.
158+
dto.setSecret1(null);
159+
dto.setSecret2(null);
160+
161+
return MCPToolUtils.successJson(dto);
156162
}
157163

158164
}

source/src/main/java/org/cerberus/core/mcp/impl/countryenvironmentparameters/ListCountryEnvironmentParametersTool.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.modelcontextprotocol.server.McpServerFeatures;
2323
import io.modelcontextprotocol.spec.McpSchema;
24+
import org.cerberus.core.api.dto.application.CountryEnvironmentParametersDTOV001;
2425
import org.cerberus.core.api.dto.application.CountryEnvironmentParametersMapperV001;
2526
import org.cerberus.core.crud.entity.CountryEnvironmentParameters;
2627
import org.cerberus.core.crud.service.ICountryEnvironmentParametersService;
@@ -159,6 +160,7 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
159160
List<Object> entries = raw.stream()
160161
.filter(cep -> matchesSearch(cep, search))
161162
.map(mapper::toDTO)
163+
.map(this::withoutSecrets)
162164
.map(Object.class::cast)
163165
.toList();
164166

@@ -185,4 +187,17 @@ private boolean matchesSearch(CountryEnvironmentParameters cep, String search) {
185187
|| MCPToolUtils.containsIgnoreCase(cep.getUrl(), search);
186188
}
187189

190+
/**
191+
* Strips the secret1/secret2 credential fields from a DTO before it is returned to the
192+
* MCP client.
193+
*
194+
* @param dto the DTO to sanitize
195+
* @return the same DTO instance, with secret1/secret2 cleared
196+
*/
197+
private CountryEnvironmentParametersDTOV001 withoutSecrets(CountryEnvironmentParametersDTOV001 dto) {
198+
dto.setSecret1(null);
199+
dto.setSecret2(null);
200+
return dto;
201+
}
202+
188203
}

source/src/main/java/org/cerberus/core/mcp/impl/countryenvironmentparameters/UpdateCountryEnvironmentParametersTool.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.modelcontextprotocol.server.McpServerFeatures;
2323
import io.modelcontextprotocol.spec.McpSchema;
24+
import org.cerberus.core.api.dto.application.CountryEnvironmentParametersDTOV001;
2425
import org.cerberus.core.api.dto.application.CountryEnvironmentParametersMapperV001;
2526
import org.cerberus.core.crud.entity.CountryEnvironmentParameters;
2627
import org.cerberus.core.crud.service.ICountryEnvironmentParametersService;
@@ -276,9 +277,14 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
276277
return MCPToolUtils.errorText("Unable to update country environment parameter: " + answer.getMessageDescription());
277278
}
278279

280+
CountryEnvironmentParametersDTOV001 dto = mapper.toDTO(cep);
281+
// Strip secret1/secret2 before returning the entry to the MCP client.
282+
dto.setSecret1(null);
283+
dto.setSecret2(null);
284+
279285
return MCPToolUtils.successJson(Map.of(
280286
"status", "updated",
281-
"entry", mapper.toDTO(cep)
287+
"entry", dto
282288
));
283289
}
284290

source/src/main/java/org/cerberus/core/mcp/impl/countryenvparam/CreateCountryEnvParamTool.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.modelcontextprotocol.server.McpServerFeatures;
2323
import io.modelcontextprotocol.spec.McpSchema;
24+
import org.cerberus.core.api.dto.application.CountryEnvParamMapperV001;
2425
import org.cerberus.core.crud.entity.CountryEnvParam;
2526
import org.cerberus.core.crud.service.ICountryEnvParamService;
2627
import org.cerberus.core.mcp.MCPTool;
@@ -44,18 +45,23 @@
4445
* <p>The country and environment values referenced here must already exist as invariants
4546
* (types COUNTRY and ENVIRONMENT) — this tool does not create them.</p>
4647
*
47-
* <p>Delegates all persistence operations to {@link ICountryEnvParamService}.</p>
48+
* <p>Delegates all persistence operations to {@link ICountryEnvParamService} and converts the
49+
* result via {@link CountryEnvParamMapperV001}.</p>
4850
*/
4951
@Component
5052
public class CreateCountryEnvParamTool implements MCPTool {
5153

5254
private static final String TOOL_NAME = "cerberus_country_env_param_create";
5355

5456
private final ICountryEnvParamService countryEnvParamService;
57+
private final CountryEnvParamMapperV001 mapper;
5558
private final MCPLogUtils mcpLogUtils;
5659

57-
public CreateCountryEnvParamTool(ICountryEnvParamService countryEnvParamService, MCPLogUtils mcpLogUtils) {
60+
public CreateCountryEnvParamTool(ICountryEnvParamService countryEnvParamService,
61+
CountryEnvParamMapperV001 mapper,
62+
MCPLogUtils mcpLogUtils) {
5863
this.countryEnvParamService = countryEnvParamService;
64+
this.mapper = mapper;
5965
this.mcpLogUtils = mcpLogUtils;
6066
}
6167

@@ -217,9 +223,7 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
217223

218224
return MCPToolUtils.successJson(Map.of(
219225
"status", "created",
220-
"system", system,
221-
"country", country,
222-
"environment", environment
226+
"entry", mapper.toDTO(cep)
223227
));
224228
}
225229

source/src/main/java/org/cerberus/core/mcp/impl/countryenvparam/DeleteCountryEnvParamTool.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import io.modelcontextprotocol.server.McpServerFeatures;
2323
import io.modelcontextprotocol.spec.McpSchema;
24+
import org.cerberus.core.api.dto.application.CountryEnvParamDTOV001;
25+
import org.cerberus.core.api.dto.application.CountryEnvParamMapperV001;
2426
import org.cerberus.core.crud.entity.CountryEnvParam;
2527
import org.cerberus.core.crud.service.ICountryEnvParamService;
2628
import org.cerberus.core.mcp.MCPTool;
@@ -44,18 +46,24 @@
4446
* may reject the deletion — the resulting error is surfaced as-is.</p>
4547
*
4648
* <p>Delegates to {@link ICountryEnvParamService} for both the existence check
47-
* ({@code readByKey}) and the deletion ({@code delete}).</p>
49+
* ({@code readByKey}) and the deletion ({@code delete}). A DTO snapshot is captured before
50+
* deletion via {@link CountryEnvParamMapperV001} so the confirmation response can include the
51+
* deleted entry's data even though the entity is gone after the service call.</p>
4852
*/
4953
@Component
5054
public class DeleteCountryEnvParamTool implements MCPTool {
5155

5256
private static final String TOOL_NAME = "cerberus_country_env_param_delete";
5357

5458
private final ICountryEnvParamService countryEnvParamService;
59+
private final CountryEnvParamMapperV001 mapper;
5560
private final MCPLogUtils mcpLogUtils;
5661

57-
public DeleteCountryEnvParamTool(ICountryEnvParamService countryEnvParamService, MCPLogUtils mcpLogUtils) {
62+
public DeleteCountryEnvParamTool(ICountryEnvParamService countryEnvParamService,
63+
CountryEnvParamMapperV001 mapper,
64+
MCPLogUtils mcpLogUtils) {
5865
this.countryEnvParamService = countryEnvParamService;
66+
this.mapper = mapper;
5967
this.mcpLogUtils = mcpLogUtils;
6068
}
6169

@@ -147,17 +155,19 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
147155
return MCPToolUtils.errorText("Country environment parameter does not exist: system=" + system + " country=" + country + " environment=" + environment);
148156
}
149157

150-
Answer deleteAnswer = countryEnvParamService.delete(readAnswer.getItem());
158+
CountryEnvParam cep = readAnswer.getItem();
159+
// Snapshot the DTO before deletion — the entity is gone after the service call.
160+
CountryEnvParamDTOV001 dto = mapper.toDTO(cep);
161+
162+
Answer deleteAnswer = countryEnvParamService.delete(cep);
151163

152164
if (!deleteAnswer.isCodeStringEquals("OK")) {
153165
return MCPToolUtils.errorText("Unable to delete country environment parameter: " + deleteAnswer.getMessageDescription());
154166
}
155167

156168
return MCPToolUtils.successJson(Map.of(
157169
"status", "deleted",
158-
"system", system,
159-
"country", country,
160-
"environment", environment
170+
"entry", dto
161171
));
162172
}
163173

source/src/main/java/org/cerberus/core/mcp/impl/countryenvparam/GetCountryEnvParamTool.java

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.modelcontextprotocol.server.McpServerFeatures;
2323
import io.modelcontextprotocol.spec.McpSchema;
24+
import org.cerberus.core.api.dto.application.CountryEnvParamMapperV001;
2425
import org.cerberus.core.crud.entity.CountryEnvParam;
2526
import org.cerberus.core.crud.service.ICountryEnvParamService;
2627
import org.cerberus.core.mcp.MCPTool;
@@ -29,7 +30,6 @@
2930
import org.cerberus.core.util.answer.AnswerItem;
3031
import org.springframework.stereotype.Component;
3132

32-
import java.util.LinkedHashMap;
3333
import java.util.List;
3434
import java.util.Map;
3535

@@ -39,18 +39,23 @@
3939
*
4040
* <p>Exposed MCP tool name: {@code cerberus_country_env_param_get}.</p>
4141
*
42-
* <p>Delegates to {@link ICountryEnvParamService#readByKey(String, String, String)}.</p>
42+
* <p>Delegates to {@link ICountryEnvParamService#readByKey(String, String, String)} and converts
43+
* the result via {@link CountryEnvParamMapperV001}.</p>
4344
*/
4445
@Component
4546
public class GetCountryEnvParamTool implements MCPTool {
4647

4748
private static final String TOOL_NAME = "cerberus_country_env_param_get";
4849

4950
private final ICountryEnvParamService countryEnvParamService;
51+
private final CountryEnvParamMapperV001 mapper;
5052
private final MCPLogUtils mcpLogUtils;
5153

52-
public GetCountryEnvParamTool(ICountryEnvParamService countryEnvParamService, MCPLogUtils mcpLogUtils) {
54+
public GetCountryEnvParamTool(ICountryEnvParamService countryEnvParamService,
55+
CountryEnvParamMapperV001 mapper,
56+
MCPLogUtils mcpLogUtils) {
5357
this.countryEnvParamService = countryEnvParamService;
58+
this.mapper = mapper;
5459
this.mcpLogUtils = mcpLogUtils;
5560
}
5661

@@ -141,34 +146,7 @@ private McpSchema.CallToolResult execute(Map<String, Object> args) {
141146
return MCPToolUtils.errorText("Country environment parameter does not exist: system=" + system + " country=" + country + " environment=" + environment);
142147
}
143148

144-
return MCPToolUtils.successJson(toMap(answer.getItem()));
145-
}
146-
147-
/**
148-
* Converts a {@link CountryEnvParam} entity into a plain map suitable for JSON serialisation.
149-
*
150-
* @param cep the entity to convert
151-
* @return an ordered map with the entry's public fields
152-
*/
153-
private Map<String, Object> toMap(CountryEnvParam cep) {
154-
Map<String, Object> map = new LinkedHashMap<>();
155-
map.put("system", cep.getSystem());
156-
map.put("country", cep.getCountry());
157-
map.put("environment", cep.getEnvironment());
158-
map.put("description", cep.getDescription());
159-
map.put("type", cep.getType());
160-
map.put("build", cep.getBuild());
161-
map.put("revision", cep.getRevision());
162-
map.put("active", cep.isActive());
163-
map.put("chain", cep.getChain());
164-
map.put("distribList", cep.getDistribList());
165-
map.put("maintenanceAct", cep.isMaintenanceAct());
166-
map.put("maintenanceStr", cep.getMaintenanceStr());
167-
map.put("maintenanceEnd", cep.getMaintenanceEnd());
168-
map.put("eMailBodyRevision", cep.geteMailBodyRevision());
169-
map.put("eMailBodyChain", cep.geteMailBodyChain());
170-
map.put("eMailBodyDisableEnvironment", cep.geteMailBodyDisableEnvironment());
171-
return map;
149+
return MCPToolUtils.successJson(mapper.toDTO(answer.getItem()));
172150
}
173151

174152
}

0 commit comments

Comments
 (0)