Class: ModelContextProtocol::Server::Resource::AnnotationsDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/model_context_protocol/server/resource.rb

Constant Summary collapse

VALID_AUDIENCE_VALUES =
[:user, :assistant].freeze

Instance Method Summary collapse

Constructor Details

#initializeAnnotationsDSL

Returns a new instance of AnnotationsDSL.



127
128
129
130
131
# File 'lib/model_context_protocol/server/resource.rb', line 127

def initialize
  @audience = nil
  @priority = nil
  @last_modified = nil
end

Instance Method Details

#audience(value) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/model_context_protocol/server/resource.rb', line 133

def audience(value)
  normalized_value = Array(value).map(&:to_sym)
  invalid_values = normalized_value - VALID_AUDIENCE_VALUES
  unless invalid_values.empty?
    raise ArgumentError, "Invalid audience values: #{invalid_values.join(", ")}. Valid values are: #{VALID_AUDIENCE_VALUES.join(", ")}"
  end
  @audience = normalized_value.map(&:to_s)
end

#last_modified(value) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'lib/model_context_protocol/server/resource.rb', line 149

def last_modified(value)
  # Validate ISO 8601 format
  begin
    Time.iso8601(value)
  rescue ArgumentError
    raise ArgumentError, "lastModified must be in ISO 8601 format (e.g., '2025-01-12T15:00:58Z'), got: #{value}"
  end
  @last_modified = value
end

#priority(value) ⇒ Object



142
143
144
145
146
147
# File 'lib/model_context_protocol/server/resource.rb', line 142

def priority(value)
  unless value.is_a?(Numeric) && value >= 0.0 && value <= 1.0
    raise ArgumentError, "Priority must be a number between 0.0 and 1.0, got: #{value}"
  end
  @priority = value.to_f
end

#serializedObject



159
160
161
162
163
164
165
# File 'lib/model_context_protocol/server/resource.rb', line 159

def serialized
  result = {}
  result[:audience] = @audience if @audience
  result[:priority] = @priority if @priority
  result[:lastModified] = @last_modified if @last_modified
  result.empty? ? nil : result
end