Describe the Bug
adkToMcpToolType guards the empty-declaration case but then calls toolDeclaration.get().parameters().get() — an unguarded Optional.get() on parameters(). A declaration that is present but has no parameters (a valid no-argument tool) yields NoSuchElementException. All built-in ADK tools populate parameters, so the library itself never triggers it, but a user-supplied custom tool overriding declaration() without parameters would.
Root Cause
// ConversionUtils.adkToMcpToolType, ~L36
... toolDeclaration.get().parameters().get() ... // NoSuchElementException when parameters is empty
Suggested Fix
Guard parameters: toolDeclaration.get().parameters().orElse(null) (or build the MCP tool without an input schema when parameters are absent — which is exactly what the failing test expects).
Corresponding Test (generated)
@Test
public void testAdkToMcpToolType_WithNonEmptyDeclarationAndNullSchema_ReturnsToolWithoutInputSchema() {
// Given
String toolName = "testTool";
String toolDescription = "A test tool";
when(mockBaseTool.name()).thenReturn(toolName);
when(mockBaseTool.description()).thenReturn(toolDescription);
when(mockBaseTool.declaration()).thenReturn(Optional.of(mockFunctionDeclaration));
when(mockFunctionDeclaration.parameters()).thenReturn(Optional.empty());
// When
McpSchema.Tool result = conversionUtils.adkToMcpToolType(mockBaseTool);
// Then
assertNotNull(result);
assertEquals(toolName, result.name());
assertEquals(toolDescription, result.description());
assertNull(result.inputSchema());
}
Environment
- Project: adk / google-adk (
com.google.adk) · upstream: github.com/google/adk-java
- Version:
0.5.1-SNAPSHOT (local) · Commit: <fill SUT commit> · Java 17 · OS macOS
This input was generated by the test case generator TestFusion developed in our STAR lab.
Describe the Bug
adkToMcpToolTypeguards the empty-declaration case but then callstoolDeclaration.get().parameters().get()— an unguardedOptional.get()onparameters(). A declaration that is present but has no parameters (a valid no-argument tool) yieldsNoSuchElementException. All built-in ADK tools populateparameters, so the library itself never triggers it, but a user-supplied custom tool overridingdeclaration()without parameters would.Root Cause
Suggested Fix
Guard parameters:
toolDeclaration.get().parameters().orElse(null)(or build the MCP tool without an input schema when parameters are absent — which is exactly what the failing test expects).Corresponding Test (generated)
Environment
com.google.adk) · upstream: github.com/google/adk-java0.5.1-SNAPSHOT(local) · Commit:<fill SUT commit>· Java 17 · OS macOSThis input was generated by the test case generator
TestFusiondeveloped in our STAR lab.