Class: ActiveMcp::Schema::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_mcp/schema/base.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context: {}) ⇒ Base

Returns a new instance of Base.



28
29
30
# File 'lib/active_mcp/schema/base.rb', line 28

def initialize(context: {})
  @context = context
end

Class Attribute Details

.promptsObject (readonly)

Returns the value of attribute prompts.



5
6
7
# File 'lib/active_mcp/schema/base.rb', line 5

def prompts
  @prompts
end

.resource_templatesObject (readonly)

Returns the value of attribute resource_templates.



5
6
7
# File 'lib/active_mcp/schema/base.rb', line 5

def resource_templates
  @resource_templates
end

.resourcesObject (readonly)

Returns the value of attribute resources.



5
6
7
# File 'lib/active_mcp/schema/base.rb', line 5

def resources
  @resources
end

.toolsObject (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(klass) ⇒ Object



22
23
24
25
# File 'lib/active_mcp/schema/base.rb', line 22

def prompt(klass)
  @prompts ||= []
  @prompts << klass
end

.resource(klass) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/active_mcp/schema/base.rb', line 7

def resource(klass)
  @resources ||= []
  @resources << klass

  if klass.class.respond_to?(:uri_template)
    @resource_templates ||= []
    @resource_templates << klass.class unless klass.class.in?(@resource_templates)
  end
end

.tool(klass) ⇒ Object



17
18
19
20
# File 'lib/active_mcp/schema/base.rb', line 17

def tool(klass)
  @tools ||= []
  @tools << klass
end

Instance Method Details

#promptsObject



50
51
52
53
54
# File 'lib/active_mcp/schema/base.rb', line 50

def prompts
  self.class.prompts&.filter do |resource|
    !resource.respond_to?(:visible?) || resource.visible?(context: @context)
  end
end

#resource_templatesObject



38
39
40
41
42
# File 'lib/active_mcp/schema/base.rb', line 38

def resource_templates
  self.class.resource_templates&.filter do |template|
    !template.respond_to?(:visible?) || template.visible?(context: @context)
  end
end

#resourcesObject



32
33
34
35
36
# File 'lib/active_mcp/schema/base.rb', line 32

def resources
  self.class.resources&.filter do |resource|
    !resource.respond_to?(:visible?) || resource.visible?(context: @context)
  end
end

#toolsObject



44
45
46
47
48
# File 'lib/active_mcp/schema/base.rb', line 44

def tools
  self.class.tools&.filter do |tool|
    !tool.respond_to?(:visible?) || tool.visible?(context: @context)
  end
end