Class: ActionMCP::Client::Blueprint::ResourceTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/action_mcp/client/blueprint.rb

Overview

Internal Blueprint class to represent individual URI templates

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ResourceTemplate

Initialize a new ResourceTemplate instance

Parameters:

  • data (Hash)

    ResourceTemplate definition hash containing uriTemplate, name, description, and optionally mimeType, and annotations



98
99
100
101
102
103
104
105
# File 'lib/action_mcp/client/blueprint.rb', line 98

def initialize(data)
  @pattern = data["uriTemplate"]
  @name = data["name"]
  @description = data["description"]
  @mime_type = data["mimeType"]
  @variable_pattern = /{([^}]+)}/
  @annotations = data["annotations"] || {}
end

Instance Attribute Details

#annotationsObject (readonly)

Returns the value of attribute annotations.



92
93
94
# File 'lib/action_mcp/client/blueprint.rb', line 92

def annotations
  @annotations
end

#descriptionObject (readonly)

Returns the value of attribute description.



92
93
94
# File 'lib/action_mcp/client/blueprint.rb', line 92

def description
  @description
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



92
93
94
# File 'lib/action_mcp/client/blueprint.rb', line 92

def mime_type
  @mime_type
end

#nameObject (readonly)

Returns the value of attribute name.



92
93
94
# File 'lib/action_mcp/client/blueprint.rb', line 92

def name
  @name
end

#patternObject (readonly)

Returns the value of attribute pattern.



92
93
94
# File 'lib/action_mcp/client/blueprint.rb', line 92

def pattern
  @pattern
end

Instance Method Details

#compatible_with?(params) ⇒ Boolean

Check if this template is compatible with a set of parameters

Parameters:

  • params (Hash)

    Parameters to check

Returns:

  • (Boolean)

    true if all required variables have corresponding parameters



143
144
145
146
# File 'lib/action_mcp/client/blueprint.rb', line 143

def compatible_with?(params)
  symbolized_params = params.transform_keys(&:to_sym)
  variables.all? { |var| symbolized_params.key?(var.to_sym) }
end

#construct(params) ⇒ String

Construct a concrete URI by substituting parameters into the template pattern

Parameters:

  • params (Hash)

    Parameters to substitute into the pattern

Returns:

  • (String)

    The constructed URI with parameters applied

Raises:

  • (KeyError)

    If a required parameter is missing



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/action_mcp/client/blueprint.rb', line 126

def construct(params)
  result = @pattern.dup

  variables.each do |var|
    raise KeyError, "Missing required parameter: #{var}" unless params.key?(var.to_sym) || params.key?(var)

    value = params[var.to_sym] || params[var]
    result.gsub!("{#{var}}", value.to_s)
  end

  result
end

#protocolString

Get the protocol part of the URI template

Returns:

  • (String)

    The protocol (scheme) of the URI template



117
118
119
# File 'lib/action_mcp/client/blueprint.rb', line 117

def protocol
  @pattern.split("://").first
end

#to_hHash

Generate a hash representation of the blueprint

Returns:

  • (Hash)

    Hash containing blueprint details



151
152
153
154
155
156
157
158
159
# File 'lib/action_mcp/client/blueprint.rb', line 151

def to_h
  {
    "uriTemplate" => @pattern,
    "name" => @name,
    "description" => @description,
    "mimeType" => @mime_type,
    "annotations" => @annotations
  }
end

#variablesArray<String>

Extract variable names from the template pattern

Returns:

  • (Array<String>)

    List of variable names in the pattern



110
111
112
# File 'lib/action_mcp/client/blueprint.rb', line 110

def variables
  @pattern.scan(@variable_pattern).flatten
end