Annotation Interface Prompt


@Target(METHOD) @Retention(RUNTIME) @Documented public @interface Prompt
Marks a method as providing an MCP prompt template. Prompts are reusable message templates that can be used by MCP clients.

Parameters

Prompt methods may have parameters of the following types:
  • String - each String parameter is treated as an argument to the prompt. In most cases these parameters must be annotated with PromptArg with the name attribute set, unless the code was compiled with the -parameters option. PromptArg also allows other properties of the argument to be configured.
  • McpRequest - to access information about the request
  • Cancellation - to allow processing to be stopped if the client cancels the prompt request
  • Progress - to send progress reports back to the client
  • Implementations may define additional types that can be used as parameters

Return Type Handling

The annotated method can return various types that will be converted to prompt responses:

  • String - Single text message with role USER in the response
  • PromptMessage - Single message in the response
  • List of PromptMessage - Multiple messages in the response
  • PromptResponse - Full response with description and messages
  • Other types - Encoded according to framework-specific rules
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    A human-readable description of what this prompt does.
    The unique name of the prompt.
    A human-readable title for the prompt.
  • 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
      The unique name of the prompt.

      Each prompt bound to the same MCP server configuration must have a unique name. This is intended for programmatic or logical use, but may be used for UI display as a fallback if title() is not present.

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

      Returns:
      the prompt name
      Default:
      "<<element name>>"
    • title

      String title
      A human-readable title for the prompt.

      This is a short, user-friendly display name for the prompt.

      Returns:
      the prompt title
      Default:
      ""
    • description

      String description
      A human-readable description of what this prompt does.

      This description will be sent to MCP clients to help them understand when and how to use this prompt.

      Returns:
      the prompt description
      Default:
      ""