Module: FastMcp::PredicateHandler

Included in:
SchemaCompiler
Defined in:
lib/mcp/tool.rb

Overview

Module for handling predicates

Instance Method Summary collapse

Instance Method Details

#add_predicate_description(predicate_name, args, key_name, properties) ⇒ Object

Add predicate description to schema



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/mcp/tool.rb', line 397

def add_predicate_description(predicate_name, args, key_name, properties)
  property = properties[key_name]

  case predicate_name
  when :array?, :bool?, :decimal?, :float?, :hash?, :int?, :nil?, :str?
    add_basic_type(predicate_name, property)
  when :date?, :date_time?, :time?
    add_date_time_format(predicate_name, property)
  when :min_size?, :max_size?, :included_in?
    add_string_constraint(predicate_name, args, property)
  when :filled?
    # Already handled by the required array
  when :uri?
    property[:format] = 'uri'
  when :uuid_v1?, :uuid_v2?, :uuid_v3?, :uuid_v4?, :uuid_v5?
    add_uuid_pattern(predicate_name, property)
  when :gt?, :gteq?, :lt?, :lteq?
    add_numeric_constraint(predicate_name, args, property)
  when :odd?, :even?
    add_number_constraint(predicate_name, property)
  when :format?
    add_format_constraint(args, property)
  when :key?
    nil
  end
end

#extract_predicate_args(rule) ⇒ Object

Extract arguments from a predicate



386
387
388
389
390
391
392
393
394
# File 'lib/mcp/tool.rb', line 386

def extract_predicate_args(rule)
  if rule.respond_to?(:args) && !rule.args.nil?
    rule.args
  elsif rule.respond_to?(:predicate) && rule.predicate.respond_to?(:arguments)
    rule.predicate.arguments
  else
    []
  end
end

#extract_predicates(rule, key, properties = nil) ⇒ Object

Extract predicates from a rule



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/mcp/tool.rb', line 361

def extract_predicates(rule, key, properties = nil)
  properties ||= @json_schema[:properties]

  case rule
  when Dry::Logic::Operations::And
    rule.rules.each { |r| extract_predicates(r, key, properties) }
  when Dry::Logic::Operations::Implication
    extract_predicates(rule.right, key, properties)
  when Dry::Logic::Operations::Key
    extract_predicates(rule.rule, key, properties)
  when Dry::Logic::Operations::Set
    rule.rules.each { |r| extract_predicates(r, key, properties) }
  else
    process_predicate(rule, key, properties) if rule.respond_to?(:name)
  end
end

#process_predicate(rule, key, properties) ⇒ Object

Process a predicate



379
380
381
382
383
# File 'lib/mcp/tool.rb', line 379

def process_predicate(rule, key, properties)
  predicate_name = rule.name
  args = extract_predicate_args(rule)
  add_predicate_description(predicate_name, args, key, properties)
end