rails-active-mcp 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 695c22b21a980b527c91e1c4d269e7ea4dc260668c2d7ee9eb135d734db95ab3
4
- data.tar.gz: 34ff366ef633aef419c388ec77a3dbb768bf8b05f3a915fcf983080ff503540e
3
+ metadata.gz: 38778186d51ca223866b9cdf181cbe389957c840609934897547d11af69c150c
4
+ data.tar.gz: 9ed227e53b104de6e482428a37837b80dd0b30f01405d3abaab8e12c4e6175c8
5
5
  SHA512:
6
- metadata.gz: 9c659fce767c7f9249f970a40d5fa1c627b151f2ef86990f676f8e50ddf2d9d398772389761e67ced5382b0640d69119be1fddf804b8fe7905814df55b659ec8
7
- data.tar.gz: 41d93c9415d7352a35fe2e914784a1581c15dfd015e63f964d8b60be46c7334edfa69247f574075c111482ae37aa3e93bf9500441253019f910d9b85cd13a98b
6
+ metadata.gz: e80bc1548f85c52f88e766a273a7f6a3f4637a398b549a36dd65b756a4243a2d86511354324120938aabdd40c5427abe9be12169890b7745721847f6da2dbfa4
7
+ data.tar.gz: fd5511135a658f588d154526bbcbe1da8b2d75b7c13d3c73687aba726293555cbd1b3f38defbe8f51ea1ce33fef3c05b38fb82c7e1d8d8f9fb96f6e214d742b2
data/README.md CHANGED
@@ -51,6 +51,11 @@ RailsActiveMcp.configure do |config|
51
51
  config.default_timeout = 30
52
52
  config.max_results = 100
53
53
 
54
+ # Server configuration
55
+ config.server_mode = :stdio # :stdio for Claude Desktop, :http for web
56
+ config.server_host = 'localhost'
57
+ config.server_port = 3001
58
+
54
59
  # Model access control
55
60
  config.allowed_models = %w[User Post Comment] # Empty = all allowed
56
61
  config.blocked_models = %w[AdminUser Secret]
@@ -64,6 +69,10 @@ RailsActiveMcp.configure do |config|
64
69
  config.production_mode! # Very strict
65
70
  config.strict_mode! # Safe defaults
66
71
  config.permissive_mode! # Development friendly
72
+
73
+ # Server mode shortcuts
74
+ config.stdio_mode! # Set stdio mode for Claude Desktop
75
+ config.http_mode!(host: '0.0.0.0', port: 8080) # Set HTTP mode with custom host/port
67
76
  end
68
77
  ```
69
78
 
@@ -71,13 +80,18 @@ end
71
80
 
72
81
  You have several options for running the MCP server:
73
82
 
74
- ### Option 1: Stdio server (recommended for Claude Desktop)
83
+ ### Option 1: Use configured mode (recommended)
75
84
 
76
85
  ```bash
77
- $ bundle exec rails-active-mcp-server stdio
86
+ $ bundle exec rails-active-mcp-server
78
87
  ```
79
88
 
80
- This mode is required for Claude Desktop integration and other MCP clients that use stdio transport.
89
+ This will use the server mode configured in your initializer (`:stdio` by default). You can override the mode:
90
+
91
+ ```bash
92
+ $ bundle exec rails-active-mcp-server stdio # Force stdio mode
93
+ $ bundle exec rails-active-mcp-server http # Force HTTP mode
94
+ ```
81
95
 
82
96
  ### Option 2: Rails-mounted (HTTP, good for development)
83
97
 
@@ -6,10 +6,29 @@ require 'rack/handler/webrick'
6
6
  require 'json'
7
7
  require_relative '../lib/rails_active_mcp'
8
8
 
9
- # Parse command line options
10
- transport = ARGV[0] || 'http'
11
- port = ARGV.include?('--port') ? ARGV[ARGV.index('--port') + 1].to_i : 3001
12
- host = ARGV.include?('--host') ? ARGV[ARGV.index('--host') + 1] : 'localhost'
9
+ # Load Rails configuration if available
10
+ require_relative '../config/environment' if File.exist?('config/environment.rb')
11
+
12
+ # Parse command line options with config defaults
13
+ default_mode = if defined?(RailsActiveMcp) && RailsActiveMcp.respond_to?(:config)
14
+ RailsActiveMcp.config.server_mode.to_s
15
+ else
16
+ 'stdio'
17
+ end
18
+ default_port = if defined?(RailsActiveMcp) && RailsActiveMcp.respond_to?(:config)
19
+ RailsActiveMcp.config.server_port
20
+ else
21
+ 3001
22
+ end
23
+ default_host = if defined?(RailsActiveMcp) && RailsActiveMcp.respond_to?(:config)
24
+ RailsActiveMcp.config.server_host
25
+ else
26
+ 'localhost'
27
+ end
28
+
29
+ transport = ARGV[0] || default_mode
30
+ port = ARGV.include?('--port') ? ARGV[ARGV.index('--port') + 1].to_i : default_port
31
+ host = ARGV.include?('--host') ? ARGV[ARGV.index('--host') + 1] : default_host
13
32
 
14
33
  case transport
15
34
  when 'stdio'
@@ -12,20 +12,27 @@ Next Steps:
12
12
 
13
13
  1. Review and customize the configuration in config/initializers/rails_active_mcp.rb
14
14
 
15
- 2. Start the MCP server:
16
- Option A: Rails-mounted server (HTTP)
17
- $ rails server
15
+ 2. Configure server mode in config/initializers/rails_active_mcp.rb:
16
+ config.server_mode = :stdio # For Claude Desktop (default)
17
+ config.server_mode = :http # For HTTP-based integrations
18
+ config.server_host = 'localhost'
19
+ config.server_port = 3001
18
20
 
19
- Option B: Standalone HTTP server
20
- $ bundle exec rails-active-mcp-server http
21
+ 3. Start the MCP server:
22
+ Option A: Use configured mode (RECOMMENDED)
23
+ $ bundle exec rails-active-mcp-server
21
24
 
22
- Option C: Using rackup
23
- $ rackup mcp.ru -p 3001
25
+ Option B: Override mode via command line
26
+ $ bundle exec rails-active-mcp-server stdio # Force stdio mode
27
+ $ bundle exec rails-active-mcp-server http # Force HTTP mode
24
28
 
25
- Option D: Stdio server for Claude Desktop (RECOMMENDED)
26
- $ bundle exec rails-active-mcp-server stdio
29
+ Option C: Rails-mounted server (HTTP)
30
+ $ rails server
31
+
32
+ Option D: Using rackup
33
+ $ rackup mcp.ru -p 3001
27
34
 
28
- 3. For Claude Desktop integration, add this to your Claude Desktop configuration:
35
+ 4. For Claude Desktop integration, add this to your Claude Desktop configuration:
29
36
 
30
37
  Location: ~/.config/claude-desktop/claude_desktop_config.json (Linux/macOS)
31
38
  Location: %APPDATA%\Claude\claude_desktop_config.json (Windows)
@@ -52,7 +59,7 @@ Next Steps:
52
59
  }
53
60
  }
54
61
 
55
- 4. For other MCP clients (HTTP-based), add this to your MCP configuration:
62
+ 5. For other MCP clients (HTTP-based), add this to your MCP configuration:
56
63
  {
57
64
  "mcpServers": {
58
65
  "rails-console": {
@@ -62,7 +69,7 @@ Next Steps:
62
69
  }
63
70
  }
64
71
 
65
- 5. Test the installation:
72
+ 6. Test the installation:
66
73
  $ rails console
67
74
  > RailsActiveMcp.safe?("User.count")
68
75
  > RailsActiveMcp.execute("User.count")
@@ -85,6 +92,26 @@ Transport Modes:
85
92
  - stdio: For Claude Desktop and compatible MCP clients (recommended)
86
93
  - http: For HTTP-based integrations and web applications
87
94
 
95
+ Configuration Examples:
96
+
97
+ For Claude Desktop (default):
98
+ config.server_mode = :stdio
99
+
100
+ For HTTP web integrations:
101
+ config.server_mode = :http
102
+ config.server_host = 'localhost'
103
+ config.server_port = 3001
104
+
105
+ For Docker/remote access:
106
+ config.http_mode!(host: '0.0.0.0', port: 8080)
107
+
108
+ For development with multiple transport modes:
109
+ if Rails.env.development?
110
+ config.stdio_mode! # Claude Desktop
111
+ else
112
+ config.http_mode!(host: '0.0.0.0', port: 3001) # Production HTTP
113
+ end
114
+
88
115
  Custom MCP Server Benefits:
89
116
  - No external dependencies
90
117
  - Full control over implementation
@@ -1,6 +1,5 @@
1
1
  require 'rails_active_mcp'
2
2
 
3
-
4
3
  RailsActiveMcp.configure do |config|
5
4
  # Enable/disable the MCP server
6
5
  config.enabled = true
@@ -19,7 +18,12 @@ RailsActiveMcp.configure do |config|
19
18
 
20
19
  # Logging and auditing
21
20
  config.log_executions = true
22
- config.audit_file = Rails.root.join("log", "rails_active_mcp.log")
21
+ config.audit_file = Rails.root.join('log', 'rails_active_mcp.log')
22
+
23
+ # Server configuration
24
+ config.server_mode = :stdio # :stdio for Claude Desktop, :http for web integrations
25
+ config.server_host = 'localhost'
26
+ config.server_port = 3001
23
27
 
24
28
  # Environment-specific settings
25
29
  case Rails.env
@@ -35,5 +39,5 @@ RailsActiveMcp.configure do |config|
35
39
  # config.add_safety_pattern(/CustomDangerousMethod/, "Custom dangerous operation")
36
40
 
37
41
  # Operations that require manual confirmation
38
- config.require_confirmation_for = [:delete, :destroy, :update_all, :delete_all]
42
+ config.require_confirmation_for = %i[delete destroy update_all delete_all]
39
43
  end
@@ -5,7 +5,8 @@ module RailsActiveMcp
5
5
  attr_accessor :enabled, :safe_mode, :default_timeout, :max_results,
6
6
  :allowed_models, :blocked_models, :custom_safety_patterns,
7
7
  :log_executions, :audit_file, :enable_mutation_tools,
8
- :require_confirmation_for, :execution_environment
8
+ :require_confirmation_for, :execution_environment, :server_mode,
9
+ :server_host, :server_port
9
10
 
10
11
  def initialize
11
12
  @enabled = true
@@ -17,10 +18,16 @@ module RailsActiveMcp
17
18
  @custom_safety_patterns = []
18
19
  @log_executions = true
19
20
  # Safe Rails.root access
20
- @audit_file = rails_root_join("log", "rails_active_mcp.log") if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
21
+ if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
22
+ @audit_file = rails_root_join('log',
23
+ 'rails_active_mcp.log')
24
+ end
21
25
  @enable_mutation_tools = false
22
- @require_confirmation_for = [:delete, :destroy, :update_all, :delete_all]
26
+ @require_confirmation_for = %i[delete destroy update_all delete_all]
23
27
  @execution_environment = :current # :current, :sandbox, :readonly_replica
28
+ @server_mode = :stdio # :stdio, :http
29
+ @server_host = 'localhost'
30
+ @server_port = 3001
24
31
  end
25
32
 
26
33
  # Safety configuration
@@ -42,7 +49,7 @@ module RailsActiveMcp
42
49
  strict_mode!
43
50
  @execution_environment = :readonly_replica
44
51
  @log_executions = true
45
- @require_confirmation_for = [:delete, :destroy, :update, :create, :save]
52
+ @require_confirmation_for = %i[delete destroy update create save]
46
53
  end
47
54
 
48
55
  # Model access configuration
@@ -58,6 +65,21 @@ module RailsActiveMcp
58
65
  @custom_safety_patterns << { pattern: pattern, description: description }
59
66
  end
60
67
 
68
+ # Server configuration
69
+ def stdio_mode!
70
+ @server_mode = :stdio
71
+ end
72
+
73
+ def http_mode!(host: 'localhost', port: 3001)
74
+ @server_mode = :http
75
+ @server_host = host
76
+ @server_port = port
77
+ end
78
+
79
+ def server_mode_valid?
80
+ %i[stdio http].include?(@server_mode)
81
+ end
82
+
61
83
  # Validation
62
84
  def model_allowed?(model_name)
63
85
  model_str = model_name.to_s
@@ -73,13 +95,15 @@ module RailsActiveMcp
73
95
  end
74
96
 
75
97
  def validate!
76
- raise ArgumentError, "timeout must be positive" if @default_timeout <= 0
77
- raise ArgumentError, "max_results must be positive" if @max_results <= 0
98
+ raise ArgumentError, 'timeout must be positive' if @default_timeout <= 0
99
+ raise ArgumentError, 'max_results must be positive' if @max_results <= 0
100
+ raise ArgumentError, "invalid server_mode: #{@server_mode}" unless server_mode_valid?
101
+ raise ArgumentError, 'server_port must be positive' if @server_port <= 0
78
102
 
79
- if defined?(Rails) && @audit_file
80
- audit_dir = File.dirname(@audit_file)
81
- FileUtils.mkdir_p(audit_dir) unless File.directory?(audit_dir)
82
- end
103
+ return unless defined?(Rails) && @audit_file
104
+
105
+ audit_dir = File.dirname(@audit_file)
106
+ FileUtils.mkdir_p(audit_dir) unless File.directory?(audit_dir)
83
107
  end
84
108
 
85
109
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsActiveMcp
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-active-mcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandyn Britton