Skip to content

fix(tools): support draft-07 schema definitions#5955

Open
he-yufeng wants to merge 1 commit into
google:mainfrom
he-yufeng:fix/mcp-draft07-definitions
Open

fix(tools): support draft-07 schema definitions#5955
he-yufeng wants to merge 1 commit into
google:mainfrom
he-yufeng:fix/mcp-draft07-definitions

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

Fixes #5940.

MCP tools may publish JSON Schema draft-07 input schemas using definitions and $ref: "#/definitions/...". ADK currently dereferences only $defs, so draft-07 schemas keep dangling refs and can crash later in Schema.from_json_schema with KeyError: 'definitions'.

This change lets the schema dereferencer read both forms:

  • draft-07 definitions
  • newer $defs, with $defs taking precedence when both are present

It also removes either definitions block after references have been resolved.

Validation

  • .\.venv\Scripts\python.exe -m pytest tests\unittests\tools\test_gemini_schema_util.py -q
  • .\.venv\Scripts\python.exe -m py_compile src\google\adk\tools\_gemini_schema_util.py tests\unittests\tools\test_gemini_schema_util.py
  • .\.venv\Scripts\python.exe -m pyink --check src\google\adk\tools\_gemini_schema_util.py tests\unittests\tools\test_gemini_schema_util.py
  • git diff --check

Note: running the same pytest command with the base Python environment failed during collection because that environment has an older google-genai package missing types.AvatarConfig. The repo-local .venv has google-genai==2.6.0 and passed the target tests.

@adk-bot adk-bot added tools [Component] This issue is related to tools mcp [Component] Issues about MCP support labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mcp [Component] Issues about MCP support tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_dereference_schema fails with KeyError 'definitions' on JSON Schema draft-07 tools — violates MCP spec

2 participants