Class: ActionMCP::Client::Blueprint
- Inherits:
-
Collection
- Object
- Collection
- ActionMCP::Client::Blueprint
- Defined in:
- lib/action_mcp/client/blueprint.rb
Overview
Blueprints
A collection that manages and provides access to URI templates (blueprints) for Model Context Protocol (MCP) resource discovery. These blueprints allow dynamic construction of resource URIs by filling in variable placeholders with specific values. The class supports lazy loading of templates when initialized with a client.
Example usage:
# Eager loading
template_data = client.list_resource_templates # Returns array of URI template definitions
blueprints = Blueprint.new(template_data)
# Lazy loading
blueprints = Blueprint.new([], client)
templates = blueprints.all # Templates are loaded here
# Access a specific blueprint by pattern
file_blueprint = Blueprint.find_by_pattern("file://{path}")
# Generate a concrete URI from a blueprint with parameters
uri = Blueprint.construct("file://{path}", { path: "/logs/app.log" })
Defined Under Namespace
Classes: ResourceTemplate
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
-
#construct(pattern, params) ⇒ String
Construct a concrete URI by applying parameters to a blueprint.
-
#contains?(pattern) ⇒ Boolean
Check if the collection contains a blueprint with the given pattern.
-
#find_by_name(name) ⇒ Array<Blueprint>
Find blueprints by name.
-
#find_by_pattern(pattern) ⇒ Blueprint?
Find a blueprint by its URI pattern.
-
#group_by_protocol ⇒ Hash<String, Array<Blueprint>>
Group blueprints by their base protocol.
-
#initialize(templates, client) ⇒ Blueprint
constructor
Initialize a new Blueprints collection with URI template definitions.
-
#templates=(templates) ⇒ Object
Convert raw template data into ResourceTemplate 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(templates, client) ⇒ Blueprint
Initialize a new Blueprints collection with URI template definitions
33 34 35 36 37 |
# File 'lib/action_mcp/client/blueprint.rb', line 33 def initialize(templates, client) super(templates, client) self.templates = @collection_data @load_method = :list_resource_templates end |
Instance Method Details
#construct(pattern, params) ⇒ String
Construct a concrete URI by applying parameters to a blueprint
61 62 63 64 65 66 |
# File 'lib/action_mcp/client/blueprint.rb', line 61 def construct(pattern, params) blueprint = find_by_pattern(pattern) raise ArgumentError, "Unknown blueprint pattern: #{pattern}" unless blueprint blueprint.construct(params) end |
#contains?(pattern) ⇒ Boolean
Check if the collection contains a blueprint with the given pattern
72 73 74 |
# File 'lib/action_mcp/client/blueprint.rb', line 72 def contains?(pattern) all.any? { |blueprint| blueprint.pattern == pattern } end |
#find_by_name(name) ⇒ Array<Blueprint>
Find blueprints by name
51 52 53 |
# File 'lib/action_mcp/client/blueprint.rb', line 51 def find_by_name(name) all.select { |blueprint| blueprint.name == name } end |
#find_by_pattern(pattern) ⇒ Blueprint?
Find a blueprint by its URI pattern
43 44 45 |
# File 'lib/action_mcp/client/blueprint.rb', line 43 def find_by_pattern(pattern) all.find { |blueprint| blueprint.pattern == pattern } end |
#group_by_protocol ⇒ Hash<String, Array<Blueprint>>
Group blueprints by their base protocol
79 80 81 |
# File 'lib/action_mcp/client/blueprint.rb', line 79 def group_by_protocol all.group_by(&:protocol) end |
#templates=(templates) ⇒ Object
Convert raw template data into ResourceTemplate objects
86 87 88 |
# File 'lib/action_mcp/client/blueprint.rb', line 86 def templates=(templates) @collection_data = templates.map { |template_data| ResourceTemplate.new(template_data) } end |