Class: MCPClient::ResourceTemplate

Inherits:
Object
  • Object
show all
Includes:
DeepCopy
Defined in:
lib/mcp_client/resource_template.rb

Overview

Representation of an MCP resource template Resource templates allow servers to expose parameterized resources using URI templates

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_template:, name:, title: nil, description: nil, mime_type: nil, annotations: nil, icons: nil, meta: nil, server: nil) ⇒ ResourceTemplate

Initialize a new resource template

Parameters:

  • uri_template (String) —

    URI template following RFC 6570

  • name (String) —

    the name of the resource template

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

    optional human-readable name for display purposes

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

    optional description

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

    optional MIME type

  • 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 template (MCP 2025-11-25)

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

    the server this resource template belongs to



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

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



29
# File 'lib/mcp_client/resource_template.rb', line 29

attr_reader :uri_template, :name, :title, :description, :mime_type, :annotations, :icons, :meta, :server

#description ⇒ String? (readonly)

Returns optional description.

Returns:

  • (String, nil) —

    optional description



29
# File 'lib/mcp_client/resource_template.rb', line 29

attr_reader :uri_template, :name, :title, :description, :mime_type, :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)



29
# File 'lib/mcp_client/resource_template.rb', line 29

attr_reader :uri_template, :name, :title, :description, :mime_type, :annotations, :icons, :meta, :server

#meta ⇒ Hash? (readonly)

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

Returns:

  • (Hash, nil) —

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



29
# File 'lib/mcp_client/resource_template.rb', line 29

attr_reader :uri_template, :name, :title, :description, :mime_type, :annotations, :icons, :meta, :server

#mime_type ⇒ String? (readonly)

Returns optional MIME type for resources created from this template.

Returns:

  • (String, nil) —

    optional MIME type for resources created from this template



29
# File 'lib/mcp_client/resource_template.rb', line 29

attr_reader :uri_template, :name, :title, :description, :mime_type, :annotations, :icons, :meta, :server

#name ⇒ String (readonly)

Returns the name of the resource template.

Returns:

  • (String) —

    the name of the resource template



29
# File 'lib/mcp_client/resource_template.rb', line 29

attr_reader :uri_template, :name, :title, :description, :mime_type, :annotations, :icons, :meta, :server

#server ⇒ Object (readonly)

Returns the value of attribute server.



29
# File 'lib/mcp_client/resource_template.rb', line 29

attr_reader :uri_template, :name, :title, :description, :mime_type, :annotations, :icons, :meta, :server

#title ⇒ String? (readonly)

Returns optional human-readable name for display purposes.

Returns:

  • (String, nil) —

    optional human-readable name for display purposes



29
# File 'lib/mcp_client/resource_template.rb', line 29

attr_reader :uri_template, :name, :title, :description, :mime_type, :annotations, :icons, :meta, :server

#uri_template ⇒ String (readonly)

Returns URI template following RFC 6570.

Returns:

  • (String) —

    URI template following RFC 6570



29
30
31
# File 'lib/mcp_client/resource_template.rb', line 29

def uri_template
  @uri_template
end

Class Method Details

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

Create a ResourceTemplate instance from JSON data

Parameters:

  • data (Hash) —

    JSON data from MCP server

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

    the server this resource template belongs to

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/mcp_client/resource_template.rb', line 58

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