Skip to content

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

Description

@SuperCorleone

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.

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions