Interface ToolManager.ToolDefinition

All Superinterfaces:
FeatureManager.FeatureDefinition<ToolManager.ToolInfo,ToolManager.ToolArguments,org.mcpjava.server.tools.ToolResponse,ToolManager.ToolDefinition>, org.mcpjava.server.MetaCarrier.Builder<ToolManager.ToolDefinition>
Enclosing interface:
ToolManager

public static interface ToolManager.ToolDefinition extends FeatureManager.FeatureDefinition<ToolManager.ToolInfo,ToolManager.ToolArguments,org.mcpjava.server.tools.ToolResponse,ToolManager.ToolDefinition>
A builder to define a new tool. Created with ToolManager.newTool(String).

This construct is not thread-safe and should not be reused.

  • Method Details

    • addArgument

      default ToolManager.ToolDefinition addArgument(String name, String description, boolean required, Type type)
      Adds an argument to the tool.
      Parameters:
      name - the argument name
      description - the argument description
      required - whether the argument is required
      type - the argument type
      Returns:
      self this builder
    • addArgument

      ToolManager.ToolDefinition addArgument(String name, String description, boolean required, Type type, String defaultValue)
      Adds an argument to the tool.
      Parameters:
      name - the argument name
      description - the argument description
      required - whether the argument is required
      type - the argument type
      defaultValue - the default value for the argument
      Returns:
      self this builder
    • setAnnotations

      Sets the annotations of the tool
      Parameters:
      annotations - the tool annotations
      Returns:
      self this builder
    • setTitle

      Sets the human-readable title of the tool
      Parameters:
      title - the title
      Returns:
      self this builder
    • generateOutputSchema

      ToolManager.ToolDefinition generateOutputSchema(Class<?> from)
      Sets the class to use to generate the output schema for structured content.

      The class will be inspected and a schema generated which will match the JSON which JSON-B would generate for a class of this type.

      Ignored if setOutputSchema(Object) is called.

      Parameters:
      from - the class to use to generate the schema
      Returns:
      self this builder
    • setOutputSchema

      ToolManager.ToolDefinition setOutputSchema(Object schema)
      Sets the output schema for structured content.

      JSON-B will be used to convert schema to JSON.

      Parameters:
      schema - the output schema
      Returns:
      self this builder
    • setInputSchema

      ToolManager.ToolDefinition setInputSchema(Object schema)
      Sets the input schema for this tool.

      If not set, the input schema is generated automatically from the tool argument types.

      JSON-B will be used to convert schema to JSON.

      Parameters:
      schema - the input schema
      Returns:
      self this builder
    • register

      Add the new tool to the tool manager.
      Specified by:
      register in interface FeatureManager.FeatureDefinition<ToolManager.ToolInfo,ToolManager.ToolArguments,org.mcpjava.server.tools.ToolResponse,ToolManager.ToolDefinition>
      Returns:
      the tool info for the newly created tool
      Throws:
      IllegalArgumentException - if a tool with the given name already exits