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

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

    the server this resource template belongs to



31
32
33
34
35
36
37
38
39
# File 'lib/mcp_client/resource_template.rb', line 31

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



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

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

#descriptionString? (readonly)

Returns optional description.

Returns:

  • (String, nil)

    optional description



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

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



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

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

#nameString (readonly)

Returns the name of the resource template.

Returns:

  • (String)

    the name of the resource template



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

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

#serverObject (readonly)

Returns the value of attribute server.



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

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

#titleString? (readonly)

Returns optional human-readable name for display purposes.

Returns:

  • (String, nil)

    optional human-readable name for display purposes



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

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

#uri_templateString (readonly)

Returns URI template following RFC 6570.

Returns:

  • (String)

    URI template following RFC 6570



21
22
23
# File 'lib/mcp_client/resource_template.rb', line 21

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:



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

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'],
    server: server
  )
end