Class: ActiveMcp::Schema::Base
- Inherits:
-
Object
- Object
- ActiveMcp::Schema::Base
- Defined in:
- lib/active_mcp/schema/base.rb
Class Attribute Summary collapse
-
.prompts ⇒ Object
readonly
Returns the value of attribute prompts.
-
.resources ⇒ Object
readonly
Returns the value of attribute resources.
-
.tools ⇒ Object
readonly
Returns the value of attribute tools.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(context: {}) ⇒ Base
constructor
A new instance of Base.
- #visible_prompts ⇒ Object
- #visible_resource_templates ⇒ Object
- #visible_resources ⇒ Object
- #visible_tools ⇒ Object
Constructor Details
#initialize(context: {}) ⇒ Base
Returns a new instance of Base.
23 24 25 |
# File 'lib/active_mcp/schema/base.rb', line 23 def initialize(context: {}) @context = context end |
Class Attribute Details
.prompts ⇒ Object (readonly)
Returns the value of attribute prompts.
5 6 7 |
# File 'lib/active_mcp/schema/base.rb', line 5 def prompts @prompts end |
.resources ⇒ Object (readonly)
Returns the value of attribute resources.
5 6 7 |
# File 'lib/active_mcp/schema/base.rb', line 5 def resources @resources end |
.tools ⇒ Object (readonly)
Returns the value of attribute tools.
5 6 7 |
# File 'lib/active_mcp/schema/base.rb', line 5 def tools @tools end |
Class Method Details
.prompt(value) ⇒ Object
17 18 19 20 |
# File 'lib/active_mcp/schema/base.rb', line 17 def prompt(value) @prompts ||= [] @prompts << value end |
.resource(value, items: []) ⇒ Object
12 13 14 15 |
# File 'lib/active_mcp/schema/base.rb', line 12 def resource(value, items: []) @resources ||= [] @resources << {klass: value, items:} end |
.tool(value) ⇒ Object
7 8 9 10 |
# File 'lib/active_mcp/schema/base.rb', line 7 def tool(value) @tools ||= [] @tools << value end |
Instance Method Details
#visible_prompts ⇒ Object
51 52 53 54 55 |
# File 'lib/active_mcp/schema/base.rb', line 51 def visible_prompts self.class.prompts&.filter do |resource| !resource.respond_to?(:visible?) || resource.visible?(context: @context) end end |
#visible_resource_templates ⇒ Object
38 39 40 41 42 43 |
# File 'lib/active_mcp/schema/base.rb', line 38 def visible_resource_templates visibles = self.class.resources&.filter do |resource| resource[:klass].respond_to?(:uri_template) && (!resource[:klass].respond_to?(:visible?) || resource[:klass].visible?(context: @context)) end visibles&.map { _1[:klass] } || [] end |
#visible_resources ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_mcp/schema/base.rb', line 27 def visible_resources visibles = self.class.resources&.filter do |resource| !resource[:klass].respond_to?(:visible?) || resource[:klass].visible?(context: @context) end visibles&.map do |resource| resource[:items].map do |item| resource[:klass].new(**item) end end&.flatten || [] end |
#visible_tools ⇒ Object
45 46 47 48 49 |
# File 'lib/active_mcp/schema/base.rb', line 45 def visible_tools self.class.tools&.filter do |tool| !tool.respond_to?(:visible?) || tool.visible?(context: @context) end end |