Class: MCPClient::Resource

Inherits:
Object
  • Object
show all
Includes:
DeepCopy
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

Methods included from DeepCopy

copy, #initialize_copy, shallow_copy

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

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



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mcp_client/resource.rb', line 43

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

#annotations ⇒ Hash? (readonly)

Returns optional annotations that provide hints to clients.

Returns:

  • (Hash, nil) —

    optional annotations that provide hints to clients



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

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

#description ⇒ String? (readonly)

Returns optional description.

Returns:

  • (String, nil) —

    optional description



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

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

#icons ⇒ Array<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)



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

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

#meta ⇒ Hash? (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)



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

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

#mime_type ⇒ String? (readonly)

Returns optional MIME type.

Returns:

  • (String, nil) —

    optional MIME type



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

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

#name ⇒ String (readonly)

Returns the name of the resource.

Returns:

  • (String) —

    the name of the resource



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

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

#server ⇒ Object (readonly)

Returns the value of attribute server.



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

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

#size ⇒ Integer? (readonly)

Returns optional size in bytes.

Returns:

  • (Integer, nil) —

    optional size in bytes



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

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

#title ⇒ String? (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



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

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

#uri ⇒ String (readonly)

Returns unique identifier for the resource.

Returns:

  • (String) —

    unique identifier for the resource



30
31
32
# File 'lib/mcp_client/resource.rb', line 30

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:



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

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_modified ⇒ String?

Return the lastModified annotation value (ISO 8601 timestamp string)

Returns:

  • (String, nil) —

    the lastModified timestamp, or nil if not set



59
60
61
62
63
# File 'lib/mcp_client/resource.rb', line 59

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

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