Skip to content

Support for non-required MCP Tool arguments #33562

@Azquelt

Description

@Azquelt

Tool arguments are required unless one of the following is true:

  • Tool.required is set to false
  • Tool.defaultValue is 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.defaultValue is not empty, then its value is converted to the argument type using a DefaultValueConverter
  • if the argument type is Optional, then it's value is an empty Optional
  • 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 ToolArgument to describe the behaviour listed above
  • implement the necessary changes

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions