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



124
125
126
127
128
# File 'lib/model_context_protocol/server/resource.rb', line 124

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

Instance Method Details

#audience(value) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/model_context_protocol/server/resource.rb', line 130

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



146
147
148
149
150
151
152
153
154
# File 'lib/model_context_protocol/server/resource.rb', line 146

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



139
140
141
142
143
144
# File 'lib/model_context_protocol/server/resource.rb', line 139

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



156
157
158
159
160
161
162
# File 'lib/model_context_protocol/server/resource.rb', line 156

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