Module: FastMcp::FormatPredicateHandler

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

Overview

Module for handling format predicates

Instance Method Summary collapse

Instance Method Details

#add_date_time_format(predicate_name, property) ⇒ Object

Add date/time format to schema



476
477
478
479
480
481
482
483
484
485
486
# File 'lib/mcp/tool.rb', line 476

def add_date_time_format(predicate_name, property)
  property[:type] = 'string'
  case predicate_name
  when :date?
    property[:format] = 'date'
  when :date_time?
    property[:format] = 'date-time'
  when :time?
    property[:format] = 'time'
  end
end

#add_format_constraint(args, property) ⇒ Object

Add format constraint to schema



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'lib/mcp/tool.rb', line 510

def add_format_constraint(args, property)
  return unless args[0].is_a?(Symbol)

  case args[0]
  when :date_time
    property[:format] = 'date-time'
  when :date
    property[:format] = 'date'
  when :time
    property[:format] = 'time'
  when :email
    property[:format] = 'email'
  when :uri
    property[:format] = 'uri'
  end
end

#add_number_constraint(predicate_name, property) ⇒ Object

Add number constraint to schema



499
500
501
502
503
504
505
506
507
# File 'lib/mcp/tool.rb', line 499

def add_number_constraint(predicate_name, property)
  property[:type] = 'integer'
  case predicate_name
  when :odd?
    property[:not] = { multipleOf: 2 }
  when :even?
    property[:multipleOf] = 2
  end
end

#add_uuid_pattern(predicate_name, property) ⇒ Object

Add UUID pattern to schema



489
490
491
492
493
494
495
496
# File 'lib/mcp/tool.rb', line 489

def add_uuid_pattern(predicate_name, property)
  version = predicate_name.to_s.split('_').last[1].to_i
  property[:pattern] = if version == 4
                         '^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}$'
                       else
                         "^[0-9A-F]{8}-[0-9A-F]{4}-#{version}[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$"
                       end
end