MCP tools reject explicit null argument values before calling the MCP client
Describe the Bug
McpTool and McpAsyncTool reject a valid explicit JSON null in tool arguments. For example, a tool whose input schema permits {"value": null} cannot receive that request through ADK: ImmutableMap.copyOf(args) throws before the MCP client's callTool method is invoked.
This matters for tools that distinguish an omitted property from an explicit null, such as clearing an optional value. Dropping the property changes the request's meaning.
Steps to Reproduce
- Use ADK Java main at dde4b23de69b3ffb16393217b195bb0b056c4bb8.
- Create an MCP tool whose input schema permits a nullable string property: {"type":"object","properties":{"value":{"type":["string","null"]}}}.
- Create its McpTool or McpAsyncTool adapter and call runAsync with a LinkedHashMap containing the entry "value" -> null, then subscribe to the result.
- Observe that request construction fails before the MCP client receives a call. The same failure occurs through Functions.handleFunctionCalls with a GenAI FunctionCall containing that argument.
Minimal argument construction:
Map<String, Object> arguments = new LinkedHashMap<>();
arguments.put("value", null);
tool.runAsync(arguments, toolContext).blockingGet();
The regression test uses mocked MCP clients and a mocked session manager, so no server or model credentials are required.
Expected Behavior
The MCP client receives an arguments object containing "value": null. Omitted arguments remain omitted.
Observed Behavior
Both adapters reject the entry while creating CallToolRequest:
java.lang.NullPointerException: null value in entry: value=null
at com.google.common.collect.CollectPreconditions.checkEntryNotNull(...)
...
at com.google.common.collect.ImmutableMap.copyOf(...)
at com.google.adk.tools.mcp.McpTool.lambda$runAsync$0(McpTool.java:96)
The existing retry path attempts session recovery, and the final subscriber error is NoSuchElementException. McpAsyncTool has the same argument-copy failure.
Environment Details
- ADK: 1.15.1-SNAPSHOT, main commit dde4b23de69b3ffb16393217b195bb0b056c4bb8
- MCP Java SDK: 2.0.0, as declared by that checkout
- OS: macOS 26.7
- Java: Liberica JDK 17.0.19
- Model: N/A; reproduced with constructed FunctionCall objects and mocked MCP clients
- Regression history: not established
- Frequency: deterministic for a top-level argument value that is null
Additional Context
The GenAI FunctionCall builder accepts this map, and the MCP SDK's CallToolRequest JSON serialization preserves "value":null. Nested null values already pass through these adapters; the rejection occurs specifically in the top-level Guava map copy.
On the unmodified main production code, the initial 12-case regression suite had four errors: direct invocation and function dispatch, each in sync and async mode. The other eight control cases passed. A local null-tolerant defensive copy fixes these failures.
The result mapper and injected MCP client cannot intercept this failure because it happens before client invocation. Replacing the adapter is possible, but passing valid JSON arguments should work with the built-in adapters.
ADK Python forwards the arguments dictionary to session.call_tool without this null rejection: https://github.com/google/adk-python/blob/main/src/google/adk/tools/mcp_tool/mcp_tool.py
Validation used actual ADK dispatch and SDK JSON serialization with mocked MCP clients; it did not connect to a live MCP server or model.
Hi @zhangxiangnan, Thank you so much for flagging this and submitting a PR. I was able to reproduce the problem and confirm locally that your changes fix it. The issue and PR are now under team review. I'll keep you posted and reach out if we need anything else.Thanks again!