solidus_mcp 0.2.0.rc2 → 0.2.0.rc3

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -0
  3. data/README.md +321 -3
  4. data/app/assets/stylesheets/solidus_mcp/admin.css +39 -0
  5. data/app/assets/stylesheets/solidus_mcp/consent.css +77 -0
  6. data/app/controllers/solidus_admin/mcp_activity_controller.rb +67 -0
  7. data/app/controllers/solidus_mcp/endpoint_controller.rb +36 -0
  8. data/app/models/solidus_mcp/activity_event.rb +37 -0
  9. data/app/models/solidus_mcp/audit_context.rb +7 -0
  10. data/app/models/solidus_mcp/stock_adjustment.rb +16 -0
  11. data/app/models/solidus_mcp/tool_request.rb +10 -0
  12. data/app/services/solidus_mcp/action_audit.rb +169 -0
  13. data/app/services/solidus_mcp/image_context.rb +44 -0
  14. data/app/services/solidus_mcp/order_workflow_authorization.rb +76 -0
  15. data/app/services/solidus_mcp/tool_request_execution.rb +76 -0
  16. data/app/tools/solidus_mcp/tools/add_product_option_type.rb +36 -0
  17. data/app/tools/solidus_mcp/tools/add_product_to_taxon.rb +40 -0
  18. data/app/tools/solidus_mcp/tools/adjust_stock.rb +98 -0
  19. data/app/tools/solidus_mcp/tools/attach_product_image.rb +77 -0
  20. data/app/tools/solidus_mcp/tools/bulk_update_variant_prices.rb +1 -1
  21. data/app/tools/solidus_mcp/tools/cancel_order.rb +44 -0
  22. data/app/tools/solidus_mcp/tools/create_product.rb +1 -0
  23. data/app/tools/solidus_mcp/tools/create_variant_price.rb +59 -0
  24. data/app/tools/solidus_mcp/tools/list_option_types.rb +34 -0
  25. data/app/tools/solidus_mcp/tools/list_option_values.rb +27 -0
  26. data/app/tools/solidus_mcp/tools/list_product_images.rb +26 -0
  27. data/app/tools/solidus_mcp/tools/list_shipping_categories.rb +24 -0
  28. data/app/tools/solidus_mcp/tools/list_stock_locations.rb +27 -0
  29. data/app/tools/solidus_mcp/tools/list_taxons.rb +40 -0
  30. data/app/tools/solidus_mcp/tools/publish_product.rb +32 -0
  31. data/app/tools/solidus_mcp/tools/refund_payment.rb +63 -0
  32. data/app/tools/solidus_mcp/tools/remove_product_image.rb +33 -0
  33. data/app/tools/solidus_mcp/tools/reorder_product_images.rb +41 -0
  34. data/app/tools/solidus_mcp/tools/ship_shipment.rb +63 -0
  35. data/app/tools/solidus_mcp/tools/unpublish_product.rb +29 -0
  36. data/app/tools/solidus_mcp/tools/update_variant.rb +54 -0
  37. data/app/tools/solidus_mcp/tools/update_variant_price.rb +1 -1
  38. data/app/views/solidus_admin/mcp_activity/index.html.erb +53 -0
  39. data/app/views/solidus_admin/mcp_connections/index.html.erb +2 -0
  40. data/app/views/solidus_mcp/authorizations/new.html.erb +59 -41
  41. data/config/routes.rb +1 -0
  42. data/db/migrate/20261112000000_create_solidus_mcp_stock_adjustments.rb +19 -0
  43. data/db/migrate/20261112010000_create_solidus_mcp_tool_requests.rb +19 -0
  44. data/db/migrate/20261112020000_create_solidus_mcp_activity_events.rb +34 -0
  45. data/db/migrate/20261112020100_add_actor_role_to_mcp_activity_events.rb +7 -0
  46. data/lib/solidus_mcp/audited_server.rb +25 -0
  47. data/lib/solidus_mcp/engine.rb +8 -3
  48. data/lib/solidus_mcp/policy.rb +4 -4
  49. data/lib/solidus_mcp/registry.rb +5 -2
  50. data/lib/solidus_mcp/server.rb +1 -2
  51. data/lib/solidus_mcp/tool.rb +9 -7
  52. data/lib/solidus_mcp/version.rb +1 -1
  53. data/lib/solidus_mcp.rb +5 -1
  54. metadata +37 -2
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusMcp
4
+ module Tools
5
+ class UpdateVariant < Base
6
+ tool_name :update_variant
7
+ description "Update variant SKU, weight, dimensions, cost price, or inventory tracking. Decimals are nonnegative strings with at most two decimal places. Changes take effect immediately."
8
+ category "Products"
9
+ permission "update_variant"
10
+ read_only false
11
+ ability :update, "Spree::Product"
12
+ ability :update, "Spree::Variant"
13
+ input :variant_id, type: "integer", minimum: 1, required: true
14
+ input :changes, type: "object", minProperties: 1, additionalProperties: false, required: true,
15
+ properties: {sku: {type: "string", minLength: 1, maxLength: 255},
16
+ weight: {type: "string", pattern: "^(0|[1-9][0-9]{0,5})(\\.[0-9]{1,2})?$", maxLength: 9},
17
+ height: {type: "string", pattern: "^(0|[1-9][0-9]{0,5})(\\.[0-9]{1,2})?$", maxLength: 9},
18
+ width: {type: "string", pattern: "^(0|[1-9][0-9]{0,5})(\\.[0-9]{1,2})?$", maxLength: 9},
19
+ depth: {type: "string", pattern: "^(0|[1-9][0-9]{0,5})(\\.[0-9]{1,2})?$", maxLength: 9},
20
+ cost_price: {type: "string", pattern: "^(0|[1-9][0-9]{0,7})(\\.[0-9]{1,2})?$", maxLength: 11},
21
+ track_inventory: {type: "boolean"}}
22
+
23
+ protected
24
+
25
+ def call(variant_id:, changes:)
26
+ attributes = changes.symbolize_keys
27
+ %i[weight height width depth cost_price].each do |attribute|
28
+ next unless attributes.key?(attribute)
29
+ digits = (attribute == :cost_price) ? 8 : 6
30
+ unless attributes[attribute].match?(/\A(?:0|[1-9][0-9]{0,#{digits - 1}})(?:\.[0-9]{1,2})?\z/)
31
+ raise ToolError, "#{attribute} must be a nonnegative decimal string with at most two decimal places"
32
+ end
33
+ attributes[attribute] = BigDecimal(attributes[attribute])
34
+ end
35
+ variant = policy.scope(Spree::Variant, :update)
36
+ .where(product_id: policy.scope(Spree::Product, :update).select(:id)).find(variant_id)
37
+ variant.with_lock do
38
+ authorize!
39
+ policy.authorize_record!(:update, variant.product)
40
+ authorize_attributes!(variant, attributes)
41
+ variant.assign_attributes(attributes)
42
+ authorize_attributes!(variant, attributes)
43
+ variant.save!
44
+ end
45
+ {variant_id: variant.id, updated: true}
46
+ end
47
+
48
+ def authorize_attributes!(variant, attributes)
49
+ policy.authorize_record!(:update, variant)
50
+ attributes.each_key { |attribute| policy.authorize_record!(:update, variant, attribute: attribute) }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -13,7 +13,7 @@ module SolidusMcp
13
13
  ability :update, "Spree::Price"
14
14
  input :variant_id, type: "integer", minimum: 1, required: true
15
15
  input :currency, type: "string", pattern: "^[A-Z]{3}$", required: true
16
- input :country_iso, type: ["string", "null"], pattern: "^[A-Z]{2}$", required: true
16
+ input :country_iso, anyOf: [{type: "string", pattern: "^[A-Z]{2}$"}, {type: "null"}], required: true
17
17
  input :amount, type: "string", required: true
18
18
 
19
19
  protected
@@ -0,0 +1,53 @@
1
+ <%= stylesheet_link_tag "solidus_mcp/admin", "data-turbo-track": "reload" %>
2
+ <div class="solidus-mcp-admin">
3
+ <h1 class="solidus-mcp-page-title">MCP activity</h1>
4
+ <p class="solidus-mcp-intro">Review which user and client performed each action, its targets, and whether it succeeded. Your MCP administration role determines whose activity is visible.</p>
5
+ <p><%= link_to "AI connections", solidus_admin.mcp_connections_path %></p>
6
+
7
+ <%= form_with url: solidus_admin.mcp_activity_index_path, method: :get, local: true, class: "solidus-mcp-activity-filters" do %>
8
+ <div><%= label_tag :user, "User (email or ID)" %><%= text_field_tag :user, @filters["user"], maxlength: 255 %></div>
9
+ <div><%= label_tag :tool, "Tool" %><%= text_field_tag :tool, @filters["tool"], maxlength: 128, placeholder: "get_product" %></div>
10
+ <div><%= label_tag :outcome, "Outcome" %><%= select_tag :outcome, options_for_select([["All outcomes", ""], ["Succeeded", "succeeded"], ["Partially succeeded", "partial"], ["Denied", "denied"], ["Failed", "failed"], ["Unfinished", "started"]], @filters["outcome"]) %></div>
11
+ <div><%= label_tag :from, "From (#{Time.zone.name})" %><%= datetime_local_field_tag :from, @filters["from"], step: 1 %></div>
12
+ <div><%= label_tag :to, "To (#{Time.zone.name})" %><%= datetime_local_field_tag :to, @filters["to"], step: 1 %></div>
13
+ <%= hidden_field_tag :action_type, @filters["action_type"] if @filters["action_type"].present? %>
14
+ <div class="solidus-mcp-activity-filter-actions"><%= submit_tag "Filter" %> <%= link_to "Clear", solidus_admin.mcp_activity_index_path %></div>
15
+ <% end %>
16
+
17
+ <nav class="solidus-mcp-activity-groups" aria-label="Action types">
18
+ <%= link_to "All (#{@counts.values.sum})", solidus_admin.mcp_activity_index_path(@filters.except("action_type", "before_id")), aria: {current: @filters["action_type"].blank? ? "page" : nil} %>
19
+ <% SolidusMcp::ActivityEvent::ACTIONS.each do |action| %>
20
+ <%= link_to "#{action.titleize} (#{@counts.fetch(action, 0)})", solidus_admin.mcp_activity_index_path(@filters.except("before_id").merge("action_type" => action)), aria: {current: @filters["action_type"] == action ? "page" : nil} %>
21
+ <% end %>
22
+ </nav>
23
+
24
+ <div class="solidus-mcp-table-scroll">
25
+ <table class="solidus-mcp-table">
26
+ <thead><tr><th scope="col">Time</th><th scope="col">User</th><th scope="col">Client</th><th scope="col">Action</th><th scope="col">Outcome</th><th scope="col">Duration</th><th scope="col">Details</th></tr></thead>
27
+ <tbody>
28
+ <% @events.each do |event| %>
29
+ <tr data-event-id="<%= event.event_id %>">
30
+ <td><time datetime="<%= event.started_at.iso8601 %>"><%= event.started_at.in_time_zone.strftime("%Y-%m-%d %H:%M:%S %Z") %></time></td>
31
+ <td><%= @users[event.user_id]&.email || "User ##{event.user_id}" %></td>
32
+ <td><%= event.application_name.presence || "Client ##{event.application_id}" %></td>
33
+ <td><strong><%= event.action.titleize %></strong><br><code><%= event.tool_name || event.protocol_method %></code></td>
34
+ <td><%= event.status == "started" ? "Unfinished" : event.status.titleize %></td>
35
+ <td><%= event.duration_ms ? "#{event.duration_ms} ms" : "—" %></td>
36
+ <td><details><summary>View details</summary>
37
+ <p>Event: <code><%= event.event_id %></code></p>
38
+ <% if event.request_id.present? %><p>Request: <code><%= event.request_id %></code></p><% end %>
39
+ <% if event.resource_ids.present? %><p>Targets: <code><%= event.resource_ids.to_json %></code></p><% end %>
40
+ <% if event.changed_fields.present? %><p>Requested fields: <%= event.changed_fields.join(", ") %></p><% end %>
41
+ <% if event.error_class.present? %><p>Error type: <code><%= event.error_class %></code></p><% end %>
42
+ </details></td>
43
+ </tr>
44
+ <% end %>
45
+ </tbody>
46
+ </table>
47
+ </div>
48
+ <% if @events.empty? %><p class="solidus-mcp-empty-state">No activity matches these filters.</p><% end %>
49
+ <nav class="solidus-mcp-pagination" aria-label="Activity pages">
50
+ <% if @filters["before_id"].present? %><%= link_to "Newest", solidus_admin.mcp_activity_index_path(@filters.except("before_id")) %><% end %>
51
+ <% if @more %><%= link_to "Older", solidus_admin.mcp_activity_index_path(@filters.merge("before_id" => @events.last.id)) %><% end %>
52
+ </nav>
53
+ </div>
@@ -9,6 +9,8 @@
9
9
  "You are an MCP user. Only your own connections are shown; an MCP administrator manages their permissions."
10
10
  end %> Permissions also remain limited by the connection owner's store access and OAuth consent.</p>
11
11
 
12
+ <p><%= link_to "MCP activity", solidus_admin.mcp_activity_index_path %></p>
13
+
12
14
  <% if mcp_superadministrator? %>
13
15
  <p><%= link_to "Manage MCP administrators", solidus_admin.mcp_administrators_path %></p>
14
16
  <% end %>
@@ -1,43 +1,61 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Connect to your Solidus store</title></head>
4
- <body><main>
5
- <h1>Connect <%= @pre_auth.client.application.name %> to your Solidus store</h1>
6
- <p>Approve only if you started this connection. The client supplies its name.</p>
7
- <p>Return address: <%= @pre_auth.redirect_uri %></p>
8
- <% if @pre_auth.scopes.include?("mcp:read") %>
9
- <h2>Read access</h2>
10
- <ul><li>Search products and variants.</li><li>View prices and inventory.</li><li>Read order information.</li></ul>
11
- <% end %>
12
- <% if @pre_auth.scopes.include?("mcp:write") %>
13
- <h2>Write access</h2>
14
- <ul><li>Modify product information.</li><li>Update prices.</li><li>Perform other explicitly enabled store-management operations.</li></ul>
15
- <% end %>
16
- <p>Administrators must also enable individual tools in AI connections. They can change enabled tools within this access level without reconnecting.</p>
17
- <% {"Authorize" => :post, "Deny" => :delete}.each do |label, method| %>
18
- <%= form_tag "#{SolidusMcp.configuration.endpoint_url}/oauth/authorize", method: method do %>
19
- <% %i[client_id redirect_uri state response_type scope code_challenge code_challenge_method resource].each do |key| %>
20
- <%= hidden_field_tag key, params[key], id: nil %>
21
- <% end %>
22
- <%= submit_tag label %>
23
- <% end %>
24
- <% end %>
25
- <section aria-labelledby="additional-access-heading">
26
- <h2 id="additional-access-heading">Need additional access?</h2>
27
- <p>If your client cannot request write access, choose it here, then select Review access. You will review the updated access before authorizing.</p>
28
- <%= form_tag "#{SolidusMcp.configuration.endpoint_url}/oauth/authorize", method: :get, id: "review-oauth-scopes" do %>
29
- <%= hidden_field_tag :review_scopes, "1" %>
30
- <% %i[client_id redirect_uri state response_type code_challenge code_challenge_method resource].each do |key| %>
31
- <%= hidden_field_tag key, params[key], id: nil %>
32
- <% end %>
33
- <% scope_options.each do |scope| %>
34
- <p><label>
35
- <%= check_box_tag "requested_scopes[]", scope, @pre_auth.scopes.include?(scope), id: "oauth_scope_#{scope.tr(':', '_')}" %>
36
- <%= scope == "mcp:write" ? "Use enabled write tools, including tools enabled later" : "Use enabled read tools" %> (<code><%= scope %></code>)
37
- </label></p>
38
- <% end %>
39
- <%= submit_tag "Review access" %>
40
- <% end %>
41
- <p>Read and write access are separate; select both if you need both. Individual tools must still be enabled in AI connections. If write access is not listed, the client's registration must be updated before reconnecting.</p>
42
- </section>
43
- </main></body></html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Connect to your Solidus store</title>
7
+ <%= stylesheet_link_tag "solidus_mcp/admin", "solidus_mcp/consent" %>
8
+ </head>
9
+ <body class="solidus-mcp-consent">
10
+ <main class="solidus-mcp-admin solidus-mcp-consent-card" aria-labelledby="consent-heading">
11
+ <header>
12
+ <h1 id="consent-heading" class="solidus-mcp-page-title">Connect <%= @pre_auth.client.application.name %> to your Solidus store</h1>
13
+ <p>Only authorize an application you intended to connect. If someone sent you this link unexpectedly, deny the request.</p>
14
+ <p class="solidus-mcp-consent-address"><strong>Return address:</strong> <%= @pre_auth.redirect_uri %></p>
15
+ </header>
16
+ <div class="solidus-mcp-consent-access">
17
+ <% if @pre_auth.scopes.include?("mcp:read") %>
18
+ <section class="solidus-mcp-consent-scope">
19
+ <h2>Read access</h2>
20
+ <ul><li>Search products and variants.</li><li>View prices and inventory.</li><li>Read order information.</li></ul>
21
+ </section>
22
+ <% end %>
23
+ <% if @pre_auth.scopes.include?("mcp:write") %>
24
+ <section class="solidus-mcp-consent-scope">
25
+ <h2>Write access</h2>
26
+ <ul><li>Modify product information.</li><li>Update prices.</li><li>Perform other explicitly enabled store-management operations.</li></ul>
27
+ </section>
28
+ <% end %>
29
+ </div>
30
+ <p>Administrators must also enable individual tools in AI connections. They can change enabled tools within this access level without reconnecting.</p>
31
+ <div class="solidus-mcp-consent-actions">
32
+ <% {"Authorize" => :post, "Deny" => :delete}.each do |label, method| %>
33
+ <%= form_tag "#{SolidusMcp.configuration.endpoint_url}/oauth/authorize", method: method do %>
34
+ <% %i[client_id redirect_uri state response_type scope code_challenge code_challenge_method resource].each do |key| %>
35
+ <%= hidden_field_tag key, params[key], id: nil %>
36
+ <% end %>
37
+ <%= submit_tag label, class: "solidus-mcp-button#{' solidus-mcp-button-primary' if method == :post}" %>
38
+ <% end %>
39
+ <% end %>
40
+ </div>
41
+ <details class="solidus-mcp-consent-review">
42
+ <summary>Change requested access</summary>
43
+ <p>Need to use write tools? You can change the access requested for this connection. You’ll review your selection before approving.</p>
44
+ <%= form_tag "#{SolidusMcp.configuration.endpoint_url}/oauth/authorize", method: :get, id: "review-oauth-scopes" do %>
45
+ <%= hidden_field_tag :review_scopes, "1" %>
46
+ <% %i[client_id redirect_uri state response_type code_challenge code_challenge_method resource].each do |key| %>
47
+ <%= hidden_field_tag key, params[key], id: nil %>
48
+ <% end %>
49
+ <% scope_options.each do |scope| %>
50
+ <p><label class="solidus-mcp-consent-choice">
51
+ <%= check_box_tag "requested_scopes[]", scope, @pre_auth.scopes.include?(scope), id: "oauth_scope_#{scope.tr(':', '_')}" %>
52
+ <span><%= scope == "mcp:write" ? "Use enabled write tools, including tools enabled later" : "Use enabled read tools" %> (<code><%= scope %></code>)</span>
53
+ </label></p>
54
+ <% end %>
55
+ <%= submit_tag "Review access", class: "solidus-mcp-button" %>
56
+ <% end %>
57
+ <p>Read and write access are separate; select both if you need both. Individual tools must still be enabled in AI connections. If write access is not listed, the client's registration must be updated before reconnecting.</p>
58
+ </details>
59
+ </main>
60
+ </body>
61
+ </html>
data/config/routes.rb CHANGED
@@ -5,6 +5,7 @@ if defined?(SolidusAdmin::Engine)
5
5
  resources :mcp_administrators, only: [:index, :create, :update] do
6
6
  get :search, on: :collection
7
7
  end
8
+ resources :mcp_activity, only: [:index]
8
9
  resources :mcp_connections, only: [:index]
9
10
  get "mcp_connections/:id/owners/:user_id/edit", to: "mcp_connections#edit", as: :edit_mcp_connection
10
11
  patch "mcp_connections/:id/owners/:user_id", to: "mcp_connections#update", as: :mcp_connection
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSolidusMcpStockAdjustments < ActiveRecord::Migration[7.2]
4
+ def change
5
+ create_table :solidus_mcp_stock_adjustments do |t|
6
+ t.references :connection_policy, null: false, foreign_key: {to_table: :solidus_mcp_connection_policies}, index: false
7
+ t.string :idempotency_key, null: false, limit: 128
8
+ t.bigint :variant_id, null: false
9
+ t.bigint :stock_location_id, null: false
10
+ t.integer :quantity, null: false
11
+ t.string :reason, null: false, limit: 1000
12
+ t.references :stock_movement, foreign_key: {to_table: :spree_stock_movements}
13
+ t.jsonb :result
14
+ t.timestamps
15
+ end
16
+ add_index :solidus_mcp_stock_adjustments, [:connection_policy_id, :idempotency_key],
17
+ unique: true, name: "index_mcp_stock_adjustments_on_request"
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSolidusMcpToolRequests < ActiveRecord::Migration[7.2]
4
+ def change
5
+ create_table :solidus_mcp_tool_requests do |t|
6
+ t.references :connection_policy, null: false, foreign_key: {to_table: :solidus_mcp_connection_policies}, index: false
7
+ t.string :operation, null: false
8
+ t.string :idempotency_key, null: false, limit: 128
9
+ t.string :guard_key
10
+ t.jsonb :payload, null: false
11
+ t.string :status, null: false, default: "pending"
12
+ t.jsonb :result
13
+ t.timestamps
14
+ end
15
+ add_index :solidus_mcp_tool_requests, [:connection_policy_id, :operation, :idempotency_key], unique: true, name: "index_mcp_tool_requests_on_key"
16
+ add_index :solidus_mcp_tool_requests, :guard_key, unique: true,
17
+ where: "status IN ('processing', 'uncertain')", name: "index_mcp_tool_requests_on_active_target"
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSolidusMcpActivityEvents < ActiveRecord::Migration[7.2]
4
+ def change
5
+ create_table :solidus_mcp_activity_events do |t|
6
+ # Preserve attribution when OAuth clients, tokens, or users are removed.
7
+ t.bigint :user_id
8
+ t.bigint :application_id
9
+ t.bigint :token_id
10
+ t.string :application_uid
11
+ t.string :application_name
12
+ t.string :event_id, null: false
13
+ t.string :request_id
14
+ t.string :protocol_method, null: false
15
+ t.string :tool_name
16
+ t.string :permission
17
+ t.string :category
18
+ t.string :action, null: false
19
+ t.string :status, null: false, default: "started"
20
+ t.jsonb :resource_ids, null: false, default: {}
21
+ t.jsonb :changed_fields, null: false, default: []
22
+ t.datetime :started_at, null: false
23
+ t.datetime :finished_at
24
+ t.bigint :duration_ms
25
+ t.string :error_class
26
+ end
27
+ add_index :solidus_mcp_activity_events, :event_id, unique: true
28
+ add_index :solidus_mcp_activity_events, :started_at
29
+ add_index :solidus_mcp_activity_events, [:user_id, :started_at]
30
+ add_index :solidus_mcp_activity_events, [:action, :started_at]
31
+ add_index :solidus_mcp_activity_events, [:tool_name, :started_at]
32
+ add_index :solidus_mcp_activity_events, [:status, :started_at]
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddActorRoleToMcpActivityEvents < ActiveRecord::Migration[7.2]
4
+ def change
5
+ add_column :solidus_mcp_activity_events, :actor_role, :string, null: false, default: "unknown"
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusMcp
4
+ # Public SDK entry points cover schema rejection and undiscoverable tools,
5
+ # which never reach a tool's Ruby implementation.
6
+ class AuditedServer < MCP::Server
7
+ def initialize(credential:, **options)
8
+ @audit_credential = credential
9
+ super(**options)
10
+ end
11
+
12
+ def handle(payload, **options)
13
+ ActionAudit.protocol(credential: @audit_credential, payload: payload) { super }
14
+ end
15
+
16
+ def handle_json(payload, **options)
17
+ parsed = begin
18
+ JSON.parse(payload)
19
+ rescue JSON::ParserError
20
+ nil
21
+ end
22
+ ActionAudit.protocol(credential: @audit_credential, payload: parsed) { super }
23
+ end
24
+ end
25
+ end
@@ -10,15 +10,20 @@ module SolidusMcp
10
10
  end
11
11
 
12
12
  initializer "solidus_mcp.filter_credentials" do |app|
13
- app.config.filter_parameters += %i[access_token refresh_token client_secret code code_verifier authorization]
13
+ app.config.filter_parameters += %i[access_token refresh_token client_secret code code_verifier authorization data_base64]
14
+ end
15
+
16
+ initializer "solidus_mcp.stylesheets" do |app|
17
+ if app.config.respond_to?(:assets)
18
+ app.config.assets.precompile += %w[solidus_mcp/admin.css solidus_mcp/consent.css]
19
+ end
14
20
  end
15
21
 
16
22
  initializer "solidus_mcp.admin_menu" do |app|
17
23
  if defined?(SolidusAdmin::Engine)
18
- app.config.assets.precompile += %w[solidus_mcp/admin.css] if app.config.respond_to?(:assets)
19
24
  SolidusAdmin::Config.menu_items << {
20
25
  key: :mcp_connections, route: :mcp_connections_path, icon: "links-line", position: 85,
21
- match_path: ->(fullpath) { fullpath.split("?", 2).first.match?(%r{/mcp_(?:connections|administrators)(?:/|$)}) }
26
+ match_path: ->(fullpath) { fullpath.split("?", 2).first.match?(%r{/mcp_(?:connections|administrators|activity)(?:/|$)}) }
22
27
  }
23
28
  else
24
29
  Rails.autoloaders.main.ignore(root.join("app/controllers/solidus_admin"))
@@ -30,13 +30,13 @@ module SolidusMcp
30
30
  true
31
31
  end
32
32
 
33
- def authorize_record!(action, record)
34
- raise AccessDenied, "Record is unavailable" unless can?(action, record)
33
+ def authorize_record!(action, record, attribute: nil)
34
+ raise AccessDenied, "Record is unavailable" unless can?(action, record, attribute: attribute)
35
35
  record
36
36
  end
37
37
 
38
- def can?(action, record)
39
- !record.nil? && ability.can?(action, record)
38
+ def can?(action, record, attribute: nil)
39
+ !record.nil? && ability.can?(action, record, attribute)
40
40
  end
41
41
 
42
42
  def scope(model, action = :read)
@@ -4,7 +4,7 @@ module SolidusMcp
4
4
  # A catalog of explicit tools, not business resources or arbitrary methods.
5
5
  class Registry
6
6
  Entry = Struct.new(:name, :description, :category, :permission, :read_only,
7
- :abilities, :input_schema, :class_name, keyword_init: true) do
7
+ :abilities, :input_schema, :class_name, :audit_action, keyword_init: true) do
8
8
  def scopes
9
9
  [read_only ? "mcp:read" : "mcp:write"]
10
10
  end
@@ -35,11 +35,14 @@ module SolidusMcp
35
35
  raise ArgumentError, "Duplicate tool: #{name}" if tools.key?(name)
36
36
  raise ArgumentError, "Permission must be unique to this tool" if tools.values.any? { |tool| tool.permission == permission }
37
37
  raise ArgumentError, "read_only must be a boolean" unless [true, false].include?(data.fetch(:read_only))
38
+ unless %w[read create update delete].include?(data[:audit_action]) && (data[:read_only] == (data[:audit_action] == "read"))
39
+ raise ArgumentError, "Audit action must match the tool's read/write scope"
40
+ end
38
41
  %i[description category].each { |key| raise ArgumentError, "Missing #{key}" if data.fetch(key).blank? }
39
42
  raise ArgumentError, "Tool needs Solidus abilities" if data[:abilities].empty?
40
43
  MCP::Tool::InputSchema.new(data[:input_schema])
41
44
  entry = Entry.new(name: name, permission: permission, **data.slice(:description, :category,
42
- :read_only, :abilities, :input_schema, :class_name))
45
+ :read_only, :abilities, :input_schema, :class_name, :audit_action))
43
46
  entry.each_pair { |_, value| deep_freeze(value) }
44
47
  tools[name] = entry.freeze
45
48
  end
@@ -10,7 +10,6 @@ module SolidusMcp
10
10
  annotations: {read_only_hint: tool.read_only, destructive_hint: !tool.read_only,
11
11
  idempotent_hint: tool.read_only, open_world_hint: false}) do |**arguments|
12
12
  arguments.delete(:server_context)
13
- policy.authorize!(tool)
14
13
  result = tool.class_name.constantize.execute(credential: credential, **arguments)
15
14
  MCP::Tool::Response.new([{type: "text", text: result.to_json}], structured_content: result)
16
15
  rescue AccessDenied, ToolError, MCP::Tool::InputSchema::ValidationError => e
@@ -21,7 +20,7 @@ module SolidusMcp
21
20
  MCP::Tool::Response.new([{type: "text", text: e.record.errors.full_messages.to_sentence}], error: true)
22
21
  end
23
22
  end
24
- MCP::Server.new(name: SolidusMcp.configuration.server_name, version: VERSION,
23
+ AuditedServer.new(credential: credential, name: SolidusMcp.configuration.server_name, version: VERSION,
25
24
  tools: tools, instructions: SolidusMcp.configuration.instructions)
26
25
  end
27
26
  end
@@ -10,7 +10,7 @@ module SolidusMcp
10
10
  subclass.instance_variable_set(:@declaration, declaration.deep_dup)
11
11
  end
12
12
 
13
- %i[tool_name description category permission read_only].each do |key|
13
+ %i[tool_name description category permission read_only audit_action].each do |key|
14
14
  define_method(key) { |value| declaration[key] = value }
15
15
  end
16
16
 
@@ -26,18 +26,20 @@ module SolidusMcp
26
26
  end
27
27
 
28
28
  def registration
29
- declaration.deep_dup.merge(class_name: name,
29
+ declaration.deep_dup.merge(class_name: name, audit_action: declaration[:audit_action] || (declaration[:read_only] ? "read" : "update"),
30
30
  input_schema: {type: "object", properties: declaration[:properties],
31
31
  required: declaration[:required], additionalProperties: false})
32
32
  end
33
33
 
34
34
  def execute(credential:, **arguments)
35
35
  entry = SolidusMcp.registry.tools[registration.fetch(:tool_name).to_s]
36
- raise AccessDenied, "Unregistered tool" unless entry && entry.class_name == name
37
- policy = Policy.new(credential)
38
- policy.authorize!(entry)
39
- MCP::Tool::InputSchema.new(entry.input_schema).validate_arguments(arguments)
40
- new(credential, policy).send(:call, **arguments)
36
+ ActionAudit.tool(credential: credential, tool_name: registration.fetch(:tool_name).to_s, arguments: arguments) do
37
+ raise AccessDenied, "Unregistered tool" unless entry && entry.class_name == name
38
+ policy = Policy.new(credential)
39
+ policy.authorize!(entry)
40
+ MCP::Tool::InputSchema.new(entry.input_schema).validate_arguments(arguments)
41
+ new(credential, policy).send(:call, **arguments)
42
+ end
41
43
  end
42
44
 
43
45
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusMcp
4
- VERSION = "0.2.0.rc2"
4
+ VERSION = "0.2.0.rc3"
5
5
  end
data/lib/solidus_mcp.rb CHANGED
@@ -11,6 +11,7 @@ require "solidus_mcp/tool"
11
11
  require "solidus_mcp/registry"
12
12
  require "solidus_mcp/policy"
13
13
  require "solidus_mcp/connection_scopes"
14
+ require "solidus_mcp/audited_server"
14
15
  require "solidus_mcp/server"
15
16
 
16
17
  module SolidusMcp
@@ -29,7 +30,10 @@ module SolidusMcp
29
30
 
30
31
  BUILTIN_TOOLS = %w[SearchProducts GetProduct GetProductVariants GetVariantPrices
31
32
  UpdateProduct UpdateVariantPrice BulkUpdateVariantPrices GetInventoryLevels
32
- SearchInventory SearchOrders GetOrder GetOrderStatus CreateProduct].map { |name| "SolidusMcp::Tools::#{name}" }.freeze
33
+ SearchInventory SearchOrders GetOrder GetOrderStatus CreateProduct ListOptionTypes
34
+ ListOptionValues ListShippingCategories AddProductOptionType UpdateVariant ListStockLocations AdjustStock ListTaxons
35
+ AddProductToTaxon PublishProduct UnpublishProduct CreateVariantPrice
36
+ ListProductImages AttachProductImage ReorderProductImages RemoveProductImage CancelOrder ShipShipment RefundPayment].map { |name| "SolidusMcp::Tools::#{name}" }.freeze
33
37
 
34
38
  class << self
35
39
  attr_writer :registry
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_mcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.rc2
4
+ version: 0.2.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Caviness
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-09 00:00:00.000000000 Z
11
+ date: 2026-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -104,7 +104,9 @@ files:
104
104
  - LICENSE
105
105
  - README.md
106
106
  - app/assets/stylesheets/solidus_mcp/admin.css
107
+ - app/assets/stylesheets/solidus_mcp/consent.css
107
108
  - app/controllers/concerns/solidus_mcp/http_access.rb
109
+ - app/controllers/solidus_admin/mcp_activity_controller.rb
108
110
  - app/controllers/solidus_admin/mcp_administrators_controller.rb
109
111
  - app/controllers/solidus_admin/mcp_connections_controller.rb
110
112
  - app/controllers/solidus_mcp/authorizations_controller.rb
@@ -112,28 +114,56 @@ files:
112
114
  - app/controllers/solidus_mcp/metadata_controller.rb
113
115
  - app/controllers/solidus_mcp/registrations_controller.rb
114
116
  - app/controllers/solidus_mcp/tokens_controller.rb
117
+ - app/models/solidus_mcp/activity_event.rb
115
118
  - app/models/solidus_mcp/administrator.rb
116
119
  - app/models/solidus_mcp/administrator_change.rb
120
+ - app/models/solidus_mcp/audit_context.rb
117
121
  - app/models/solidus_mcp/connection_policy.rb
118
122
  - app/models/solidus_mcp/credential.rb
119
123
  - app/models/solidus_mcp/policy_change.rb
124
+ - app/models/solidus_mcp/stock_adjustment.rb
125
+ - app/models/solidus_mcp/tool_request.rb
126
+ - app/services/solidus_mcp/action_audit.rb
120
127
  - app/services/solidus_mcp/client_registration.rb
128
+ - app/services/solidus_mcp/image_context.rb
129
+ - app/services/solidus_mcp/order_workflow_authorization.rb
121
130
  - app/services/solidus_mcp/price_update.rb
122
131
  - app/services/solidus_mcp/serializers.rb
132
+ - app/services/solidus_mcp/tool_request_execution.rb
133
+ - app/tools/solidus_mcp/tools/add_product_option_type.rb
134
+ - app/tools/solidus_mcp/tools/add_product_to_taxon.rb
135
+ - app/tools/solidus_mcp/tools/adjust_stock.rb
136
+ - app/tools/solidus_mcp/tools/attach_product_image.rb
123
137
  - app/tools/solidus_mcp/tools/base.rb
124
138
  - app/tools/solidus_mcp/tools/bulk_update_variant_prices.rb
139
+ - app/tools/solidus_mcp/tools/cancel_order.rb
125
140
  - app/tools/solidus_mcp/tools/create_product.rb
141
+ - app/tools/solidus_mcp/tools/create_variant_price.rb
126
142
  - app/tools/solidus_mcp/tools/get_inventory_levels.rb
127
143
  - app/tools/solidus_mcp/tools/get_order.rb
128
144
  - app/tools/solidus_mcp/tools/get_order_status.rb
129
145
  - app/tools/solidus_mcp/tools/get_product.rb
130
146
  - app/tools/solidus_mcp/tools/get_product_variants.rb
131
147
  - app/tools/solidus_mcp/tools/get_variant_prices.rb
148
+ - app/tools/solidus_mcp/tools/list_option_types.rb
149
+ - app/tools/solidus_mcp/tools/list_option_values.rb
150
+ - app/tools/solidus_mcp/tools/list_product_images.rb
151
+ - app/tools/solidus_mcp/tools/list_shipping_categories.rb
152
+ - app/tools/solidus_mcp/tools/list_stock_locations.rb
153
+ - app/tools/solidus_mcp/tools/list_taxons.rb
154
+ - app/tools/solidus_mcp/tools/publish_product.rb
155
+ - app/tools/solidus_mcp/tools/refund_payment.rb
156
+ - app/tools/solidus_mcp/tools/remove_product_image.rb
157
+ - app/tools/solidus_mcp/tools/reorder_product_images.rb
132
158
  - app/tools/solidus_mcp/tools/search_inventory.rb
133
159
  - app/tools/solidus_mcp/tools/search_orders.rb
134
160
  - app/tools/solidus_mcp/tools/search_products.rb
161
+ - app/tools/solidus_mcp/tools/ship_shipment.rb
162
+ - app/tools/solidus_mcp/tools/unpublish_product.rb
135
163
  - app/tools/solidus_mcp/tools/update_product.rb
164
+ - app/tools/solidus_mcp/tools/update_variant.rb
136
165
  - app/tools/solidus_mcp/tools/update_variant_price.rb
166
+ - app/views/solidus_admin/mcp_activity/index.html.erb
137
167
  - app/views/solidus_admin/mcp_administrators/_account_search.html.erb
138
168
  - app/views/solidus_admin/mcp_administrators/index.html.erb
139
169
  - app/views/solidus_admin/mcp_connections/_permission_selection.html.erb
@@ -147,9 +177,14 @@ files:
147
177
  - db/migrate/20261024000000_add_solidus_mcp_oauth_attributes.rb
148
178
  - db/migrate/20261024010000_add_deleted_at_to_solidus_mcp_connection_policies.rb
149
179
  - db/migrate/20261108000000_create_solidus_mcp_administrators.rb
180
+ - db/migrate/20261112000000_create_solidus_mcp_stock_adjustments.rb
181
+ - db/migrate/20261112010000_create_solidus_mcp_tool_requests.rb
182
+ - db/migrate/20261112020000_create_solidus_mcp_activity_events.rb
183
+ - db/migrate/20261112020100_add_actor_role_to_mcp_activity_events.rb
150
184
  - docs/administration.md
151
185
  - lib/solidus_mcp.rb
152
186
  - lib/solidus_mcp/administration.rb
187
+ - lib/solidus_mcp/audited_server.rb
153
188
  - lib/solidus_mcp/configuration.rb
154
189
  - lib/solidus_mcp/connection_scopes.rb
155
190
  - lib/solidus_mcp/engine.rb