-
Notifications
You must be signed in to change notification settings - Fork 622
Open
Description
Tool arguments are required unless one of the following is true:
Tool.requiredis set tofalseTool.defaultValueis set- the argument type is
Optional
When an argument is not required, here's how we find the value to pass into the method:
- if
Tool.defaultValueis not empty, then its value is converted to the argument type using aDefaultValueConverter- it's an error if there is no appropriate converter, or if the converter throws an exception when converting the value
- this conversion is implemented in MCP: Allow tool methods to have default values #33380 and Support using custom types for default values in MCP ToolArgs #33517, for this issue you should just call the converter
- if the argument type is
Optional, then it's value is an emptyOptional - if the argument type is primitive, then it's value is the default value for that primitive type
- otherwise, the value is
null
Ideally, the default value for each tool argument should be worked out at startup, so that we can validate it, but we probably do need to create a new instance of the value by calling the DefaultValueConverter for every tool call, since we don't know whether the object is immutable.
Tasks:
- write tests for all of the above cases
- update the Javadoc for
ToolArgumentto describe the behaviour listed above - implement the necessary changes
Metadata
Metadata
Assignees
Labels
No labels