Class: StimulusPlumbers::MCP::Plugins::ComponentSchema

Inherits:
Base
  • Object
show all
Defined in:
lib/stimulus_plumbers/mcp/plugins/component_schema.rb

Class Method Summary collapse

Methods inherited from Base

json_resource, not_found, text_resource, text_tool

Class Method Details

.dynamic_resource_templatesObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/stimulus_plumbers/mcp/plugins/component_schema.rb', line 33

def dynamic_resource_templates
  [
    ::MCP::ResourceTemplate.new(
      uri_template: "component://{name}/schema",
      name:         "component-schema",
      description:  "Params, valid values, defaults, and required controllers for a component",
      mime_type:    "application/json"
    )
  ].freeze
end

.loaderObject



12
13
14
# File 'lib/stimulus_plumbers/mcp/plugins/component_schema.rb', line 12

def loader
  ComponentSchemaLoader
end

.loader_keyObject



8
9
10
# File 'lib/stimulus_plumbers/mcp/plugins/component_schema.rb', line 8

def loader_key
  :component_schema
end

.read(uri, store) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/stimulus_plumbers/mcp/plugins/component_schema.rb', line 44

def read(uri, store)
  schema = store[:component_schema]

  case uri
  when "component://index"
    json_resource(uri, schema[:components].keys)
  when "component://integration"
    json_resource(uri, schema[:controllers])
  when %r{\Acomponent://([^/]+)/schema\z}
    key = Regexp.last_match(1).to_sym
    json_resource(uri, component_data(schema, key) || { error: "unknown component: #{key}" })
  end
end

.register_tools(server, store) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/stimulus_plumbers/mcp/plugins/component_schema.rb', line 58

def register_tools(server, store)
  schema = store[:component_schema]
  data_by_component = component_data_map(schema)

  register_list_components(server, schema)
  register_get_component_schema(server, data_by_component)
  register_get_field_as_values(server, schema)
  register_get_field_as_controller(server, schema)
end

.static_resourcesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stimulus_plumbers/mcp/plugins/component_schema.rb', line 16

def static_resources
  [
    ::MCP::Resource.new(
      uri:         "component://index",
      name:        "components-index",
      description: "Index of all stimulus-plumbers component theme keys",
      mime_type:   "application/json"
    ),
    ::MCP::Resource.new(
      uri:         "component://integration",
      name:        "component-integration",
      description: "Mapping from Rails component name to the Stimulus controller identifiers it requires",
      mime_type:   "application/json"
    )
  ].freeze
end