Class: ActionMCP::Client::Catalog::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/action_mcp/client/catalog.rb

Overview

Internal Resource class to represent individual resources

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = []) ⇒ Resource

Initialize a new Resource instance

Parameters:

  • data (Hash) (defaults to: [])

    Resource definition hash containing uri, name, description, and mimeType



111
112
113
114
115
116
117
# File 'lib/action_mcp/client/catalog.rb', line 111

def initialize(data = [])
  @uri = data["uri"]
  @name = data["name"]
  @description = data["description"]
  @mime_type = data["mimeType"]
  @annotations = data["annotations"] || {}
end

Instance Attribute Details

#annotationsObject (readonly)

Returns the value of attribute annotations.



106
107
108
# File 'lib/action_mcp/client/catalog.rb', line 106

def annotations
  @annotations
end

#descriptionObject (readonly)

Returns the value of attribute description.



106
107
108
# File 'lib/action_mcp/client/catalog.rb', line 106

def description
  @description
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



106
107
108
# File 'lib/action_mcp/client/catalog.rb', line 106

def mime_type
  @mime_type
end

#nameObject (readonly)

Returns the value of attribute name.



106
107
108
# File 'lib/action_mcp/client/catalog.rb', line 106

def name
  @name
end

#uriObject (readonly)

Returns the value of attribute uri.



106
107
108
# File 'lib/action_mcp/client/catalog.rb', line 106

def uri
  @uri
end

Instance Method Details

#extensionString?

Get the file extension from the resource name

Returns:

  • (String, nil)

    The file extension or nil if no extension



122
123
124
# File 'lib/action_mcp/client/catalog.rb', line 122

def extension
  File.extname(@name)[1..] if @name.include?(".")
end

#image?Boolean

Check if this resource is an image based on MIME type

Returns:

  • (Boolean)

    true if the resource is an image



136
137
138
# File 'lib/action_mcp/client/catalog.rb', line 136

def image?
  @mime_type&.start_with?("image/")
end

#pathString?

Get the path portion of the URI

Returns:

  • (String, nil)

    The path component of the URI



143
144
145
146
147
# File 'lib/action_mcp/client/catalog.rb', line 143

def path
  URI(@uri).path
rescue StandardError
  nil
end

#text?Boolean

Check if this resource is a text file based on MIME type

Returns:

  • (Boolean)

    true if the resource is a text file



129
130
131
# File 'lib/action_mcp/client/catalog.rb', line 129

def text?
  @mime_type&.start_with?("text/")
end

#to_hHash

Generate a hash representation of the resource

Returns:

  • (Hash)

    Hash containing resource details



152
153
154
155
156
157
158
159
160
# File 'lib/action_mcp/client/catalog.rb', line 152

def to_h
  {
    "uri" => @uri,
    "name" => @name,
    "description" => @description,
    "mimeType" => @mime_type,
    "annotations" => @annotations
  }
end