π΄ Required Information
Describe the Bug:
When using McpToolset with an MCP server that returns tool inputSchema using JSON Schema draft-07 (i.e., definitions + $ref: "#/definitions/..." instead of $defs), the ADK crashes with KeyError: 'definitions'.
This is a spec-compliance bug: the MCP specification (2025-11-25), section 5.3.2 explicitly supports JSON Schema draft-07 in tool definitions β meaning any MCP server sending "$schema": "http://json-schema.org/draft-07/schema#" is fully spec-compliant and ADK must handle it.
This was previously reported in #3685 and closed as stale without a fix.
Steps to Reproduce:
- Install
google-adk (any recent version)
- Connect
McpToolset to any MCP server whose tools use draft-07 schemas with definitions (e.g., Apollo MCP Server)
- Run the agent and send a message that triggers a call to one of those tools
- Observe the crash with the stacktrace below
Expected Behavior:
ADK should handle both $defs (draft 2019+/2020-12) and definitions (draft-07) when dereferencing schemas, since both are valid per the MCP spec.
Observed Behavior:
File ".../google/adk/tools/mcp_tool/mcp_tool.py", line 119, in _get_declaration
parameters = _to_gemini_schema(input_schema)
File ".../google/adk/tools/_gemini_schema_util.py", line 207, in _to_gemini_schema
return Schema.from_json_schema(
File ".../google/genai/types.py", line 2720, in from_json_schema
return convert_json_schema(...)
File ".../google/genai/types.py", line 2492, in _resolve_ref
current = current[part]
KeyError: 'definitions'
Root cause: _dereference_schema in _gemini_schema_util.py only reads $defs:
defs = schema.get("$defs", {}) # ignores `definitions` entirely
_sanitize_schema_formats_for_gemini then silently strips the definitions block, leaving dangling $ref pointers that crash Schema.from_json_schema.
Model Information:
- Are you using LiteLLM: No
- Which model is being used: gemini-2.5-flash
π‘ Optional Information
Regression:
Unknown β definitions support was likely never implemented, as the bug appears to be a missing code path rather than a regression.
Logs:
File ".../google/adk/flows/llm_flows/base_llm_flow.py", line 579, in _preprocess_async
await tool.process_llm_request(
tool_context=tool_context, llm_request=llm_request
)
File ".../google/adk/tools/base_tool.py", line 129, in process_llm_request
llm_request.append_tools([self])
File ".../google/adk/models/llm_request.py", line 255, in append_tools
declaration = tool._get_declaration()
File ".../google/adk/tools/mcp_tool/mcp_tool.py", line 119, in _get_declaration
parameters = _to_gemini_schema(input_schema)
File ".../google/adk/tools/_gemini_schema_util.py", line 207, in _to_gemini_schema
return Schema.from_json_schema(
File ".../google/genai/types.py", line 2492, in _resolve_ref
current = current[part]
KeyError: 'definitions'
Additional Context:
The MCP spec section 5.3.2 explicitly provides a "Tool with explicit draft-07 schema" example, and states:
"Defaults to 2020-12 if no $schema field is present"
This means draft-07 is a first-class citizen of the spec. The previous issue #3685 was closed suggesting the problem was on the server side, but that is incorrect β the server is spec-compliant.
Proposed fix β a one-line change in _dereference_schema:
# Before
defs = schema.get("$defs", {})
# After
defs = schema.get("$defs") or schema.get("definitions") or {}
Minimal Reproduction Code:
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
from google.adk.agents.llm_agent import LlmAgent
# Any MCP server that returns draft-07 schemas with `definitions`
toolset = McpToolset(
connection_params=StreamableHTTPConnectionParams(
url="http://your-draft07-mcp-server/mcp"
)
)
agent = LlmAgent(
model="gemini-2.5-flash",
name="TestAgent",
instruction="Use the available tools.",
tools=[toolset]
)
# Invoking any tool from this server will crash with KeyError: 'definitions'
References:
How often has this issue occurred?
π΄ Required Information
Describe the Bug:
When using
McpToolsetwith an MCP server that returns toolinputSchemausing JSON Schema draft-07 (i.e.,definitions+$ref: "#/definitions/..."instead of$defs), the ADK crashes withKeyError: 'definitions'.This is a spec-compliance bug: the MCP specification (2025-11-25), section 5.3.2 explicitly supports JSON Schema draft-07 in tool definitions β meaning any MCP server sending
"$schema": "http://json-schema.org/draft-07/schema#"is fully spec-compliant and ADK must handle it.This was previously reported in #3685 and closed as stale without a fix.
Steps to Reproduce:
google-adk(any recent version)McpToolsetto any MCP server whose tools use draft-07 schemas withdefinitions(e.g., Apollo MCP Server)Expected Behavior:
ADK should handle both
$defs(draft 2019+/2020-12) anddefinitions(draft-07) when dereferencing schemas, since both are valid per the MCP spec.Observed Behavior:
Root cause:
_dereference_schemain_gemini_schema_util.pyonly reads$defs:_sanitize_schema_formats_for_geminithen silently strips thedefinitionsblock, leaving dangling$refpointers that crashSchema.from_json_schema.Model Information:
π‘ Optional Information
Regression:
Unknown β
definitionssupport was likely never implemented, as the bug appears to be a missing code path rather than a regression.Logs:
Additional Context:
The MCP spec section 5.3.2 explicitly provides a "Tool with explicit draft-07 schema" example, and states:
This means draft-07 is a first-class citizen of the spec. The previous issue #3685 was closed suggesting the problem was on the server side, but that is incorrect β the server is spec-compliant.
Proposed fix β a one-line change in
_dereference_schema:Minimal Reproduction Code:
References:
How often has this issue occurred?