**Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.
🔴 Required Information
Please ensure all items in this section are completed to allow for efficient triaging. Requests without complete information may be rejected / deprioritized. If an item is not applicable to you - please mark it as N/A.
Describe the Bug:
When building an LlmAgent from a declarative agent config (e.g., root_agent.yaml) containing an McpToolset configured exclusively with stdioServerParams (e.g., command: npx), the toolset constructs fine but fails with a NullPointerException at the first attempt to retrieve tools. This happens because McpToolset.fromConfig correctly validates the configuration but incorrectly extracts the connection parameters, ignoring stdioServerParams completely.
Object connectionParameters =
Optional.<Object>ofNullable(mcpToolsetConfig.stdioConnectionParams())
.or(() -> Optional.ofNullable(mcpToolsetConfig.sseServerParams()))
.orElse(mcpToolsetConfig.stdioConnectionParams());
As a result, it passes a null connection parameter object to DefaultMcpTransportBuilder, leading to a deferred crash that does not mention MCP or the configuration keys in its stack trace.
Steps to Reproduce:
Please provide a numbered list of steps to reproduce the behavior:
- Author a minimal agent config
root_agent.yaml that declares an MCP toolset using stdio_server_params (note: name, model, and instruction are required by LlmAgent.fromConfig, otherwise loading fails before reaching this bug):
name: filesystem_agent
model: gemini-2.5-flash
instruction: |
You are a file system assistant. Use the provided tools to read and list files.
tools:
- name: McpToolset
args:
stdio_server_params:
command: npx
args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp/mcp-demo"]
- Load it via
com.google.adk.agents.ConfigAgentUtils.fromConfig("/path/to/root_agent.yaml") — the LlmAgent builds successfully; the misconfiguration is silent at construction time.
- Run any prompt through the agent (e.g.
new InMemoryRunner(agent) + runAsync) — the first request that resolves the agent's tools triggers McpToolset.getTools().
- Observe the
NullPointerException originating from DefaultMcpTransportBuilder.build(null). The configured MCP server process is never launched.
Expected Behavior:
The toolset should correctly resolve the stdioServerParams, map them to ServerParameters, and successfully establish the MCP Stdio connection, identical to how it behaves when the parameters are provided programmatically.
Observed Behavior:
A NullPointerException occurs far away from the misconfiguration — the stack trace mentions neither MCP configuration keys nor the config file:
18:33:55.890 [main] INFO com.google.adk.agents.LlmAgent -- Successfully created LlmAgent: filesystem_agent with 0 subagents
18:33:56.311 [main] INFO com.google.adk.tools.mcp.McpToolset -- MCP session is null, initializing.
18:33:56.312 [main] ERROR com.google.adk.tools.mcp.McpToolset -- Unexpected error during tool loading, retry attempt 1
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "connectionParams" is null
at com.google.adk.tools.mcp.DefaultMcpTransportBuilder.build(DefaultMcpTransportBuilder.java:72)
at com.google.adk.tools.mcp.McpSessionManager.initializeSession(McpSessionManager.java:78)
at com.google.adk.tools.mcp.McpSessionManager.createSession(McpSessionManager.java:56)
at com.google.adk.tools.mcp.McpToolset.lambda$0(McpToolset.java:265)
Environment Details:
- ADK Library Version: 1.6.1-SNAPSHOT (commit
ba23601c)
- OS: Windows
- TS Version (tsc --version): N/A
Model Information:
- Which model is being used: gemini-2.5-flash
🟡 Optional Information
Regression:
No. The declarative config mechanism for MCP toolsets is a new capability in development.
Logs:
The toolset retries three times (each attempt hitting the same NPE, since the null connection params are permanent) and then gives up:
18:33:56.328 [main] ERROR com.google.adk.tools.mcp.McpToolset -- Unexpected error during tool loading, retry attempt 2
18:33:56.331 [main] ERROR com.google.adk.tools.mcp.McpToolset -- Unexpected error during tool loading, retry attempt 3
18:33:56.334 [main] INFO com.google.adk.tools.mcp.McpToolset -- Reinitializing MCP session before next retry for unexpected error.
18:33:56.334 [main] ERROR com.google.adk.tools.mcp.McpToolset -- Failed to load tools after multiple retries due to unexpected error.
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "connectionParams" is null
Screenshots / Video:
N/A — see stack traces and logs above.
Additional Context:
The bug affects only the config-driven path (McpToolset.fromConfig); programmatic construction via new McpToolset(ServerParameters) works correctly because callers manually invoke StdioServerParameters.toServerParameters().
How often has this issue occurred?:
**Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.
🔴 Required Information
Please ensure all items in this section are completed to allow for efficient triaging. Requests without complete information may be rejected / deprioritized. If an item is not applicable to you - please mark it as N/A.
Describe the Bug:
When building an
LlmAgentfrom a declarative agent config (e.g.,root_agent.yaml) containing anMcpToolsetconfigured exclusively withstdioServerParams(e.g.,command: npx), the toolset constructs fine but fails with aNullPointerExceptionat the first attempt to retrieve tools. This happens becauseMcpToolset.fromConfigcorrectly validates the configuration but incorrectly extracts the connection parameters, ignoringstdioServerParamscompletely.As a result, it passes a
nullconnection parameter object toDefaultMcpTransportBuilder, leading to a deferred crash that does not mention MCP or the configuration keys in its stack trace.Steps to Reproduce:
Please provide a numbered list of steps to reproduce the behavior:
root_agent.yamlthat declares an MCP toolset usingstdio_server_params(note:name,model, andinstructionare required byLlmAgent.fromConfig, otherwise loading fails before reaching this bug):com.google.adk.agents.ConfigAgentUtils.fromConfig("/path/to/root_agent.yaml")— theLlmAgentbuilds successfully; the misconfiguration is silent at construction time.new InMemoryRunner(agent)+runAsync) — the first request that resolves the agent's tools triggersMcpToolset.getTools().NullPointerExceptionoriginating fromDefaultMcpTransportBuilder.build(null). The configured MCP server process is never launched.Expected Behavior:
The toolset should correctly resolve the
stdioServerParams, map them toServerParameters, and successfully establish the MCP Stdio connection, identical to how it behaves when the parameters are provided programmatically.Observed Behavior:
A
NullPointerExceptionoccurs far away from the misconfiguration — the stack trace mentions neither MCP configuration keys nor the config file:Environment Details:
ba23601c)Model Information:
🟡 Optional Information
Regression:
No. The declarative config mechanism for MCP toolsets is a new capability in development.
Logs:
The toolset retries three times (each attempt hitting the same NPE, since the null connection params are permanent) and then gives up:
Screenshots / Video:
N/A — see stack traces and logs above.
Additional Context:
The bug affects only the config-driven path (
McpToolset.fromConfig); programmatic construction vianew McpToolset(ServerParameters)works correctly because callers manually invokeStdioServerParameters.toServerParameters().How often has this issue occurred?: