Annotation Interface Tool


@Retention(RUNTIME) @Target(METHOD) public @interface Tool
Annotates a business method of a CDI bean as an exposed tool.

A result of a "tool call" operation is always represented as a ToolResponse. However, the annotated method can also return other types that are converted according to the following rules.

  • If it returns String then the response is success and contains a single TextContent.
  • If it returns an implementation of Content then the response is success and contains a single content object.
  • If it returns a List of Content implementations or strings then the response is success and contains a list of relevant content objects.
  • It may also return a CompletionStage that wraps any of the type mentioned above.

There is a default content encoder registered; it encodes the returned value as JSON using JSON-B.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
     
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Additional hints for clients.
    A human-readable description of the tool.
    Each tool must have a unique name.
    boolean
    If set to true and the method returns a type X which is not specifically treated (see the conversion rules), then the return value is converted to JSON and used as a structuredContent of the result.
    A human-readable title for the tool.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Constant value for name() indicating that the annotated element's name should be used as-is.
  • Field Details

    • ELEMENT_NAME

      static final String ELEMENT_NAME
      Constant value for name() indicating that the annotated element's name should be used as-is.
      See Also:
  • Element Details

    • name

      String name
      Each tool must have a unique name.

      Intended for programmatic or logical use, but used for UI in past specs or as fallback if title isn't present.

      By default, the name is derived from the name of the annotated method.

      Default:
      "<<element name>>"
    • title

      String title
      A human-readable title for the tool.
      Default:
      ""
    • description

      String description
      A human-readable description of the tool. A hint to the model.
      Default:
      ""
    • annotations

      Tool.Annotations annotations
      Additional hints for clients.

      Note that the default value of this annotation member is ignored. In other words, the annotations have to be declared explicitly in order to be included in Tool metadata.

      Default:
      @io.openliberty.mcp.annotations.Tool.Annotations
    • structuredContent

      boolean structuredContent
      If set to true and the method returns a type X which is not specifically treated (see the conversion rules), then the return value is converted to JSON and used as a structuredContent of the result.

      Also the output schema is generated automatically from the return type.

      Default:
      false