stimulus_plumbers_mcp 0.4.4 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +120 -0
  3. data/bin/bump-version +26 -0
  4. data/bin/mcp-query +107 -0
  5. data/bin/server +8 -0
  6. data/bin/stimulus-plumbers-mcp +7 -0
  7. data/lib/stimulus_plumbers/mcp/cli.rb +13 -0
  8. data/lib/stimulus_plumbers/mcp/loaders/aria_loader.rb +31 -0
  9. data/lib/stimulus_plumbers/mcp/loaders/component_docs_loader.rb +38 -0
  10. data/lib/stimulus_plumbers/mcp/loaders/component_requirements.rb +41 -0
  11. data/lib/stimulus_plumbers/mcp/loaders/component_schema_loader.rb +49 -0
  12. data/lib/stimulus_plumbers/mcp/loaders/component_theme_loader.rb +41 -0
  13. data/lib/stimulus_plumbers/mcp/loaders/controller_docs_loader.rb +31 -0
  14. data/lib/stimulus_plumbers/mcp/loaders/controller_schema_loader.rb +49 -0
  15. data/lib/stimulus_plumbers/mcp/loaders/guide.md +48 -0
  16. data/lib/stimulus_plumbers/mcp/loaders/guide_loader.rb +40 -4
  17. data/lib/stimulus_plumbers/mcp/loaders/icons_loader.rb +34 -0
  18. data/lib/stimulus_plumbers/mcp/loaders/support/docs_table_parser.rb +112 -0
  19. data/lib/stimulus_plumbers/mcp/loaders/support/gem_vendor_path.rb +18 -0
  20. data/lib/stimulus_plumbers/mcp/loaders/tailwind_loader.rb +35 -0
  21. data/lib/stimulus_plumbers/mcp/loaders/versions_loader.rb +110 -0
  22. data/lib/stimulus_plumbers/mcp/plugins/aria.rb +34 -0
  23. data/lib/stimulus_plumbers/mcp/plugins/base.rb +40 -31
  24. data/lib/stimulus_plumbers/mcp/plugins/component_docs.rb +96 -0
  25. data/lib/stimulus_plumbers/mcp/plugins/component_schema.rb +133 -0
  26. data/lib/stimulus_plumbers/mcp/plugins/component_theme.rb +90 -0
  27. data/lib/stimulus_plumbers/mcp/plugins/controller_docs.rb +91 -0
  28. data/lib/stimulus_plumbers/mcp/plugins/controller_schema.rb +81 -0
  29. data/lib/stimulus_plumbers/mcp/plugins/guide.rb +70 -16
  30. data/lib/stimulus_plumbers/mcp/plugins/icons.rb +42 -0
  31. data/lib/stimulus_plumbers/mcp/plugins/tailwind.rb +69 -45
  32. data/lib/stimulus_plumbers/mcp/plugins/versions.rb +44 -0
  33. data/lib/stimulus_plumbers/mcp/server.rb +26 -9
  34. data/lib/stimulus_plumbers/mcp/version.rb +1 -1
  35. data/lib/stimulus_plumbers_mcp.rb +32 -11
  36. metadata +36 -13
  37. data/lib/stimulus_plumbers/mcp/loaders/component_controller_map.rb +0 -38
  38. data/lib/stimulus_plumbers/mcp/loaders/docs_loader.rb +0 -122
  39. data/lib/stimulus_plumbers/mcp/loaders/schema_loader.rb +0 -45
  40. data/lib/stimulus_plumbers/mcp/loaders/stimulus_manifest.rb +0 -23
  41. data/lib/stimulus_plumbers/mcp/loaders/tailwind_theme_loader.rb +0 -29
  42. data/lib/stimulus_plumbers/mcp/loaders/theme_loader.rb +0 -97
  43. data/lib/stimulus_plumbers/mcp/plugins/docs.rb +0 -82
  44. data/lib/stimulus_plumbers/mcp/plugins/schema.rb +0 -110
  45. data/lib/stimulus_plumbers/mcp/plugins/stimulus.rb +0 -66
  46. data/lib/stimulus_plumbers/mcp/plugins/theme.rb +0 -66
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00ce340e2b2d68fcfef0406efd76e88e91c5214c653bc44cbed78d6ebf23bd4e
4
- data.tar.gz: c4ec9ad1abdabfb7ab464b685e604d78feec3a67b10944339885adbd5f322668
3
+ metadata.gz: 33ad1eb09fa4ed8fa1780dffe068f475fc04f3b3e1f179d6cbda211190155dc9
4
+ data.tar.gz: 29fecb05f19a17c3b398d8eb9189167e87cfe2f6f13d2b511472884ed9ebc935
5
5
  SHA512:
6
- metadata.gz: 752269bd37dc2716c2fdabf2aab3bb6cecb9bd6aaae82ff245c95414ef98c9a670ac1da896a32dafa00b9d47b8231214b5f150f3ca1efd7705faafe978eabccb
7
- data.tar.gz: 8540984025d8870982f1d75d8a33a51dfcb3096084eb8c8d0ef0dc5cc39f62b02310f787568a0d34a8cb49ac055273b6f2fa7254b398a67703879d750dceb9f5
6
+ metadata.gz: cd757ac9c1c357f3b71c1683816ab497718215ac181e2773af6d02bca45f95114c725e501a3218a71aefa11a4e090d233efdaa085a0a01e7af399745f4082284
7
+ data.tar.gz: 8481e2f13c22dfccbfa0e089442bdec11fe9475c408e4d189567ea4b60b2557aa1f959698c5bc511d428b079f1fbcc5038b327729b4e43b7eb78da8f2261720c
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # stimulus-plumbers-mcp
2
+
3
+ MCP server for [`stimulus_plumbers`](../stimulus-plumbers-rails). Exposes the component API schema, documentation, and Stimulus controller metadata to LLM-powered IDEs.
4
+
5
+ ## Requirements
6
+
7
+ - Ruby >= 3.0
8
+ - Node (contributors only — to build the Stimulus controller manifest)
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ gem install stimulus_plumbers_mcp
14
+ ```
15
+
16
+ ## Resources
17
+
18
+ | URI | Content |
19
+ |-----|---------|
20
+ | `guide://overview` | **Start here** — map of the form/view/stimulus API with pointers to every tool/resource |
21
+ | `guide://{name}` | Per-package usage guide: `component` (Rails forms/views), `controller` (plain-JS/non-Rails setup), `tailwind` (Tailwind install/theming), `theme` (custom theme integration contract) |
22
+ | `aria://reference` | WCAG 2.1 AA criteria, keyboard navigation patterns, and per-component ARIA patterns |
23
+ | `component://index` | Index of all component theme keys |
24
+ | `component://icons` | All available icon names |
25
+ | `component://integration` | Map from component key → required Stimulus controller identifiers |
26
+ | `component://{name}/schema` | Params, valid values, defaults + required controllers |
27
+ | `component://{name}/docs` | Full markdown doc with ERB examples |
28
+ | `component://{name}/helper` | Full `sp_` helper surface: keyword options + defaults (grouped by helper signature) + slot methods |
29
+ | `component://theme` | Index of theme-implementable component keys |
30
+ | `component://{name}/theme` | Method name, param signature, return contract |
31
+ | `component://theme/base` | Custom theme authoring guide |
32
+ | `component://tailwind` | Index of Tailwind theme component keys |
33
+ | `component://{name}/tailwind` | Tailwind CSS classes per variant |
34
+ | `controller://index` | Index of Stimulus controller identifiers |
35
+ | `controller://{name}/schema` | Targets, values, outlets, classes for a controller |
36
+ | `controller://docs` | Index of JS controller narrative docs, grouped by controller family |
37
+ | `controller://docs/{name}` | Narrative usage doc for a controller family (plain-JS/Hotwire, no Rails helpers) |
38
+ | `versions://sources` | Resolved version (and resolution path) of each source gem/package |
39
+
40
+ ## Tools
41
+
42
+ | Tool | Input | Output |
43
+ |------|-------|--------|
44
+ | `list_components` | — | All component theme keys |
45
+ | `list_component_docs` | — | Components with markdown docs + helper signatures (the `component://{name}/docs`+`/helper` set) |
46
+ | `get_component_schema` | `name` | Themed params (type/variant/size) + defaults + required controllers |
47
+ | `get_component_helper` | `name` | Full `sp_` helper surface — keyword options grouped by helper signature (incl. `icon_leading`) + slot methods |
48
+ | `get_component_examples` | `name` | ERB code fences from docs |
49
+ | `get_field_as_values` | `builder_method` (`field`/`collection_field`/`choice`) | Valid `as:` values |
50
+ | `get_component_theme` | `name` | Method signature + return contract for custom theme |
51
+ | `get_component_tailwind` | `name` | Tailwind CSS utility classes per variant |
52
+ | `list_controllers` | — | All Stimulus controller identifiers |
53
+ | `get_controller_schema` | `name` | Targets, values, outlets, classes |
54
+ | `list_controller_docs` | — | Controller doc families available at `controller://docs/{name}` |
55
+ | `get_controller_docs` | `name` | Narrative usage doc for a controller family |
56
+ | `get_source_versions` | — | Resolved version (and resolution path) of each source |
57
+ | `list_guides` | — | Available per-package guide names (`component`/`controller`/`tailwind`/`theme`) |
58
+ | `get_guide` | `name` | Per-package usage guide content |
59
+
60
+ ## IDE Setup
61
+
62
+ ```json
63
+ {
64
+ "mcpServers": {
65
+ "stimulus-plumbers": {
66
+ "command": "gem",
67
+ "args": ["exec", "stimulus-plumbers-mcp"]
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ Requires Ruby >= 3.3. No `cwd` required. Pin a specific version by adding it to your `Gemfile` and running `bundle exec gem exec stimulus-plumbers-mcp`.
74
+
75
+ ## Stimulus Manifest
76
+
77
+ `controller://` resources require the controller manifest. The server resolves it in order:
78
+
79
+ 1. `node_modules/@stimulus-plumbers/controllers/dist/controllers.manifest.json` — npm/yarn/bun projects
80
+ 2. `vendor/controllers.manifest.json` inside the installed `stimulus_plumbers` gem — importmaps fallback
81
+ 3. `../stimulus-plumbers/dist/controllers.manifest.json` — monorepo dev fallback
82
+
83
+ No extra steps needed for setups 1 or 2.
84
+
85
+ ## Development
86
+
87
+ ```bash
88
+ git clone https://github.com/ryancyq/stimulus-plumbers
89
+ cd stimulus-plumbers/stimulus-plumbers-mcp
90
+ bundle install
91
+
92
+ # Build the Stimulus controller manifest (pure Node, no toolchain install needed)
93
+ cd ../stimulus-plumbers && node --run build:manifest && cd -
94
+
95
+ # Start the server
96
+ bundle exec ruby bin/server
97
+ ```
98
+
99
+ ### Manual querying
100
+
101
+ `bin/mcp-query` wraps the JSON-RPC stdio protocol for quick manual inspection:
102
+
103
+ ```bash
104
+ bundle exec ruby bin/mcp-query tools # list tools
105
+ bundle exec ruby bin/mcp-query resources # list resources
106
+ bundle exec ruby bin/mcp-query tool list_components # call a tool (no args)
107
+ bundle exec ruby bin/mcp-query tool get_component_schema '{"name":"button"}'
108
+ bundle exec ruby bin/mcp-query read guide://overview
109
+ bundle exec ruby bin/mcp-query read component://form/docs
110
+ ```
111
+
112
+ ```bash
113
+ bundle exec rake test:unit # unit tests
114
+ bundle exec rake rubocop # lint
115
+ bundle exec rake coverage # run tests with coverage
116
+ ```
117
+
118
+ ## License
119
+
120
+ [MIT](https://opensource.org/licenses/MIT)
data/bin/bump-version ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ VERSION = ARGV[0]
5
+
6
+ if VERSION.nil? || VERSION.empty?
7
+ warn "Usage: #{$PROGRAM_NAME} <version>"
8
+ exit 1
9
+ end
10
+
11
+ OUTPUT_FILE = File.expand_path("../lib/stimulus_plumbers/mcp/version.rb", __dir__)
12
+
13
+ output = <<~RUBY
14
+ # frozen_string_literal: true
15
+
16
+ module StimulusPlumbers
17
+ module MCP
18
+ VERSION = "#{VERSION}"
19
+ end
20
+ end
21
+ RUBY
22
+
23
+ File.write(OUTPUT_FILE, output)
24
+ system("bundle > /dev/null")
25
+
26
+ puts VERSION
data/bin/mcp-query ADDED
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Query the stimulus-plumbers MCP server over stdio.
5
+ #
6
+ # Usage:
7
+ # bin/mcp-query tools # list available tools
8
+ # bin/mcp-query resources # list available resources
9
+ # bin/mcp-query tool <name> [args_json] # call a tool (args_json defaults to {})
10
+ # bin/mcp-query read <uri> # read a resource
11
+
12
+ require "bundler/setup"
13
+ require "json"
14
+ require "open3"
15
+ require "rbconfig"
16
+
17
+ SERVER = File.join(__dir__, "server")
18
+
19
+ def usage
20
+ warn <<~USAGE
21
+ Usage:
22
+ bin/mcp-query tools
23
+ bin/mcp-query resources
24
+ bin/mcp-query tool <name> [args_json]
25
+ bin/mcp-query read <uri>
26
+ USAGE
27
+ exit 1
28
+ end
29
+
30
+ def die(message)
31
+ warn "error: #{message}"
32
+ exit 1
33
+ end
34
+
35
+ def build_requests(*requests)
36
+ client_info = { name: "mcp-query", version: "1.0" }
37
+ init_params = { protocolVersion: "2024-11-05", capabilities: {}, clientInfo: client_info }
38
+ handshake = [
39
+ { jsonrpc: "2.0", id: 1, method: "initialize", params: init_params },
40
+ { jsonrpc: "2.0", method: "notifications/initialized" }
41
+ ]
42
+ "#{(handshake + requests).map { JSON.generate(_1) }.join("\n")}\n"
43
+ end
44
+
45
+ def query_server(requests)
46
+ stdout, _stderr, = Open3.capture3(RbConfig.ruby, SERVER, stdin_data: requests)
47
+ parsed = stdout.each_line.filter_map do |l|
48
+ JSON.parse(l.strip)
49
+ rescue StandardError
50
+ nil
51
+ end
52
+ response = parsed.find { |r| r["id"] == 2 }
53
+ raise "No response from server" unless response
54
+
55
+ response
56
+ end
57
+
58
+ def print_error_and_exit(response)
59
+ warn "error: #{JSON.pretty_generate(response["error"])}"
60
+ exit 1
61
+ end
62
+
63
+ subcommand = ARGV.shift || usage
64
+
65
+ case subcommand
66
+ when "tools"
67
+ response = query_server(build_requests({ jsonrpc: "2.0", id: 2, method: "tools/list" }))
68
+ print_error_and_exit(response) if response["error"]
69
+
70
+ response.dig("result", "tools").each do |tool|
71
+ puts " #{tool["name"]}"
72
+ puts " #{tool["description"]}"
73
+ puts
74
+ end
75
+
76
+ when "resources"
77
+ response = query_server(build_requests({ jsonrpc: "2.0", id: 2, method: "resources/list" }))
78
+ print_error_and_exit(response) if response["error"]
79
+
80
+ response.dig("result", "resources").each do |res|
81
+ puts " #{res["uri"]}"
82
+ puts " #{res["description"] || res["name"]}"
83
+ puts
84
+ end
85
+
86
+ when "tool"
87
+ name = ARGV.shift || die("tool requires a name")
88
+ args = JSON.parse(ARGV.shift || "{}")
89
+
90
+ request = { jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: name, arguments: args } }
91
+ response = query_server(build_requests(request))
92
+ print_error_and_exit(response) if response["error"]
93
+
94
+ response.dig("result", "content").each { puts _1["text"] }
95
+
96
+ when "read"
97
+ uri = ARGV.shift || die("read requires a URI")
98
+
99
+ request = { jsonrpc: "2.0", id: 2, method: "resources/read", params: { uri: uri } }
100
+ response = query_server(build_requests(request))
101
+ print_error_and_exit(response) if response["error"]
102
+
103
+ response.dig("result", "contents").each { puts _1["text"] }
104
+
105
+ else
106
+ usage
107
+ end
data/bin/server ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Monorepo dev entry point — loads lib via require_relative (no gem install needed).
5
+ require "bundler/setup"
6
+ require_relative "../lib/stimulus_plumbers_mcp"
7
+
8
+ StimulusPlumbers::MCP::CLI.run
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # gem exec entry point — loads via installed gem load path (no clone needed).
5
+ require "stimulus_plumbers_mcp"
6
+
7
+ StimulusPlumbers::MCP::CLI.run
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StimulusPlumbers
4
+ module MCP
5
+ module CLI
6
+ def self.run
7
+ server = Server.build
8
+ warn "[stimulus-plumbers-mcp] server started (version #{VERSION})"
9
+ ::MCP::Server::Transports::StdioTransport.new(server).open
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StimulusPlumbers
4
+ module MCP
5
+ class AriaLoader
6
+ FILENAME = "ARIA.md"
7
+
8
+ class << self
9
+ def call
10
+ path = resolved_path
11
+ path ? File.read(path) : ""
12
+ end
13
+
14
+ private
15
+
16
+ def resolved_path
17
+ aria_paths.find { |p| File.exist?(p) }
18
+ end
19
+
20
+ def aria_paths
21
+ [
22
+ # 1. Monorepo dev checkout — the root file is the freshest copy while working locally.
23
+ File.expand_path(File.join(__dir__, "../../../../..", FILENAME)),
24
+ # 2. gem exec — vendored into the rails gem at release time (bin/release).
25
+ GemVendorPath.resolve(FILENAME)
26
+ ].compact
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StimulusPlumbers
4
+ module MCP
5
+ class ComponentDocsLoader
6
+ class << self
7
+ def docs_dir
8
+ @docs_dir ||= resolve_docs_dir
9
+ end
10
+
11
+ def call
12
+ Dir[File.join(docs_dir, "*.md")].each_with_object({}) do |path, result|
13
+ name = File.basename(path, ".md").to_sym
14
+ content = File.read(path)
15
+ result[name] = {
16
+ content: content,
17
+ examples: extract_erb_examples(content),
18
+ signature: DocsTableParser.call(content)
19
+ }
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def resolve_docs_dir
26
+ gem_dir = Gem::Specification.find_by_name("stimulus_plumbers").gem_dir
27
+ File.join(gem_dir, "docs/component")
28
+ rescue Gem::MissingSpecError
29
+ File.expand_path("../../../../../stimulus-plumbers-rails/docs/component", __dir__)
30
+ end
31
+
32
+ def extract_erb_examples(content)
33
+ content.scan(%r{```erb\n(.*?)```}m).map(&:first).map(&:strip)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StimulusPlumbers
4
+ module MCP
5
+ class ComponentRequirements
6
+ class << self
7
+ def call
8
+ Components.constants
9
+ .map { |c| Components.const_get(c) }
10
+ .grep(Class)
11
+ .to_h { |klass| [component_key(klass), controllers_for(klass).uniq] }
12
+ end
13
+
14
+ private
15
+
16
+ # Controllers from a component class plus its nested sub-components (e.g. Combobox::Date),
17
+ # keyed to the top-level component. Skips references to sibling components.
18
+ def controllers_for(mod)
19
+ mod.constants(false).flat_map do |const|
20
+ value = mod.const_get(const)
21
+ if const.to_s.end_with?("CONTROLLER")
22
+ Array(value).grep(String).flat_map(&:split)
23
+ elsif nested?(mod, value)
24
+ controllers_for(value)
25
+ else
26
+ []
27
+ end
28
+ end
29
+ end
30
+
31
+ def nested?(mod, value)
32
+ value.is_a?(Module) && !value.name.nil? && value.name.start_with?("#{mod.name}::")
33
+ end
34
+
35
+ def component_key(klass)
36
+ klass.name.demodulize.underscore.to_sym
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StimulusPlumbers
4
+ module MCP
5
+ class ComponentSchemaLoader
6
+ # Not derivable from Form::Fields::Renderer's method names (`search:` renders via
7
+ # `render_combobox_typeahead`, but wires up "combobox-dropdown", not
8
+ # "combobox-typeahead") — hand-maintained; keep in sync with form.md's "backed by" notes.
9
+ FIELD_AS_CONTROLLERS = {
10
+ date: "combobox-date",
11
+ time: "combobox-time",
12
+ select: "combobox-dropdown",
13
+ search: "combobox-dropdown",
14
+ collection_select: "combobox-dropdown",
15
+ grouped_collection_select: "combobox-dropdown"
16
+ }.freeze
17
+
18
+ class << self
19
+ def call
20
+ {
21
+ components: extract_schema,
22
+ field_as: extract_field_as,
23
+ field_as_controllers: FIELD_AS_CONTROLLERS,
24
+ controllers: ComponentRequirements.call
25
+ }
26
+ end
27
+
28
+ private
29
+
30
+ def extract_schema
31
+ Themes::Base::SCHEMA.transform_values do |param_schema|
32
+ param_schema.transform_values do |meta|
33
+ v = meta[:validate]
34
+ { default: meta[:default], valid: v.respond_to?(:to_a) ? v.to_a : v.inspect }
35
+ end
36
+ end
37
+ end
38
+
39
+ def extract_field_as
40
+ {
41
+ field: Form::Fields::Renderer::FIELD.keys,
42
+ collection_field: Form::Fields::Renderer::COLLECTION.keys,
43
+ choice: Form::Fields::Renderer::CHOICE.keys
44
+ }
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StimulusPlumbers
4
+ module MCP
5
+ class ComponentThemeLoader
6
+ class << self
7
+ def call
8
+ {
9
+ base_doc: base_doc,
10
+ components: extract_interface
11
+ }
12
+ end
13
+
14
+ private
15
+
16
+ # Same file ComponentDocsLoader already serves at component://theme/docs — avoids a duplicate heredoc.
17
+ def base_doc
18
+ path = File.join(ComponentDocsLoader.docs_dir, "theme.md")
19
+ File.exist?(path) ? File.read(path) : ""
20
+ end
21
+
22
+ def extract_interface
23
+ Themes::Base::SCHEMA.each_with_object({}) do |(key, params), result|
24
+ result[key] = {
25
+ method: "#{key}_classes",
26
+ params: params.transform_values { |meta| format_param(meta) },
27
+ returns: "{ classes: String }"
28
+ }
29
+ end
30
+ end
31
+
32
+ def format_param(meta)
33
+ valid = meta[:validate]
34
+ entry = { default: meta[:default] }
35
+ entry[:valid] = valid.to_a if valid.respond_to?(:to_a)
36
+ entry
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StimulusPlumbers
4
+ module MCP
5
+ class ControllerDocsLoader
6
+ class << self
7
+ def docs_dir
8
+ @docs_dir ||= resolve_docs_dir
9
+ end
10
+
11
+ def call
12
+ Dir[File.join(docs_dir, "*.md")].to_h do |path|
13
+ [File.basename(path, ".md").to_sym, File.read(path)]
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def resolve_docs_dir
20
+ # 1. Monorepo dev checkout — the JS package's own docs are freshest while working locally.
21
+ dev_path = File.expand_path(File.join(__dir__, "../../../../..", "stimulus-plumbers", "docs", "component"))
22
+ return dev_path if Dir.exist?(dev_path)
23
+
24
+ # 2. gem exec — vendored into the rails gem at release time, under vendor/controller/docs/
25
+ # (mirrors the MCP server's controller:// resource namespace).
26
+ GemVendorPath.resolve("controller", "docs") || dev_path
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StimulusPlumbers
4
+ module MCP
5
+ class ControllerSchemaLoader
6
+ MANIFEST_FILENAME = "controllers.manifest.json"
7
+ # Vendored as manifest.json — the "controllers" prefix is redundant once nested
8
+ # under vendor/controller/ (mirrors the MCP server's controller:// namespace).
9
+ VENDOR_FILENAME = "manifest.json"
10
+
11
+ class << self
12
+ def call
13
+ path = resolved_path
14
+
15
+ unless path
16
+ StimulusPlumbers::Logger.warn(
17
+ "controller manifest not found. Tried:\n" \
18
+ "#{manifest_paths.map { |p| " - #{p}" }.join("\n")}\n" \
19
+ "Run `node --run build:manifest` in stimulus-plumbers/ to generate it."
20
+ )
21
+ return {}
22
+ end
23
+
24
+ JSON.parse(File.read(path))
25
+ end
26
+
27
+ # Reused by VersionsLoader to report which fallback location resolved.
28
+ def resolved_path
29
+ manifest_paths.find { |p| File.exist?(p) }
30
+ end
31
+
32
+ private
33
+
34
+ def manifest_paths
35
+ [
36
+ # 1. npm/yarn/bun project — version matches project lockfile
37
+ File.join(Dir.pwd, "node_modules/@stimulus-plumbers/controllers/dist", MANIFEST_FILENAME),
38
+ # 2. importmaps users — vendored in Rails gem at release time
39
+ GemVendorPath.resolve("controller", VENDOR_FILENAME),
40
+ # 3. Monorepo dev fallback
41
+ File.expand_path(
42
+ File.join(__dir__, "../../../../..", "stimulus-plumbers", "dist", MANIFEST_FILENAME)
43
+ )
44
+ ].compact
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ # stimulus-plumbers — overview
2
+
3
+ Accessible Rails view components plus a themed form builder, backed by Stimulus controllers.
4
+ Start here, then drill into the per-package guides and per-component resources/tools below.
5
+
6
+ ## Per-package guides
7
+ - `guide://component` — building forms (`f.field`/`f.collection_field`/`f.choice`) and views
8
+ (`sp_*` helpers) with the Rails gem
9
+ - `guide://controller` — plain-JS / non-Rails setup for `@stimulus-plumbers/controllers`
10
+ - `guide://tailwind` — Tailwind theme install + icons
11
+ - `guide://theme` — implementing a custom theme (subclassing `Themes::Base`)
12
+
13
+ Tools: `list_guides`, `get_guide(name:)`.
14
+
15
+ ## Building forms and views
16
+ Valid `as:` values: `get_field_as_values(builder_method:)`. Combobox-backed `as:` values' controller
17
+ identifier: `get_field_as_controller(as:)` — `component://{name}/schema` keys are renderer-level, not
18
+ `as:` values. Component helper surface: `get_component_helper(name)`; themed params:
19
+ `get_component_schema(name)`; ERB examples: `get_component_examples(name)`. List everything with
20
+ `list_components`; `list_component_docs` shows which components have full docs
21
+ (`component://{name}/docs`) and helper signatures (`component://{name}/helper`). Icon options take a
22
+ name from `component://icons` (or `list_icons`). All 77 schema components are queryable via
23
+ `get_component_schema`; only a subset have full docs and ERB examples — use `list_component_docs` to
24
+ see what's covered. Full form builder reference: `component://form/docs`.
25
+
26
+ ## Stimulus integration
27
+ Most display components are pure markup; interactive ones (combobox, popover, calendar) emit their
28
+ `data-controller` attributes automatically. Component → required controllers: `component://integration`.
29
+ Controller identifiers and details (targets/values/outlets/classes): `controller://index`,
30
+ `get_controller_schema(id)` / `list_controllers`.
31
+ Narrative docs by controller family: `get_controller_docs(name)` / `controller://docs/{name}`.
32
+
33
+ ## How this server is organized
34
+ - **Resources** live under entity namespaces — `component://` (Rails `sp_*` helper surface: schema,
35
+ docs, helper, theme, tailwind, icons facets), `controller://` (plain-JS Stimulus surface: schema,
36
+ docs facets), `guide://` (per-package usage guides) — plus `aria://reference` and `versions://sources`.
37
+ **Tools** (`get_*`, `list_*`) expose the same data for targeted lookups. Use whichever your client prefers.
38
+ - `aria://reference` — WCAG 2.1 AA criteria and component ARIA patterns. For generic ARIA/WCAG reference,
39
+ connect the MDN MCP server too: `claude mcp add --transport http mdn https://mcp.mdn.mozilla.net/`
40
+ - Each source (schema, docs, theme, tailwind, icons, stimulus, stimulus_docs, guide) is read from an
41
+ independently-versioned gem/npm package — `versions://sources` / `get_source_versions` reports what's
42
+ actually resolved, useful if data looks stale or inconsistent with the app code you're generating for.
43
+ `icons` versions with the Tailwind theme gem, not the schema gem, since the bundled icon set is
44
+ Tailwind-specific.
45
+ - **View generation** uses the form builder + `sp_` helper tools/resources above. The `component://theme`
46
+ and `component://tailwind` facets are for *theme authors* implementing a custom theme — skip them when
47
+ generating views.
48
+ - **Errors are uniform:** a not-found tool/resource returns `{ "error": "..." }` (tools also set `isError`).