[BUG] `AbstractMcpTool` constructor NPEs when an MCP tool has no description
Describe the Bug
AbstractMcpTool's constructor calls mcpTool.description().isEmpty() to substitute "" for an empty description, but McpSchema.Tool.description is nullable (the MCP spec makes description optional, and the record does no null-check). When a connected MCP server returns a tool without a description, .isEmpty() is invoked on null → NullPointerException, crashing tool loading.
Root Cause
// AbstractMcpTool.<init>, L53-55
super(
mcpTool == null ? "" : mcpTool.name(),
mcpTool == null ? "" : (mcpTool.description().isEmpty() ? "" : mcpTool.description()));
// ^^^^^^^^^^^^^^^^^^^^^^^^^ NPE when description() == null
McpToolset.getTools() maps each server-provided io.modelcontextprotocol.spec.McpSchema.Tool directly into new McpTool(tool, ...), so any tool with an absent description triggers the NPE during loading.
Steps to Reproduce
// A spec-legal MCP tool with no description:
McpSchema.Tool tool = McpSchema.Tool.builder().name("myTool").build(); // description() == null
new McpTool(tool, mcpSession, mcpSessionManager, objectMapper); // throws NPE at AbstractMcpTool:55
(Reproduced with a real Tool — no mocks — the NPE fires before any later null-checks.)
Expected Behavior
A tool without a description loads normally (description treated as empty).
Observed Behavior
java.lang.NullPointerException: Cannot invoke "String.isEmpty()" because the return value of
"io.modelcontextprotocol.spec.McpSchema$Tool.description()" is null
at com.google.adk.tools.mcp.AbstractMcpTool.<init>(AbstractMcpTool.java:55)
Suggested Fix
Null-safe handling:
super(
mcpTool == null ? "" : mcpTool.name(),
mcpTool == null ? "" : Strings.nullToEmpty(mcpTool.description()));
Corresponding Test (generated)
All @Test methods in TestFusionIntegration__3114__Test fail in the shared @BeforeEach, which constructs the tool with a mocked Tool whose description() defaults to null (mirroring a real server that omits the description). Verbatim:
@Mock private Tool mcpTool;
@Mock private McpSyncClient mcpSession;
@Mock private McpSessionManager mcpSessionManager;
@Mock private ToolContext toolContext;
@BeforeEach
void setUp() {
objectMapper = JsonBaseModel.getMapper();
when(mcpSessionManager.createSession()).thenReturn(mcpSession);
mcpToolInstance = new McpTool(mcpTool, mcpSession, mcpSessionManager, objectMapper); // NPE at AbstractMcpTool:55
}
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.
Hi @SuperCorleone, Thank you for reporting this issue and providing detailed information. I am able to reproduce this issue in latest version which you described and I have created this PR to resolve this problem. hope this will resolve your issue?