rails-mcp-server 1.1.4 → 1.2.1

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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +216 -0
  3. data/README.md +156 -46
  4. data/config/resources.yml +203 -0
  5. data/docs/RESOURCES.md +339 -0
  6. data/exe/rails-mcp-server +8 -5
  7. data/exe/rails-mcp-server-download-resources +120 -0
  8. data/lib/rails-mcp-server/config.rb +7 -1
  9. data/lib/rails-mcp-server/extensions/resource_templating.rb +182 -0
  10. data/lib/rails-mcp-server/extensions/server_templating.rb +333 -0
  11. data/lib/rails-mcp-server/helpers/resource_base.rb +143 -0
  12. data/lib/rails-mcp-server/helpers/resource_downloader.rb +104 -0
  13. data/lib/rails-mcp-server/helpers/resource_importer.rb +113 -0
  14. data/lib/rails-mcp-server/resources/base_resource.rb +7 -0
  15. data/lib/rails-mcp-server/resources/custom_guides_resource.rb +54 -0
  16. data/lib/rails-mcp-server/resources/custom_guides_resources.rb +37 -0
  17. data/lib/rails-mcp-server/resources/guide_content_formatter.rb +130 -0
  18. data/lib/rails-mcp-server/resources/guide_error_handler.rb +85 -0
  19. data/lib/rails-mcp-server/resources/guide_file_finder.rb +100 -0
  20. data/lib/rails-mcp-server/resources/guide_framework_contract.rb +65 -0
  21. data/lib/rails-mcp-server/resources/guide_loader_template.rb +122 -0
  22. data/lib/rails-mcp-server/resources/guide_manifest_operations.rb +52 -0
  23. data/lib/rails-mcp-server/resources/kamal_guides_resource.rb +80 -0
  24. data/lib/rails-mcp-server/resources/kamal_guides_resources.rb +110 -0
  25. data/lib/rails-mcp-server/resources/rails_guides_resource.rb +29 -0
  26. data/lib/rails-mcp-server/resources/rails_guides_resources.rb +37 -0
  27. data/lib/rails-mcp-server/resources/stimulus_guides_resource.rb +29 -0
  28. data/lib/rails-mcp-server/resources/stimulus_guides_resources.rb +37 -0
  29. data/lib/rails-mcp-server/resources/turbo_guides_resource.rb +29 -0
  30. data/lib/rails-mcp-server/resources/turbo_guides_resources.rb +37 -0
  31. data/lib/rails-mcp-server/tools/analyze_models.rb +1 -1
  32. data/lib/rails-mcp-server/tools/load_guide.rb +370 -0
  33. data/lib/rails-mcp-server/version.rb +1 -1
  34. data/lib/rails_mcp_server.rb +51 -283
  35. metadata +49 -6
@@ -0,0 +1,203 @@
1
+ rails:
2
+ base_url: "https://raw.githubusercontent.com/rails/rails/v8.0.2/guides/source"
3
+ description: "Official Ruby on Rails documentation guides"
4
+ version: "8.0.2"
5
+ files:
6
+ # Getting Started
7
+ - getting_started.md
8
+ - install_ruby_on_rails.md
9
+ - getting_started_with_devcontainer.md
10
+
11
+ # Core Components
12
+ - active_record_basics.md
13
+ - active_record_migrations.md
14
+ - active_record_validations.md
15
+ - active_record_callbacks.md
16
+ - active_record_querying.md
17
+ - active_record_encryption.md
18
+ - active_record_multiple_databases.md
19
+ - active_record_postgresql.md
20
+ - active_record_composite_primary_keys.md
21
+ - association_basics.md
22
+
23
+ # Action Pack
24
+ - action_controller_overview.md
25
+ - action_controller_advanced_topics.md
26
+ - action_view_overview.md
27
+ - action_view_helpers.md
28
+ - layouts_and_rendering.md
29
+ - form_helpers.md
30
+ - routing.md
31
+
32
+ # Other Action Components
33
+ - action_mailer_basics.md
34
+ - action_cable_overview.md
35
+ - action_text_overview.md
36
+ - action_mailbox_basics.md
37
+ - active_job_basics.md
38
+ - active_storage_overview.md
39
+
40
+ # Active Support
41
+ - active_support_core_extensions.md
42
+ - active_support_instrumentation.md
43
+ - active_model_basics.md
44
+
45
+ # Configuration and Setup
46
+ - configuring.md
47
+ - command_line.md
48
+ - asset_pipeline.md
49
+ - working_with_javascript_in_rails.md
50
+ - autoloading_and_reloading_constants.md
51
+ - initialization.md
52
+ - rails_on_rack.md
53
+
54
+ # Advanced Topics
55
+ - engines.md
56
+ - threading_and_code_execution.md
57
+ - api_app.md
58
+ - generators.md
59
+ - plugins.md
60
+ - caching_with_rails.md
61
+
62
+ # Development and Testing
63
+ - testing.md
64
+ - debugging_rails_applications.md
65
+ - development_dependencies_install.md
66
+ - error_reporting.md
67
+
68
+ # Deployment and Performance
69
+ - tuning_performance_for_deployment.md
70
+ - upgrading_ruby_on_rails.md
71
+
72
+ # Security and Internationalization
73
+ - security.md
74
+ - i18n.md
75
+
76
+ # Contributing
77
+ - contributing_to_ruby_on_rails.md
78
+ - api_documentation_guidelines.md
79
+ - ruby_on_rails_guides_guidelines.md
80
+ - maintenance_policy.md
81
+
82
+ # Stimulus JavaScript Framework Documentation
83
+ stimulus:
84
+ base_url: "https://raw.githubusercontent.com/hotwired/stimulus/refs/heads/main/docs"
85
+ description: "Stimulus JavaScript framework documentation"
86
+ version: "latest"
87
+ files:
88
+ # Handbook - Main Documentation
89
+ - handbook/00_the_origin_of_stimulus.md
90
+ - handbook/01_introduction.md
91
+ - handbook/02_hello_stimulus.md
92
+ - handbook/03_building_something_real.md
93
+ - handbook/04_designing_for_resilience.md
94
+ - handbook/05_managing_state.md
95
+ - handbook/06_working_with_external_resources.md
96
+ - handbook/07_installing_stimulus.md
97
+
98
+ # Reference - API Documentation
99
+ - reference/actions.md
100
+ - reference/controllers.md
101
+ - reference/css_classes.md
102
+ - reference/lifecycle_callbacks.md
103
+ - reference/outlets.md
104
+ - reference/targets.md
105
+ - reference/using_typescript.md
106
+ - reference/values.md
107
+
108
+ # Turbo Hotwire Framework Documentation
109
+ turbo:
110
+ base_url: "https://raw.githubusercontent.com/hotwired/turbo-site/refs/heads/main/_source"
111
+ description: "Turbo Hotwire framework documentation"
112
+ version: "latest"
113
+ files:
114
+ # Handbook - Main Documentation
115
+ - handbook/01_introduction.md
116
+ - handbook/02_drive.md
117
+ - handbook/03_page_refreshes.md
118
+ - handbook/04_frames.md
119
+ - handbook/05_streams.md
120
+ - handbook/06_native.md
121
+ - handbook/07_building.md
122
+ - handbook/08_installing.md
123
+
124
+ # Reference - API Documentation
125
+ - reference/attributes.md
126
+ - reference/drive.md
127
+ - reference/events.md
128
+ - reference/frames.md
129
+ - reference/streams.md
130
+
131
+ # Kamal Deploy Documentation
132
+ kamal:
133
+ base_url: "https://raw.githubusercontent.com/basecamp/kamal-site/refs/heads/main/docs"
134
+ description: "Kamal deployment tool documentation"
135
+ version: "latest"
136
+ files:
137
+ # Installation
138
+ - installation/index.md
139
+ - installation/dockerized.md
140
+
141
+ # Configuration
142
+ - configuration/accessories.md
143
+ - configuration/aliases.md
144
+ - configuration/anchors.md
145
+ - configuration/booting.md
146
+ - configuration/builder-examples.md
147
+ - configuration/builders.md
148
+ - configuration/cron.md
149
+ - configuration/docker-registry.md
150
+ - configuration/environment-variables.md
151
+ - configuration/logging.md
152
+ - configuration/overview.md
153
+ - configuration/proxy.md
154
+ - configuration/roles.md
155
+ - configuration/servers.md
156
+ - configuration/ssh.md
157
+ - configuration/sshkit.md
158
+
159
+ # Commands
160
+ - commands/accessory.md
161
+ - commands/app.md
162
+ - commands/audit.md
163
+ - commands/build.md
164
+ - commands/config.md
165
+ - commands/deploy.md
166
+ - commands/details.md
167
+ - commands/docs.md
168
+ - commands/help.md
169
+ - commands/init.md
170
+ - commands/lock.md
171
+ - commands/proxy.md
172
+ - commands/prune.md
173
+ - commands/redeploy.md
174
+ - commands/registry.md
175
+ - commands/remove.md
176
+ - commands/rollback.md
177
+ - commands/running-commands-on-servers.md
178
+ - commands/secrets.md
179
+ - commands/server.md
180
+ - commands/setup.md
181
+ - commands/upgrade.md
182
+ - commands/version.md
183
+ - commands/view-all-commands.md
184
+
185
+ # Hooks
186
+ - hooks/overview.md
187
+ - hooks/docker-setup.md
188
+ - hooks/post-app-boot.md
189
+ - hooks/post-deploy.md
190
+ - hooks/post-proxy-reboot.md
191
+ - hooks/pre-app-boot.md
192
+ - hooks/pre-build.md
193
+ - hooks/pre-connect.md
194
+ - hooks/pre-deploy.md
195
+ - hooks/pre-proxy-reboot.md
196
+
197
+ # Upgrading
198
+ - upgrading/configuration-changes.md
199
+ - upgrading/continuing-to-use-traefik.md
200
+ - upgrading/network-changes.md
201
+ - upgrading/overview.md
202
+ - upgrading/proxy-changes.md
203
+ - upgrading/secrets-changes.md
data/docs/RESOURCES.md ADDED
@@ -0,0 +1,339 @@
1
+ # Rails MCP Server - Resources Guide
2
+
3
+ This guide explains how the Rails MCP Server handles documentation resources, how to download predefined guides, and how to load custom documentation files. Resources in the Rails MCP Server provide access to comprehensive documentation for Rails and related frameworks through both the `load_guide` tool and direct MCP resource access.
4
+
5
+ ## Table of Contents
6
+
7
+ - [What are Resources?](#what-are-resources)
8
+ - [Available Resource Categories](#available-resource-categories)
9
+ - [Downloading Predefined Resources](#downloading-predefined-resources)
10
+ - [Loading Custom Files](#loading-custom-files)
11
+ - [Using the load_guide Tool](#using-the-load_guide-tool)
12
+ - [Direct Resource Access](#direct-resource-access)
13
+ - [Troubleshooting](#troubleshooting)
14
+
15
+ ## What are Resources?
16
+
17
+ Resources in the Rails MCP Server are documentation guides that can be accessed through two main methods:
18
+
19
+ 1. **Tool-based access**: Using the `load_guide` tool to retrieve specific guides
20
+ 2. **Direct resource access**: MCP clients can directly query resources using URI templates
21
+
22
+ Resources are stored locally in your configuration directory and can be:
23
+ - **Predefined resources**: Official documentation from Rails, Turbo, Stimulus, and Kamal
24
+ - **Custom resources**: Your own markdown files imported into the system
25
+
26
+ ## Available Resource Categories
27
+
28
+ The Rails MCP Server supports five categories of resources:
29
+
30
+ ### 1. Rails Guides
31
+ - **Framework**: Ruby on Rails
32
+ - **Content**: Official Rails 8.0.2 documentation
33
+
34
+ ### 2. Turbo Guides
35
+ - **Framework**: Turbo (Hotwire)
36
+ - **Content**: Official Turbo framework documentation
37
+
38
+ ### 3. Stimulus Guides
39
+ - **Framework**: Stimulus (Hotwire)
40
+ - **Content**: Official Stimulus JavaScript framework documentation
41
+
42
+ ### 4. Kamal Guides
43
+ - **Framework**: Kamal Deploy
44
+ - **Content**: Official Kamal deployment tool documentation
45
+
46
+ ### 5. Custom Guides
47
+ - **Framework**: Custom/Local
48
+ - **Content**: Your imported markdown files
49
+
50
+ ## Downloading Predefined Resources
51
+
52
+ Before you can use predefined resources, you need to download them using the resource downloader tool.
53
+
54
+ ### Basic Download Command
55
+
56
+ ```bash
57
+ # Download Rails guides
58
+ rails-mcp-server-download-resources rails
59
+
60
+ # Download Turbo guides
61
+ rails-mcp-server-download-resources turbo
62
+
63
+ # Download Stimulus guides
64
+ rails-mcp-server-download-resources stimulus
65
+
66
+ # Download Kamal guides
67
+ rails-mcp-server-download-resources kamal
68
+ ```
69
+
70
+ ### Download Options
71
+
72
+ ```bash
73
+ # Force download even if files haven't changed
74
+ rails-mcp-server-download-resources --force rails
75
+
76
+ # Verbose output to see download progress
77
+ rails-mcp-server-download-resources --verbose turbo
78
+
79
+ # Combine options
80
+ rails-mcp-server-download-resources --verbose --force stimulus
81
+ ```
82
+
83
+ ### Download Process
84
+
85
+ When you run the download command:
86
+
87
+ 1. **Creates directories**: Sets up the resource folder structure in your config directory
88
+ 2. **Downloads guides**: Fetches the latest documentation from official repositories
89
+ 3. **Creates manifest**: Generates a manifest.yaml file tracking all downloaded files
90
+ 4. **Tracks changes**: Monitors file modifications to avoid unnecessary re-downloads
91
+
92
+ ### Resource Storage Location
93
+
94
+ Downloaded resources are stored in:
95
+ - **macOS**: `~/.config/rails-mcp/resources/`
96
+ - **Windows**: `%APPDATA%\rails-mcp\resources\`
97
+
98
+ Directory structure:
99
+ ```
100
+ ~/.config/rails-mcp/resources/
101
+ ├── rails/
102
+ │ ├── manifest.yaml
103
+ │ ├── getting_started.md
104
+ │ ├── active_record_basics.md
105
+ │ └── ...
106
+ ├── turbo/
107
+ │ ├── manifest.yaml
108
+ │ ├── handbook/
109
+ │ │ ├── 01_introduction.md
110
+ │ │ └── ...
111
+ │ └── reference/
112
+ │ ├── streams.md
113
+ │ └── ...
114
+ ├── stimulus/
115
+ ├── kamal/
116
+ └── custom/
117
+ ```
118
+
119
+ ## Loading Custom Files
120
+
121
+ You can import your own markdown files into the Custom guides category using the `--file` option.
122
+
123
+ ### Import Single File
124
+
125
+ ```bash
126
+ # Import a single markdown file
127
+ rails-mcp-server-download-resources --file /path/to/guide.md
128
+
129
+ # Force import even if file hasn't changed
130
+ rails-mcp-server-download-resources --force --file /path/to/api-docs.md
131
+ ```
132
+
133
+ ### Import Directory
134
+
135
+ ```bash
136
+ # Import all markdown files from a directory
137
+ rails-mcp-server-download-resources --file /path/to/docs/
138
+
139
+ # Verbose import with progress information
140
+ rails-mcp-server-download-resources --verbose --file /path/to/project-docs/
141
+ ```
142
+
143
+ ### Import Process
144
+
145
+ When importing custom files:
146
+
147
+ 1. **File validation**: Checks that source files exist and are readable
148
+ 2. **Filename normalization**: Converts filenames to lowercase with underscores
149
+ 3. **Duplication handling**: Skips unchanged files unless `--force` is used
150
+ 4. **Manifest updates**: Tracks imported files in the custom manifest
151
+
152
+ ### Filename Normalization
153
+
154
+ Custom files are normalized for consistency:
155
+ - `API Documentation.md` → `api_documentation.md`
156
+ - `Setup-Guide.md` → `setup_guide.md`
157
+ - `user_manual.md` → `user_manual.md` (already normalized)
158
+
159
+ ## Using the load_guide Tool
160
+
161
+ The `load_guide` tool is the primary way to access resources programmatically within MCP conversations.
162
+
163
+ ### Basic Syntax
164
+
165
+ ```
166
+ load_guide guides: "category" guide: "guide_name"
167
+ ```
168
+
169
+ ### Loading Specific Guides
170
+
171
+ #### Rails Guides
172
+ ```
173
+ Can you load the Rails getting started guide?
174
+
175
+ I need to see the Active Record basics documentation.
176
+
177
+ Show me the Rails routing guide.
178
+ ```
179
+
180
+ #### Turbo Guides
181
+ ```
182
+ Can you load the Turbo introduction guide?
183
+
184
+ I'd like to see the Turbo Frames documentation.
185
+
186
+ Show me the Turbo streams reference.
187
+ ```
188
+
189
+ #### Stimulus Guides
190
+ ```
191
+ Load the Hello Stimulus tutorial for me.
192
+
193
+ I need help with Stimulus controllers - can you show me that guide?
194
+
195
+ Can you display the Stimulus targets reference?
196
+ ```
197
+
198
+ #### Kamal Guides
199
+ ```
200
+ Show me the Kamal installation guide.
201
+
202
+ I need to understand Kamal deployment - can you load that documentation?
203
+
204
+ Can you get the Kamal configuration overview?
205
+ ```
206
+
207
+ #### Custom Guides
208
+ ```
209
+ Load my API documentation guide.
210
+
211
+ Can you show me the setup guide I imported?
212
+
213
+ I need to see my custom user manual.
214
+ ```
215
+
216
+ ### Listing Available Guides
217
+
218
+ ```
219
+ What Rails guides are available?
220
+
221
+ Show me all the Turbo documentation.
222
+
223
+ List the available custom guides I've imported.
224
+ ```
225
+
226
+ ### Tool Output Format
227
+
228
+ The `load_guide` tool returns formatted content with:
229
+
230
+ ```markdown
231
+ # Guide Title
232
+
233
+ **Source:** Framework Name
234
+ **Guide:** guide_name
235
+ **File:** path/to/file.md (for sectioned guides)
236
+
237
+ ---
238
+
239
+ [Guide content here...]
240
+ ```
241
+
242
+ ## Direct Resource Access
243
+
244
+ MCP clients that support resources can access documentation directly without using the `load_guide` tool.
245
+
246
+ ### Resource URIs
247
+
248
+ Each resource category has specific URI patterns:
249
+
250
+ #### List Resources (Available Guides)
251
+ - `rails://guides` - List all Rails guides
252
+ - `turbo://guides` - List all Turbo guides
253
+ - `stimulus://guides` - List all Stimulus guides
254
+ - `kamal://guides` - List all Kamal guides
255
+ - `custom://guides` - List all custom guides
256
+
257
+ #### Specific Guide Resources
258
+ - `rails://guides/{guide_name}` - Access specific Rails guide
259
+ - `turbo://guides/{guide_name}` - Access specific Turbo guide
260
+ - `stimulus://guides/{guide_name}` - Access specific Stimulus guide
261
+ - `kamal://guides/{guide_name}` - Access specific Kamal guide
262
+ - `custom://guides/{guide_name}` - Access specific custom guide
263
+
264
+ ### Resource Metadata
265
+
266
+ Each resource includes metadata:
267
+ - `resource_name`: Human-readable name
268
+ - `description`: Resource description
269
+ - `mime_type`: Content type (text/markdown)
270
+ - `uri`: URI template pattern
271
+
272
+ ## Troubleshooting
273
+
274
+ ### Common Issues
275
+
276
+ #### Resource Not Found
277
+ ```
278
+ Error: Unknown resource: rails
279
+ ```
280
+ **Solution**: Check available resources with `--help` flag
281
+
282
+ #### Download Failures
283
+ ```
284
+ failed (HTTP 404)
285
+ ```
286
+ **Solution**: Resource may have moved; try updating or check internet connection
287
+
288
+ #### Permission Errors
289
+ ```
290
+ Error: Source not readable: /path/to/file
291
+ ```
292
+ **Solution**: Check file permissions and path existence
293
+
294
+ #### Guide Not Found
295
+ ```
296
+ Guide 'invalid_guide' not found in Rails guides.
297
+ ```
298
+ **Solution**: Use `load_guide guides: "rails"` to see available guides
299
+
300
+ ### Verbose Troubleshooting
301
+
302
+ Use verbose mode for detailed information:
303
+
304
+ ```bash
305
+ # Verbose download
306
+ rails-mcp-server-download-resources --verbose rails
307
+
308
+ # Verbose import
309
+ rails-mcp-server-download-resources --verbose --file /path/to/docs/
310
+ ```
311
+
312
+ ### Manual Resource Management
313
+
314
+ If needed, you can manually manage resources:
315
+
316
+ ```bash
317
+ # Remove all downloaded resources
318
+ rm -rf ~/.config/rails-mcp/resources/
319
+
320
+ # Re-download everything
321
+ rails-mcp-server-download-resources rails
322
+ rails-mcp-server-download-resources turbo
323
+ rails-mcp-server-download-resources stimulus
324
+ rails-mcp-server-download-resources kamal
325
+ ```
326
+
327
+ ## Best Practices
328
+
329
+ ### Resource Organization
330
+ 1. **Download first**: Always download resources before using the `load_guide` tool
331
+ 2. **Update regularly**: Keep resources current by re-downloading periodically
332
+ 3. **Organize custom guides**: Use descriptive filenames for custom imports
333
+
334
+ ### Performance Tips
335
+ 1. **Selective downloads**: Only download resources you need
336
+ 2. **Avoid force**: Don't use `--force` unless necessary
337
+ 3. **Batch imports**: Import multiple custom files at once using directory paths
338
+
339
+ This comprehensive resource system makes the Rails MCP Server a powerful documentation companion for Rails development, providing instant access to official guides and your custom documentation through both tool-based and direct resource access methods.
data/exe/rails-mcp-server CHANGED
@@ -63,17 +63,20 @@ while i < ARGV.length
63
63
  end
64
64
  end
65
65
 
66
- RailsMcpServer.config do |config|
67
- config.log_level = log_level
68
- end
69
-
66
+ RailsMcpServer.config.log_level = log_level
70
67
  RailsMcpServer.log(:info, "Starting Rails MCP Server in #{mode} mode...")
71
68
 
72
69
  # Create tools configuration for both modes
73
70
  def setup_mcp_tools(server)
74
71
  server.register_tools(RailsMcpServer::SwitchProject, RailsMcpServer::ProjectInfo,
75
72
  RailsMcpServer::ListFiles, RailsMcpServer::GetFile, RailsMcpServer::GetRoutes, RailsMcpServer::AnalyzeModels,
76
- RailsMcpServer::GetSchema, RailsMcpServer::AnalyzeControllerViews, RailsMcpServer::AnalyzeEnvironmentConfig)
73
+ RailsMcpServer::GetSchema, RailsMcpServer::AnalyzeControllerViews, RailsMcpServer::AnalyzeEnvironmentConfig,
74
+ RailsMcpServer::LoadGuide)
75
+
76
+ server.register_resources(RailsMcpServer::RailsGuidesResource, RailsMcpServer::RailsGuidesResources,
77
+ RailsMcpServer::StimulusGuidesResource, RailsMcpServer::StimulusGuidesResources, RailsMcpServer::TurboGuidesResource,
78
+ RailsMcpServer::TurboGuidesResources, RailsMcpServer::CustomGuidesResource, RailsMcpServer::CustomGuidesResources,
79
+ RailsMcpServer::KamalGuidesResource, RailsMcpServer::KamalGuidesResources)
77
80
  end
78
81
 
79
82
  case mode
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require_relative "../lib/rails-mcp-server/config"
5
+ require_relative "../lib/rails-mcp-server/helpers/resource_downloader"
6
+ require_relative "../lib/rails-mcp-server/helpers/resource_importer"
7
+
8
+ def show_help(parser, config_dir)
9
+ puts parser
10
+ puts "\nAvailable resources:"
11
+
12
+ available = RailsMcpServer::ResourceDownloader.available_resources(config_dir)
13
+ if available.any?
14
+ available.each { |resource| puts " - #{resource}" }
15
+ else
16
+ puts " No resources configured"
17
+ end
18
+
19
+ puts "\nOr use --file to import custom markdown files"
20
+ end
21
+
22
+ def print_summary(action, results)
23
+ puts "\n#{action} Summary:"
24
+ if action == "Import"
25
+ puts " Imported: #{results[:imported]}"
26
+ else
27
+ puts " Downloaded: #{results[:downloaded]}"
28
+ end
29
+ puts " Skipped: #{results[:skipped]}"
30
+ puts " Failed: #{results[:failed]}"
31
+ end
32
+
33
+ options = {
34
+ force: false,
35
+ verbose: false,
36
+ file: nil
37
+ }
38
+
39
+ parser = OptionParser.new do |opts|
40
+ opts.banner = "Usage: rails-mcp-server-download-resources [options] RESOURCE_NAME"
41
+ opts.separator ""
42
+ opts.separator "Downloads documentation resources for Rails MCP Server"
43
+ opts.separator ""
44
+
45
+ opts.on("-f", "--force", "Force download/import even if files haven't changed") do
46
+ options[:force] = true
47
+ end
48
+
49
+ opts.on("-v", "--verbose", "Verbose output") do
50
+ options[:verbose] = true
51
+ end
52
+
53
+ opts.on("--file PATH", "Import custom markdown file(s) from PATH") do |path|
54
+ options[:file] = path
55
+ end
56
+
57
+ opts.on("-h", "--help", "Show this help message") do
58
+ puts opts
59
+ puts ""
60
+ puts "Examples:"
61
+ puts " rails-mcp-server-download-resources rails"
62
+ puts " rails-mcp-server-download-resources --file /path/to/guide.md"
63
+ puts " rails-mcp-server-download-resources --file /path/to/guides/"
64
+ puts " rails-mcp-server-download-resources --verbose --force stimulus"
65
+ exit
66
+ end
67
+ end
68
+
69
+ parser.parse!
70
+
71
+ begin
72
+ # Get config directory without requiring Rails projects
73
+ config_dir = File.expand_path("~/.config/rails-mcp")
74
+
75
+ # Handle file import
76
+ if options[:file]
77
+ unless File.exist?(options[:file])
78
+ puts "Error: File or directory not found: #{options[:file]}"
79
+ exit 1
80
+ end
81
+
82
+ importer = RailsMcpServer::ResourceImporter.new(
83
+ "custom",
84
+ config_dir: config_dir,
85
+ source_path: options[:file],
86
+ force: options[:force],
87
+ verbose: options[:verbose]
88
+ )
89
+
90
+ results = importer.import
91
+ print_summary("Import", results)
92
+ exit (results[:failed] > 0) ? 1 : 0
93
+ end
94
+
95
+ # Handle resource download
96
+ if ARGV.empty?
97
+ show_help(parser, config_dir)
98
+ exit 1
99
+ end
100
+
101
+ resource_name = ARGV[0]
102
+ downloader = RailsMcpServer::ResourceDownloader.new(
103
+ resource_name,
104
+ config_dir: config_dir,
105
+ force: options[:force],
106
+ verbose: options[:verbose]
107
+ )
108
+
109
+ results = downloader.download
110
+ print_summary("Download", results)
111
+ exit (results[:failed] > 0) ? 1 : 0
112
+ rescue RailsMcpServer::ResourceDownloader::DownloadError,
113
+ RailsMcpServer::ResourceImporter::ImportError => e
114
+ puts "Error: #{e.message}"
115
+ exit 1
116
+ rescue => e
117
+ puts "Unexpected error: #{e.message}"
118
+ puts e.backtrace if options[:verbose]
119
+ exit 1
120
+ end
@@ -2,7 +2,8 @@ require "logger"
2
2
 
3
3
  module RailsMcpServer
4
4
  class Config
5
- attr_accessor :logger, :log_level, :projects, :current_project, :active_project_path
5
+ attr_accessor :logger, :projects, :current_project, :active_project_path, :config_dir
6
+ attr_reader :log_level
6
7
 
7
8
  def self.setup
8
9
  new.tap do |instance|
@@ -20,6 +21,11 @@ module RailsMcpServer
20
21
  load_projects
21
22
  end
22
23
 
24
+ def log_level=(level)
25
+ @log_level = LEVELS[level] || Logger::INFO
26
+ @logger.level = @log_level
27
+ end
28
+
23
29
  private
24
30
 
25
31
  def load_projects