-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support parsing anyOf from MCP tools
#1708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Support parsing anyOf from MCP tools
#1708
Conversation
| if enum is not None: | ||
| value["enum"] = enum | ||
|
|
||
| value.pop("anyOf") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this .pop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we parse anyOf, keeping it then results duplicated information. That's why we just pop the key after parsing it.
| if t["type"] == "null": | ||
| continue | ||
| if t["type"] == "any": | ||
| types.append("string") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a type "any", why not use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check line 247, this is how we parse Any all along, i'm just following the current practice here.
| enum = None | ||
| for t in value["anyOf"]: | ||
| if t["type"] == "null": | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have type "null", why not use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is covered by the nullable part above
Smolagents uses MCPAdapt, one problem is that it doesn't handle
anyOffield from the input schema.To mitigate this problem, I expanded
get_tool_json_schemafunction that parses the argument properly.Here is an example of before and after the change:
Before:
After