Skip to content

Commit 44e490b

Browse files
committed
Rename illigal args to missing args, rename source set for consistency, review comments
1 parent ce5df9a commit 44e490b

File tree

7 files changed

+29
-24
lines changed

7 files changed

+29
-24
lines changed

dev/io.openliberty.mcp.internal/src/io/openliberty/mcp/internal/McpCdiExtension.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ void afterDeploymentValidation(@Observes AfterDeploymentValidation afterDeployme
6363
private void reportOnToolArgEdgeCases(AfterDeploymentValidation afterDeploymentValidation) {
6464
StringBuilder sbBlankArgs = new StringBuilder("Blank arguments found in MCP Tool:");
6565
StringBuilder sbDuplicateArgs = new StringBuilder("Duplicate arguments found in MCP Tool:");
66-
StringBuilder sbIllegalArgs = new StringBuilder("Illegal arguments found in MCP Tool:");
66+
StringBuilder sbMissingArgs = new StringBuilder("Missing arguments found in MCP Tool:");
6767
boolean blankArgumentsFound = false;
6868
boolean duplicateArgumentsFound = false;
69-
boolean illegalArgumentsFound = false;
69+
boolean missingArgumentName = false;
7070

7171
for (ToolMetadata tool : tools.getAllTools()) {
7272
Map<String, ArgumentMetadata> arguments = tool.arguments();
@@ -78,9 +78,10 @@ private void reportOnToolArgEdgeCases(AfterDeploymentValidation afterDeploymentV
7878
} else if (arguments.get(argName).isDuplicate()) {
7979
sbDuplicateArgs.append("\n").append("Tool: " + tool.getToolQualifiedName() + " - Argument: " + argName);
8080
duplicateArgumentsFound = true;
81-
} else if (argName.equals(ToolMetadata.ILLEGAL_TOOL_ARG_NAME)) {
82-
sbIllegalArgs.append("\n").append("Tool: " + tool.getToolQualifiedName());
83-
illegalArgumentsFound = true;
81+
} else if (argName.equals(ToolMetadata.MISSING_TOOL_ARG_NAME)) {
82+
sbMissingArgs.append("\n").append("Tool: " + tool.getToolQualifiedName());
83+
sbMissingArgs.append("\n Tool argument name was not provided for the parameter. Either add a name to the @ToolArg annotation, or to add the -parameters compiler option to use the parameter name");
84+
missingArgumentName = true;
8485
}
8586
}
8687
}
@@ -90,8 +91,8 @@ private void reportOnToolArgEdgeCases(AfterDeploymentValidation afterDeploymentV
9091
if (duplicateArgumentsFound) {
9192
afterDeploymentValidation.addDeploymentProblem(new Exception(sbDuplicateArgs.toString()));
9293
}
93-
if (illegalArgumentsFound) {
94-
afterDeploymentValidation.addDeploymentProblem(new Exception(sbIllegalArgs.toString()));
94+
if (missingArgumentName) {
95+
afterDeploymentValidation.addDeploymentProblem(new Exception(sbMissingArgs.toString()));
9596
}
9697
}
9798

dev/io.openliberty.mcp.internal/src/io/openliberty/mcp/internal/ToolMetadata.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public record ToolMetadata(Tool annotation, Bean<?> bean, AnnotatedMethod<?> met
2929
String name, String title, String description,
3030
List<Class<? extends Throwable>> businessExceptions) {
3131

32-
public static final String ILLEGAL_TOOL_ARG_NAME = "<<<ILLEGAL NAME>>>";
32+
public static final String MISSING_TOOL_ARG_NAME = "<<<MISSING TOOL_ARG NAME>>>";
3333

3434
public record ArgumentMetadata(Type type, int index, String description, boolean required, boolean isDuplicate) {}
3535

@@ -86,7 +86,7 @@ private static String resolveArgumentName(AnnotatedParameter<?> param, ToolArg a
8686
return param.getJavaParameter().getName();
8787
}
8888

89-
return ILLEGAL_TOOL_ARG_NAME;
89+
return MISSING_TOOL_ARG_NAME;
9090
}
9191

9292
private static List<SpecialArgumentMetadata> getSpecialArgumentList(AnnotatedMethod<?> method) {

dev/io.openliberty.mcp.internal_fat/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<attribute name="test" value="true"/>
66
</attributes>
77
</classpathentry>
8-
<classpathentry kind="src" path="noParamTest">
8+
<classpathentry kind="src" path="noParamNames">
99
<attributes>
1010
<attribute name="test" value="true"/>
1111
</attributes>

dev/io.openliberty.mcp.internal_fat/build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ sourceSets {
2828
dependencies {
2929
requiredLibs 'org.json:json:20080701',
3030
'org.skyscreamer:jsonassert:2.0-rc1'
31-
noParamNamesTestCompileOnly project(':io.openliberty.mcp'),
31+
noParamNamesCompileOnly project(':io.openliberty.mcp'),
3232
project(path: ':io.openliberty.jakarta', configuration: 'cdi40')
33-
implementation sourceSets.noParamNamesTest.output
33+
implementation sourceSets.noParamNames.output
3434
}
3535

3636
/* Added to allow method parmaters to be available for MCP Tool Server*/
@@ -39,14 +39,14 @@ compileJava {
3939
options.compilerArgs << '-parameters'
4040
}
4141

42-
// Build the noParamNamesTest code into a jar
43-
tasks.register('noParamNamesTestJar', Jar) {
44-
dependsOn noParamNamesTestClasses
45-
from sourceSets.noParamNamesTest.output
46-
archiveFileName = 'noParamNamesTest.jar'
42+
// Build the noParamNames code into a jar
43+
tasks.register('noParamNamesJar', Jar) {
44+
dependsOn noParamNamesClasses
45+
from sourceSets.noParamNames.output
46+
archiveFileName = 'noParamNames.jar'
4747
}
4848

49-
// Build the noParamNamesTest jar before the autoFVT zip so that it gets included in the zip
49+
// Build the noParamNames jar before the autoFVT zip so that it gets included in the zip
5050
tasks.named('autoFVT') {
51-
dependsOn noParamNamesTestJar
51+
dependsOn noParamNamesJar
5252
}

dev/io.openliberty.mcp.internal_fat/fat/src/io/openliberty/mcp/internal/fat/tool/NoParamNameTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static void teardown() throws Exception {
3939

4040
@Test
4141
public void testNoParamNameToolArg() throws Exception {
42-
String expectedErrorHeader = "Illegal arguments found in MCP Tool:";
43-
List<String> expectedErrorList = List.of("io.openliberty.mcp.internal.fat.noparamtool.NoParamTools.illegalToolArgNameTool");
44-
ExpectedAppFailureValidator.findAndAssertExpectedErrorsInLogs("Illegal Tool Arg: ", expectedErrorHeader, expectedErrorList, server);
42+
String expectedErrorHeader = "Missing arguments found in MCP Tool:";
43+
List<String> expectedErrorList = List.of("io.openliberty.mcp.internal.fat.noparamtool.NoParamTools.missingToolArgNameTool");
44+
ExpectedAppFailureValidator.findAndAssertExpectedErrorsInLogs("Missing arguments found in MCP Tool: ", expectedErrorHeader, expectedErrorList, server);
4545
}
4646
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
@ApplicationScoped
1717
public class NoParamTools {
1818

19-
@Tool(name = "illegalToolArgNameTool", title = "illegal ToolArgName Tool", description = "thows illegalArgumentExeption because of the ToolArgName")
20-
public String illegalToolArgNameTool(@ToolArg(name = Tool.ELEMENT_NAME, description = "input to echo") String input) {
19+
@Tool(name = "missingToolArgNameTool", title = "missing ToolArgName Tool", description = "ToolArgName is missing so app wont start")
20+
public String missingToolArgNameTool(@ToolArg(description = "input to echo") String input) {
2121
return input;
2222
}
2323
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# No Param Names
2+
3+
This source set contains a basic tool called *missingToolArgNameTool*. The reason the tool has been separated out of the the rest of the application is because we need this to be compiled without the -parameters flag. This allows us to test that if parameter names are not included, then we report an error.
4+

0 commit comments

Comments
 (0)