rails-active-mcp 0.1.3 → 0.1.5

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: ab07c3ba6b1a97791cbaa3345aadb3cc43fb2c28b6c5008bace92f1c4dc089f3
4
+ data.tar.gz: c1489640a38d8c4ee0e886ab0b311bb6ee1e7a2cfb06b71bdef2ef8a7b329d6d
5
5
  SHA512:
6
- metadata.gz: 9c659fce767c7f9249f970a40d5fa1c627b151f2ef86990f676f8e50ddf2d9d398772389761e67ced5382b0640d69119be1fddf804b8fe7905814df55b659ec8
7
- data.tar.gz: 41d93c9415d7352a35fe2e914784a1581c15dfd015e63f964d8b60be46c7334edfa69247f574075c111482ae37aa3e93bf9500441253019f910d9b85cd13a98b
6
+ metadata.gz: aac5e4ebc969fb723c24f48ba7f00e33b3b374df75816d4ce6c1af85278eff95575005a4c045a1c47c6ffa87cf4d1802e98a738af3860291e1b5f38bdaa57f1a
7
+ data.tar.gz: aa77ab523129a8419dc70f562915a2a78e8cd57dc9a6a64dbe29810131797a56ee66e7d92dda5d85dd903217128fe29202e44077b84d6e47da9bb99333fe6cd5
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
 
@@ -2,14 +2,32 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'rack'
5
- require 'rack/handler/webrick'
6
5
  require 'json'
7
6
  require_relative '../lib/rails_active_mcp'
8
7
 
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'
8
+ # Load Rails configuration if available
9
+ require_relative '../config/environment' if File.exist?('config/environment.rb')
10
+
11
+ # Parse command line options with config defaults
12
+ default_mode = if defined?(RailsActiveMcp) && RailsActiveMcp.respond_to?(:config)
13
+ RailsActiveMcp.config.server_mode.to_s
14
+ else
15
+ 'stdio'
16
+ end
17
+ default_port = if defined?(RailsActiveMcp) && RailsActiveMcp.respond_to?(:config)
18
+ RailsActiveMcp.config.server_port
19
+ else
20
+ 3001
21
+ end
22
+ default_host = if defined?(RailsActiveMcp) && RailsActiveMcp.respond_to?(:config)
23
+ RailsActiveMcp.config.server_host
24
+ else
25
+ 'localhost'
26
+ end
27
+
28
+ transport = ARGV[0] || default_mode
29
+ port = ARGV.include?('--port') ? ARGV[ARGV.index('--port') + 1].to_i : default_port
30
+ host = ARGV.include?('--host') ? ARGV[ARGV.index('--host') + 1] : default_host
13
31
 
14
32
  case transport
15
33
  when 'stdio'
@@ -32,12 +50,19 @@ when 'http'
32
50
  puts 'Press Ctrl+C to stop'
33
51
 
34
52
  begin
53
+ require 'webrick'
54
+ require 'rack/handler/webrick'
55
+
35
56
  Rack::Handler::WEBrick.run(
36
57
  RailsActiveMcp::McpServer.new,
37
58
  Port: port,
38
59
  Host: host,
39
60
  Logger: WEBrick::Log.new(nil, WEBrick::BasicLog::WARN)
40
61
  )
62
+ rescue LoadError => e
63
+ puts 'Error: WEBrick not available. Please install: gem install webrick'
64
+ puts 'Or use stdio mode for Claude Desktop: rails-active-mcp-server stdio'
65
+ exit(1)
41
66
  rescue Interrupt
42
67
  puts "\nShutting down server..."
43
68
  end
@@ -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.5'
5
5
  end
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency 'json', '~> 2.0'
38
38
  spec.add_dependency 'rack', '~> 3.0'
39
39
  spec.add_dependency 'timeout', '~> 0.4'
40
+ spec.add_dependency 'webrick', '~> 1.8'
40
41
 
41
42
  # Development dependencies - keep versions consistent with Gemfile
42
43
  spec.add_development_dependency 'factory_bot_rails', '~> 6.0'
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandyn Britton
@@ -79,6 +79,20 @@ dependencies:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0.4'
82
+ - !ruby/object:Gem::Dependency
83
+ name: webrick
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.8'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.8'
82
96
  - !ruby/object:Gem::Dependency
83
97
  name: factory_bot_rails
84
98
  requirement: !ruby/object:Gem::Requirement