Class: ActionMCP::Client::Catalog
- Inherits:
-
Collection
- Object
- Collection
- ActionMCP::Client::Catalog
- Defined in:
- lib/action_mcp/client/catalog.rb
Overview
Catalog
A collection that manages and provides access to resources. This class stores resource definitions and provides methods for retrieving, filtering, and accessing resources by URI or other attributes. It supports lazy loading of resources when initialized with a client.
Example usage:
# Eager loading
resources_data = client.list_resources # Returns array of resource definitions
catalog = Catalog.new(resources_data)
# Lazy loading
catalog = Catalog.new([], client)
resources = catalog.all # Resources are loaded here
# Access a specific resource by URI
main_file = catalog.find_by_uri("file:///project/src/main.rs")
# Get all resources matching a criteria
rust_files = catalog.filter { |r| r.mime_type == "text/x-rust" }
Defined Under Namespace
Classes: Resource
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_uri?(uri) ⇒ Boolean
Check if the collection contains a resource with the given URI.
-
#find_by_mime_type(mime_type) ⇒ Array<Resource>
Find resources by MIME type.
-
#find_by_name(name) ⇒ Array<Resource>
Find resources by name.
-
#find_by_uri(uri) ⇒ Resource?
Find a resource by URI.
-
#group_by_mime_type ⇒ Hash<String, Array<Resource>>
Group resources by MIME type.
-
#initialize(resources, client) ⇒ Catalog
constructor
Initialize a new Catalog with resource definitions.
-
#resources=(raw_resources) ⇒ Object
Convert raw resource data into Resource objects.
-
#search(keyword) ⇒ Array<Resource>
Search resources by keyword in name or description.
-
#uris ⇒ Array<String>
Get a list of all resource URIs.
Methods inherited from Collection
#all, #all!, #each, #each_page, #filter, #has_more_pages?, #next_page, #page, #size
Methods included from RequestTimeouts
Constructor Details
#initialize(resources, client) ⇒ Catalog
Initialize a new Catalog with resource definitions
33 34 35 36 37 |
# File 'lib/action_mcp/client/catalog.rb', line 33 def initialize(resources, client) super(resources, client) self.resources = @collection_data @load_method = :list_resources end |
Instance Method Details
#contains_uri?(uri) ⇒ Boolean
Check if the collection contains a resource with the given URI
74 75 76 |
# File 'lib/action_mcp/client/catalog.rb', line 74 def contains_uri?(uri) all.any? { |resource| resource.uri == uri } end |
#find_by_mime_type(mime_type) ⇒ Array<Resource>
Find resources by MIME type
59 60 61 |
# File 'lib/action_mcp/client/catalog.rb', line 59 def find_by_mime_type(mime_type) all.select { |resource| resource.mime_type == mime_type } end |
#find_by_name(name) ⇒ Array<Resource>
Find resources by name
51 52 53 |
# File 'lib/action_mcp/client/catalog.rb', line 51 def find_by_name(name) all.select { |resource| resource.name == name } end |
#find_by_uri(uri) ⇒ Resource?
Find a resource by URI
43 44 45 |
# File 'lib/action_mcp/client/catalog.rb', line 43 def find_by_uri(uri) all.find { |resource| resource.uri == uri } end |
#group_by_mime_type ⇒ Hash<String, Array<Resource>>
Group resources by MIME type
81 82 83 |
# File 'lib/action_mcp/client/catalog.rb', line 81 def group_by_mime_type all.group_by(&:mime_type) end |
#resources=(raw_resources) ⇒ Object
Convert raw resource data into Resource objects
100 101 102 |
# File 'lib/action_mcp/client/catalog.rb', line 100 def resources=(raw_resources) @collection_data = raw_resources.map { |resource_data| Resource.new(resource_data) } end |
#search(keyword) ⇒ Array<Resource>
Search resources by keyword in name or description
89 90 91 92 93 94 95 |
# File 'lib/action_mcp/client/catalog.rb', line 89 def search(keyword) keyword = keyword.downcase all.select do |resource| resource.name.downcase.include?(keyword) || resource.description&.downcase&.include?(keyword) end end |
#uris ⇒ Array<String>
Get a list of all resource URIs
66 67 68 |
# File 'lib/action_mcp/client/catalog.rb', line 66 def uris all.map(&:uri) end |