activeadmin_mcp 0.0.3 → 0.1.0

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.
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module ActiveadminMcp
4
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
5
3
  end
@@ -1,11 +1,17 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative "activeadmin_mcp/version"
4
2
  require_relative "activeadmin_mcp/configuration"
5
3
  require_relative "activeadmin_mcp/authorization"
4
+ require_relative "activeadmin_mcp/active_admin_ext"
5
+ require_relative "activeadmin_mcp/action_definition"
6
+ require_relative "activeadmin_mcp/action_schema"
7
+ require_relative "activeadmin_mcp/action_params"
8
+ require_relative "activeadmin_mcp/action_catalog"
9
+ require_relative "activeadmin_mcp/controller_dispatcher"
10
+ require_relative "activeadmin_mcp/action_runner"
6
11
  require_relative "activeadmin_mcp/resource_registry"
7
12
  require_relative "activeadmin_mcp/form_field_collector"
8
- require_relative "activeadmin_mcp/record_updater"
13
+ require_relative "activeadmin_mcp/form_description"
14
+ require_relative "activeadmin_mcp/record_writer"
9
15
  require_relative "activeadmin_mcp/request_handler"
10
16
  require_relative "activeadmin_mcp/engine"
11
17
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "rails/generators"
4
2
  require "rails/generators/active_record"
5
3
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  ActiveadminMcp.configure do |config|
4
2
  # Uncomment to enable API token authentication.
5
3
  # Requires running the auth migration first:
@@ -19,6 +17,11 @@ ActiveadminMcp.configure do |config|
19
17
  # Path where the MCP server is mounted.
20
18
  # config.mount_path = "/mcp"
21
19
 
20
+ # How the engine adds its route: :prepend (default), :append, or :none.
21
+ # Set it to :none when you want to mount the engine yourself, for instance
22
+ # inside a constraints block your admin routes already sit in.
23
+ # config.mount_strategy = :prepend
24
+
22
25
  # HTTP header used to read the Bearer token from.
23
26
  # Useful when a reverse proxy (e.g. AWS Verified Access) strips the
24
27
  # standard Authorization header.
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  ActiveAdmin.register_page "MCP API Tokens" do
4
2
  menu label: "MCP Tokens", parent: ActiveadminMcp.config.menu_parent, priority: 100
5
3
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  class CreateMcpApiTokens < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
4
2
  def change
5
3
  return if table_exists?(:mcp_api_tokens)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_mcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - harunkumars
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
19
+ version: '7.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '6.1'
26
+ version: '7.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activeadmin
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '3.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '3.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -95,11 +95,19 @@ files:
95
95
  - app/models/activeadmin_mcp/api_token.rb
96
96
  - config/routes.rb
97
97
  - lib/activeadmin_mcp.rb
98
+ - lib/activeadmin_mcp/action_catalog.rb
99
+ - lib/activeadmin_mcp/action_definition.rb
100
+ - lib/activeadmin_mcp/action_params.rb
101
+ - lib/activeadmin_mcp/action_runner.rb
102
+ - lib/activeadmin_mcp/action_schema.rb
103
+ - lib/activeadmin_mcp/active_admin_ext.rb
98
104
  - lib/activeadmin_mcp/authorization.rb
99
105
  - lib/activeadmin_mcp/configuration.rb
106
+ - lib/activeadmin_mcp/controller_dispatcher.rb
100
107
  - lib/activeadmin_mcp/engine.rb
108
+ - lib/activeadmin_mcp/form_description.rb
101
109
  - lib/activeadmin_mcp/form_field_collector.rb
102
- - lib/activeadmin_mcp/record_updater.rb
110
+ - lib/activeadmin_mcp/record_writer.rb
103
111
  - lib/activeadmin_mcp/request_handler.rb
104
112
  - lib/activeadmin_mcp/resource_registry.rb
105
113
  - lib/activeadmin_mcp/version.rb
@@ -122,14 +130,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
130
  requirements:
123
131
  - - ">="
124
132
  - !ruby/object:Gem::Version
125
- version: 3.0.0
133
+ version: 4.0.0
126
134
  required_rubygems_version: !ruby/object:Gem::Requirement
127
135
  requirements:
128
136
  - - ">="
129
137
  - !ruby/object:Gem::Version
130
138
  version: '0'
131
139
  requirements: []
132
- rubygems_version: 3.6.9
140
+ rubygems_version: 4.0.20
133
141
  specification_version: 4
134
142
  summary: MCP server for Rails apps with ActiveAdmin
135
143
  test_files: []
@@ -1,108 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveadminMcp
4
- # Updates a single ActiveAdmin-managed record, enforcing the same three gates
5
- # the admin UI would: the resource must expose the update action, the current
6
- # user must be authorized, and only fields the admin form permits are written.
7
- class RecordUpdater
8
- UPDATE = :update
9
-
10
- # Raised internally when the resource's permitted params cannot be resolved.
11
- class PermitError < StandardError; end
12
-
13
- def initialize(resource:, current_user:)
14
- @resource = resource
15
- @current_user = current_user
16
- end
17
-
18
- def call(id:, attributes:)
19
- config = @resource[:config]
20
-
21
- return error("Resource is not editable: #{@resource[:name]}") unless editable?(config)
22
-
23
- record = @resource[:model].find_by(id: id)
24
- return error("Record not found: #{@resource[:name]}##{id}") unless record
25
-
26
- unless authorized?(config, record)
27
- return error("Not authorized to update #{@resource[:name]}##{id}")
28
- end
29
-
30
- begin
31
- permitted = permitted_attributes(config, attributes)
32
- rescue PermitError => e
33
- return error(e.message)
34
- end
35
- return error("No permitted attributes to update") if permitted.empty?
36
-
37
- if record.update(permitted)
38
- {
39
- resource: @resource[:name],
40
- id: record.id,
41
- updated: permitted.keys,
42
- record: record.as_json,
43
- }
44
- else
45
- error("Validation failed", details: record.errors.full_messages)
46
- end
47
- end
48
-
49
- private
50
-
51
- def editable?(config)
52
- config.defined_actions.include?(UPDATE)
53
- end
54
-
55
- def authorized?(config, record)
56
- Authorization.for(config, @current_user).authorized?(UPDATE, record)
57
- end
58
-
59
- # Resolves the fields we may write, accepting exactly what the admin form
60
- # accepts. Prefers the resource's own `permit_params` (via the controller's
61
- # compiled permitted_params); when a resource declares its writable fields
62
- # through a `form do ... end` block instead — as ActiveAdmin's default
63
- # permitted_params then returns nil — derives them from the form inputs.
64
- # Fails closed if neither can be resolved.
65
- def permitted_attributes(config, attributes)
66
- from_permit_params(config, attributes) ||
67
- from_form(config, attributes) ||
68
- raise(PermitError, "Could not determine permitted attributes: #{@resource[:name]}")
69
- end
70
-
71
- def from_permit_params(config, attributes)
72
- param_key = config.param_key.to_sym
73
- controller = config.controller.new
74
- return nil unless controller.respond_to?(:permitted_params, true)
75
-
76
- controller.params = ActionController::Parameters.new(param_key => attributes)
77
- permitted = controller.send(:permitted_params)
78
- scoped = permitted && permitted[param_key]
79
- scoped ? scoped.to_h.symbolize_keys : nil
80
- rescue StandardError
81
- nil
82
- end
83
-
84
- def from_form(config, attributes)
85
- fields = form_fields(config)
86
- return nil if fields.empty?
87
-
88
- ActionController::Parameters.new(attributes).permit(*fields).to_h.symbolize_keys
89
- rescue StandardError
90
- nil
91
- end
92
-
93
- def form_fields(config)
94
- return [] unless config.respond_to?(:page_presenters)
95
-
96
- block = config.page_presenters[:form]&.block
97
- return [] unless block
98
-
99
- FormFieldCollector.new.collect(&block)
100
- end
101
-
102
- def error(message, details: nil)
103
- result = { error: message }
104
- result[:details] = details if details
105
- result
106
- end
107
- end
108
- end