Class: MCP::Prompt
- Inherits:
-
Object
show all
- Defined in:
- lib/mcp/prompt.rb,
lib/mcp/prompt/result.rb,
lib/mcp/prompt/message.rb,
lib/mcp/prompt/argument.rb
Defined Under Namespace
Classes: Argument, Message, Result
Constant Summary
collapse
- NOT_SET =
Object.new
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.arguments_value ⇒ Object
Returns the value of attribute arguments_value.
11
12
13
|
# File 'lib/mcp/prompt.rb', line 11
def arguments_value
@arguments_value
end
|
.description_value ⇒ Object
Returns the value of attribute description_value.
9
10
11
|
# File 'lib/mcp/prompt.rb', line 9
def description_value
@description_value
end
|
.icons_value ⇒ Object
Returns the value of attribute icons_value.
10
11
12
|
# File 'lib/mcp/prompt.rb', line 10
def icons_value
@icons_value
end
|
Returns the value of attribute meta_value.
12
13
14
|
# File 'lib/mcp/prompt.rb', line 12
def meta_value
@meta_value
end
|
.title_value ⇒ Object
Returns the value of attribute title_value.
8
9
10
|
# File 'lib/mcp/prompt.rb', line 8
def title_value
@title_value
end
|
Class Method Details
.arguments(value = NOT_SET) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/mcp/prompt.rb', line 75
def arguments(value = NOT_SET)
if value == NOT_SET
@arguments_value
else
@arguments_value = value
end
end
|
.define(name: nil, title: nil, description: nil, icons: [], arguments: [], meta: nil, &block) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/mcp/prompt.rb', line 91
def define(name: nil, title: nil, description: nil, icons: [], arguments: [], meta: nil, &block)
Class.new(self) do
prompt_name name
title title
description description
icons icons
arguments arguments
define_singleton_method(:template) do |args, server_context: nil|
instance_exec(args, server_context: server_context, &block)
end
meta meta
end
end
|
.description(value = NOT_SET) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/mcp/prompt.rb', line 59
def description(value = NOT_SET)
if value == NOT_SET
@description_value
else
@description_value = value
end
end
|
.icons(value = NOT_SET) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/mcp/prompt.rb', line 67
def icons(value = NOT_SET)
if value == NOT_SET
@icons_value
else
@icons_value = value
end
end
|
.inherited(subclass) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/mcp/prompt.rb', line 29
def inherited(subclass)
super
subclass.instance_variable_set(:@name_value, nil)
subclass.instance_variable_set(:@title_value, nil)
subclass.instance_variable_set(:@description_value, nil)
subclass.instance_variable_set(:@icons_value, nil)
subclass.instance_variable_set(:@arguments_value, nil)
subclass.instance_variable_set(:@meta_value, nil)
end
|
83
84
85
86
87
88
89
|
# File 'lib/mcp/prompt.rb', line 83
def meta(value = NOT_SET)
if value == NOT_SET
@meta_value
else
@meta_value = value
end
end
|
.name_value ⇒ Object
47
48
49
|
# File 'lib/mcp/prompt.rb', line 47
def name_value
@name_value || StringUtils.handle_from_class_name(name)
end
|
.prompt_name(value = NOT_SET) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/mcp/prompt.rb', line 39
def prompt_name(value = NOT_SET)
if value == NOT_SET
@name_value
else
@name_value = value
end
end
|
.template(args, server_context: nil) ⇒ Object
14
15
16
|
# File 'lib/mcp/prompt.rb', line 14
def template(args, server_context: nil)
raise NotImplementedError, "Subclasses must implement template"
end
|
.title(value = NOT_SET) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/mcp/prompt.rb', line 51
def title(value = NOT_SET)
if value == NOT_SET
@title_value
else
@title_value = value
end
end
|
.to_h ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/mcp/prompt.rb', line 18
def to_h
{
name: name_value,
title: title_value,
description: description_value,
icons: icons_value&.then { |icons| icons.empty? ? nil : icons.map(&:to_h) },
arguments: arguments_value&.map(&:to_h),
_meta: meta_value,
}.compact
end
|
.validate_arguments!(args) ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/mcp/prompt.rb', line 105
def validate_arguments!(args)
missing = required_args - args.keys
return if missing.empty?
raise MCP::Server::RequestHandlerError.new(
"Missing required arguments: #{missing.join(", ")}", nil, error_type: :missing_required_arguments
)
end
|