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, 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

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

    the server this resource belongs to



33
34
35
36
37
38
39
40
41
42
# File 'lib/mcp_client/resource.rb', line 33

def initialize(uri:, name:, title: nil, description: nil, mime_type: nil, size: nil, annotations: nil, server: nil)
  @uri = uri
  @name = name
  @title = title
  @description = description
  @mime_type = mime_type
  @size = size
  @annotations = annotations
  @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



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

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

#descriptionString? (readonly)

Returns optional description.

Returns:

  • (String, nil)

    optional description



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

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

#mime_typeString? (readonly)

Returns optional MIME type.

Returns:

  • (String, nil)

    optional MIME type



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

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

#nameString (readonly)

Returns the name of the resource.

Returns:

  • (String)

    the name of the resource



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

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

#serverObject (readonly)

Returns the value of attribute server.



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

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

#sizeInteger? (readonly)

Returns optional size in bytes.

Returns:

  • (Integer, nil)

    optional size in bytes



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

attr_reader :uri, :name, :title, :description, :mime_type, :size, :annotations, :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



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

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

#uriString (readonly)

Returns unique identifier for the resource.

Returns:

  • (String)

    unique identifier for the resource



22
23
24
# File 'lib/mcp_client/resource.rb', line 22

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:



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/mcp_client/resource.rb', line 56

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'],
    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



46
47
48
49
50
# File 'lib/mcp_client/resource.rb', line 46

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

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