Class: ActionMCP::Client::PromptBook
- Inherits:
-
Collection
- Object
- Collection
- ActionMCP::Client::PromptBook
- Defined in:
- lib/action_mcp/client/prompt_book.rb
Overview
PromptBook
A collection that manages and provides access to prompt templates from the MCP server. The class stores prompt definitions along with their arguments and provides methods for retrieving, filtering, and accessing prompts. It supports lazy loading of prompts when initialized with a client.
Example usage:
# Eager loading
prompts_data = client.list_prompts # Returns array of prompt definitions
book = PromptBook.new(prompts_data)
# Lazy loading
book = PromptBook.new([], client)
prompts = book.all # Prompts are loaded here
# Access a specific prompt by name
summary_prompt = book.find("summarize_text")
# Get all prompts matching a criteria
text_prompts = book.filter { |p| p.name.include?("text") }
Defined Under Namespace
Classes: Prompt
Constant Summary
Constants included from RequestTimeouts
RequestTimeouts::DEFAULT_TIMEOUT
Instance Attribute Summary
Attributes inherited from Collection
#client, #loaded, #next_cursor, #total
Instance Method Summary collapse
-
#contains?(name) ⇒ Boolean
Check if the collection contains a prompt with the given name.
-
#find(name) ⇒ Prompt?
Find a prompt by name.
-
#initialize(prompts, client) ⇒ PromptBook
constructor
Initialize a new PromptBook with prompt definitions.
-
#names ⇒ Array<String>
Get a list of all prompt names.
-
#prompts=(prompts) ⇒ Object
Convert raw prompt data into Prompt objects.
Methods inherited from Collection
#all, #all!, #each, #each_page, #filter, #has_more_pages?, #next_page, #page, #size
Methods included from RequestTimeouts
Constructor Details
#initialize(prompts, client) ⇒ PromptBook
Initialize a new PromptBook with prompt definitions
33 34 35 36 37 |
# File 'lib/action_mcp/client/prompt_book.rb', line 33 def initialize(prompts, client) super(prompts, client) self.prompts = @collection_data @load_method = :list_prompts end |
Instance Method Details
#contains?(name) ⇒ Boolean
Check if the collection contains a prompt with the given name
58 59 60 |
# File 'lib/action_mcp/client/prompt_book.rb', line 58 def contains?(name) all.any? { |prompt| prompt.name == name } end |
#find(name) ⇒ Prompt?
Find a prompt by name
43 44 45 |
# File 'lib/action_mcp/client/prompt_book.rb', line 43 def find(name) all.find { |prompt| prompt.name == name } end |
#names ⇒ Array<String>
Get a list of all prompt names
50 51 52 |
# File 'lib/action_mcp/client/prompt_book.rb', line 50 def names all.map(&:name) end |
#prompts=(prompts) ⇒ Object
Convert raw prompt data into Prompt objects
65 66 67 |
# File 'lib/action_mcp/client/prompt_book.rb', line 65 def prompts=(prompts) @collection_data = prompts.map { |data| Prompt.new(data) } end |