Class: MCPClient::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp_client/resource.rb

Overview

Representation of an MCP resource

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new resource rubocop:disable Metrics/ParameterLists

Parameters:

  • uri (String)

    unique identifier for the resource

  • name (String)

    the name of the resource

  • title (String, nil) (defaults to: nil)

    optional human-readable name of the resource for display purposes

  • description (String, nil) (defaults to: nil)

    optional description

  • mime_type (String, nil) (defaults to: nil)

    optional MIME type

  • size (Integer, nil) (defaults to: nil)

    optional size in bytes

  • annotations (Hash, nil) (defaults to: nil)

    optional annotations that provide hints to clients

  • icons (Array<Hash>, nil) (defaults to: nil)

    optional icons for display in user interfaces (MCP 2025-11-25)

  • meta (Hash, nil) (defaults to: nil)

    optional _meta metadata attached to the resource (MCP 2025-11-25)

  • server (MCPClient::ServerBase, nil) (defaults to: nil)

    the server this resource belongs to



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mcp_client/resource.rb', line 40

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

Instance Attribute Details

#annotationsHash? (readonly)

Returns optional annotations that provide hints to clients.

Returns:

  • (Hash, nil)

    optional annotations that provide hints to clients



26
# File 'lib/mcp_client/resource.rb', line 26

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta, :server

#descriptionString? (readonly)

Returns optional description.

Returns:

  • (String, nil)

    optional description



26
# File 'lib/mcp_client/resource.rb', line 26

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta, :server

#iconsArray<Hash>? (readonly)

Returns optional icons for display in user interfaces (MCP 2025-11-25, SEP-973).

Returns:

  • (Array<Hash>, nil)

    optional icons for display in user interfaces (MCP 2025-11-25, SEP-973)



26
# File 'lib/mcp_client/resource.rb', line 26

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta, :server

#metaHash? (readonly)

Returns optional _meta metadata attached to the resource (MCP 2025-11-25).

Returns:

  • (Hash, nil)

    optional _meta metadata attached to the resource (MCP 2025-11-25)



26
# File 'lib/mcp_client/resource.rb', line 26

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta, :server

#mime_typeString? (readonly)

Returns optional MIME type.

Returns:

  • (String, nil)

    optional MIME type



26
# File 'lib/mcp_client/resource.rb', line 26

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta, :server

#nameString (readonly)

Returns the name of the resource.

Returns:

  • (String)

    the name of the resource



26
# File 'lib/mcp_client/resource.rb', line 26

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta, :server

#serverObject (readonly)

Returns the value of attribute server.



26
# File 'lib/mcp_client/resource.rb', line 26

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta, :server

#sizeInteger? (readonly)

Returns optional size in bytes.

Returns:

  • (Integer, nil)

    optional size in bytes



26
# File 'lib/mcp_client/resource.rb', line 26

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta, :server

#titleString? (readonly)

Returns optional human-readable name of the resource for display purposes.

Returns:

  • (String, nil)

    optional human-readable name of the resource for display purposes



26
# File 'lib/mcp_client/resource.rb', line 26

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :icons, :meta, :server

#uriString (readonly)

Returns unique identifier for the resource.

Returns:

  • (String)

    unique identifier for the resource



26
27
28
# File 'lib/mcp_client/resource.rb', line 26

def uri
  @uri
end

Class Method Details

.from_json(data, server: nil) ⇒ MCPClient::Resource

Create a Resource instance from JSON data

Parameters:

  • data (Hash)

    JSON data from MCP server

  • server (MCPClient::ServerBase, nil) (defaults to: nil)

    the server this resource belongs to

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/mcp_client/resource.rb', line 67

def self.from_json(data, server: nil)
  new(
    uri: data['uri'],
    name: data['name'],
    title: data['title'],
    description: data['description'],
    mime_type: data['mimeType'],
    size: data['size'],
    annotations: data['annotations'],
    icons: data['icons'],
    meta: data['_meta'],
    server: server
  )
end

Instance Method Details

#last_modifiedString?

Return the lastModified annotation value (ISO 8601 timestamp string)

Returns:

  • (String, nil)

    the lastModified timestamp, or nil if not set



57
58
59
60
61
# File 'lib/mcp_client/resource.rb', line 57

def last_modified
  return nil unless @annotations.is_a?(Hash)

  @annotations['lastModified'] || @annotations[:lastModified]
end