Prompt class

Annotation to mark a method as an MCP prompt template.

Prompts are user-invoked templates that generate structured messages for interacting with language models. Unlike tools (which are model-called), prompts are explicitly selected by users (e.g., as slash commands).

A prompt method must return a PromptResult containing a list of PromptMessage objects. The method's parameters become the prompt's arguments, which users provide when invoking the prompt.

Example:

class CodeReviewPrompts {
  @Prompt(
    title: 'Request Code Review',
    description: 'Asks the LLM to analyze code quality and suggest improvements',
  )
  PromptResult codeReview({
    @PromptArgument(
      title: 'Source Code',
      description: 'The code to review for quality and issues',
    )
    required String code,
  }) {
    return PromptResult(
      description: 'Code review prompt',
      messages: [
        PromptMessage(
          role: PromptRole.user,
          content: TextPromptContent(
            'Please review this code:\\n\\n```\\n$code\\n```',
          ),
        ),
      ],
    );
  }
}
Annotations
  • @immutable

Constructors

Prompt({String? name, String? title, String? description})
Creates a Prompt annotation.
const

Properties

description → String?
Description of what this prompt does.
final
hashCode → int
The hash code for this object.
no setterinherited
name → String?
Custom name for this prompt.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
title → String?
Human-readable title for this prompt.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited