-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathprompt.rb
More file actions
37 lines (28 loc) · 840 Bytes
/
prompt.rb
File metadata and controls
37 lines (28 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# typed: strict
# frozen_string_literal: true
module MCP
class Prompt
attr_reader :name, :description, :arguments, :to_h
class << self
def define(...) = new(...)
private :new
private
def inherited(subclass)
super
raise TypeError, "#{self} should no longer be subclassed. Use #{self}.define factory method instead."
end
end
def initialize(name:, description:, arguments:, &block)
arguments = arguments.map { |arg| Hash === arg ? Argument.new(**arg) : arg }
@name = name
@description = description
@arguments = arguments
@block = block
@to_h = { name:, description:, arguments: arguments.map(&:to_h) }.compact.freeze
freeze
end
def call(args, server_context:)
@block.call(args, server_context:)
end
end
end