adk-java icon indicating copy to clipboard operation
adk-java copied to clipboard

[BUG] `ConversionUtils.adkToMcpToolType` throws `NoSuchElementException` for a tool declaration without parameters

Open SuperCorleone opened this issue 5 months ago • 3 comments

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.

SuperCorleone avatar Jun 16 '26 14:06 SuperCorleone

Hi @SuperCorleone, Thank you for reporting this issue. I am able to reproduce this issue which you described. Currently this Issue is under review by our team, we will keep you update if any additional information is required. thank you.

hemasekhar-p avatar Jun 23 '26 13:06 hemasekhar-p

@krwc, Please have a look into it.

hemasekhar-p avatar Jun 23 '26 13:06 hemasekhar-p

The issue has been resolved in commit 66fa921 and will be part of next releease.

MiloszSobczyk avatar Jul 09 '26 14:07 MiloszSobczyk