Class: MCP::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp/resource.rb,
lib/mcp/resource/contents.rb,
lib/mcp/resource/embedded.rb

Defined Under Namespace

Classes: BlobContents, Contents, Embedded, TextContents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, name:, title: nil, description: nil, icons: [], mime_type: nil, size: nil, meta: nil) ⇒ Resource

Returns a new instance of Resource.



10
11
12
13
14
15
16
17
18
19
# File 'lib/mcp/resource.rb', line 10

def initialize(uri:, name:, title: nil, description: nil, icons: [], mime_type: nil, size: nil, meta: nil)
  @uri = uri
  @name = name
  @title = title
  @description = description
  @icons = icons
  @mime_type = mime_type
  @size = size
  @meta = meta
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/mcp/resource.rb', line 8

def description
  @description
end

#iconsObject (readonly)

Returns the value of attribute icons.



8
9
10
# File 'lib/mcp/resource.rb', line 8

def icons
  @icons
end

#metaObject (readonly)

Returns the value of attribute meta.



8
9
10
# File 'lib/mcp/resource.rb', line 8

def meta
  @meta
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



8
9
10
# File 'lib/mcp/resource.rb', line 8

def mime_type
  @mime_type
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/mcp/resource.rb', line 8

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/mcp/resource.rb', line 8

def size
  @size
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/mcp/resource.rb', line 8

def title
  @title
end

#uriObject (readonly)

Returns the value of attribute uri.



8
9
10
# File 'lib/mcp/resource.rb', line 8

def uri
  @uri
end

Instance Method Details

#to_hObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mcp/resource.rb', line 21

def to_h
  {
    uri: uri,
    name: name,
    title: title,
    description: description,
    icons: icons&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
    mimeType: mime_type,
    size: size,
    _meta: meta,
  }.compact
end