adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Issue parsing $ref and $def notation from using MCPToolset

Open ezedonovan opened this issue 1 year ago • 5 comments

** Please make sure you read the contribution guide and file the issues in the right place. ** Contribution guide.

Describe the bug

My agent is using the MCPToolset, simple as

MCPToolset( connection_params=SseServerParams(url=os.getenv("MCP_SERVER")) )

The tool parser is not parsing the tool input schema correctly. From the agent prompt, I see the following: 10:40:44 adk.1 | Functions: 10:40:44 adk.1 | query_domains: {'payload': {'type': <Type.OBJECT: 'OBJECT'>}} -> None 10:40:44 adk.1 | -----------------------------------------------------------

where the payload is not deep dive defined. Hence the LLM is trying some arbitrary key in the payload dict definition. Things like:

args: payload: identifiers: 0: "yahoo.com" identifier_type: "domain_name" name: "query_domains"

This tool is picked up from a FastMCP server. When I use MCP Inspector to list tools on the same server, the tool input schema is correctly defined using the $def and $ref keys. Here is a snippet of the tool definitions from listing tools on the MCP Inspector:

{ "tools": [ { "name": "query_domains", "description": "Some description.", "inputSchema": { "type": "object", "properties": { "payload": { "$ref": "#/$defs/DomainPayload" } }, "required": [ "payload" ], "$defs": { "DomainPayload": { "properties": { "adDomain": { "description": "List of one or many domains.", "items": { "type": "string" }, "title": "Addomain", "type": "array" }, "device": { "default": "GLOBAL", "description": "Filter by device. All devices are returned by default.", "enum": [ "GLOBAL", "desktop", "mobile" ], "title": "Device", "type": "string" }, ..... .....

I think the issue arises from this line of code https://github.com/google/adk-python/blob/main/src/google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.py#L51 which is being used in the to_gemini_schema function https://github.com/google/adk-python/blob/main/src/google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.py#L107

OpenAPI specs https://swagger.io/specification/ Going to Specifications > Schema > Path Item Object

To Reproduce Steps to reproduce the behavior: You'll need access to some MCP that defines tools using $ref and $def notation. And create an agent that uses that tool.

Expected behavior I expect the definiton of the inputSchema in the LLM prompt to be correctly defined. Experimenting the same with LangChain, I managed to include the raw inputSchema definition as they come from the MCP. LLMs already know OpenAPI specs.

Desktop (please complete the following information):

  • OS: Sequoia 15.5
  • Python version(python -V): 3.11.11
  • ADK version(pip show google-adk): 1.1.0

ezedonovan avatar May 29 '25 17:05 ezedonovan

Hi @ezedonovan !

We're currently doing some housekeeping on our issue tracker. Given the rapid pace of development and the number of updates since this was last active, there's a good chance this issue has been resolved in a newer version. To help us keep our backlog focused on current issues, we are closing this as stale.

If you're still facing this problem, could you please update to the very latest version of the library and confirm the issue still exists? If it does, please comment here, and we will be happy to reopen this issue and investigate further.

Thanks for your contribution and understanding!

jwiejulie avatar Aug 08 '25 22:08 jwiejulie

I’m facing the same issue.

chyok avatar Aug 20 '25 09:08 chyok

Also facing the same issue. Using google-adk 1.13.0

dandolf81 avatar Aug 27 '25 23:08 dandolf81

"google-adk>=1.14.0" same issue.

JupiterFeng avatar Sep 12 '25 09:09 JupiterFeng

Fixed by a239716930c72a0dbd2ccabeea69be46110ca48d

xuanyang15 avatar Sep 30 '25 17:09 xuanyang15