Class: ActionModelContext::Prompt

Inherits:
Object
  • Object
show all
Includes:
Primitive
Defined in:
lib/action_model_context/prompt.rb

Overview

Base class of the prompts. An application subclasses it through ApplicationPrompt, under app/mcp/prompts.

Examples:

class SummarizePrompt < ApplicationPrompt
  argument :topic, required: true

  def call(topic:) = "Summarize #{topic} in three points"
end

Instance Attribute Summary

Attributes included from Primitive

#context

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Primitive

description, title

Class Method Details

.argument(name, required: false, title: nil, description: nil) ⇒ void

This method returns an undefined value.

Declares an argument. MCP gives a prompt argument no type, only these fields.

Parameters:

  • name (Symbol, String) —

    the argument's name

  • required (Boolean) (defaults to: false) —

    whether the client must send it

  • title (String, nil) (defaults to: nil) —

    its title, falling back on I18n

  • description (String, nil) (defaults to: nil) —

    its description, falling back on I18n

.prompt_name(name = nil) ⇒ String?

Declares the name, or reads it.

Parameters:

  • name (String, nil) (defaults to: nil) —

    the name to declare

Returns:

  • (String, nil) —

    the declared name, else the underscored class name without its Prompt suffix

Instance Method Details

#call ⇒ String, Array<Hash>

Builds the prompt. A subclass defines it, with one keyword per argument it takes.

Returns:

  • (String, Array<Hash>) —

    one user message, or { role:, content: } hashes

Raises:

  • (Error) —

    to answer an invalid_params JSON-RPC error

  • (NotImplementedError) —

    when no subclass defines it