Class: MCPClient::ResourceTemplate

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

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 rubocop:disable Metrics/ParameterLists

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



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mcp_client/resource_template.rb', line 38

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

#annotationsHash? (readonly)

Returns optional annotations that provide hints to clients.

Returns:

  • (Hash, nil)

    optional annotations that provide hints to clients



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

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

#descriptionString? (readonly)

Returns optional description.

Returns:

  • (String, nil)

    optional description



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

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



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

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

#metaHash? (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)



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

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

#mime_typeString? (readonly)

Returns optional MIME type for resources created from this template.

Returns:

  • (String, nil)

    optional MIME type for resources created from this template



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

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

#nameString (readonly)

Returns the name of the resource template.

Returns:

  • (String)

    the name of the resource template



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

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

#serverObject (readonly)

Returns the value of attribute server.



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

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

#titleString? (readonly)

Returns optional human-readable name for display purposes.

Returns:

  • (String, nil)

    optional human-readable name for display purposes



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

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

#uri_templateString (readonly)

Returns URI template following RFC 6570.

Returns:

  • (String)

    URI template following RFC 6570



25
26
27
# File 'lib/mcp_client/resource_template.rb', line 25

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:



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

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