Add basic update tool (respecting ActiveAdmin form + authorization) - #3
Merged
Conversation
Adds a basic `update` MCP tool that modifies a single record, enforcing the same rules as the ActiveAdmin UI: - editable resources only (resource must expose the :update action) - authorization via the namespace's authorization adapter for the authenticated MCP user - only fields the resource's permit_params allows are written, driven through ActiveAdmin's own permitted_params Also threads the current MCP user through RequestHandler and exposes the ActiveAdmin resource config from ResourceRegistry.find so the updater can inspect actions/authorization. Specs added for RecordUpdater and the update tool; existing specs updated for the new tools/list entry and ResourceRegistry.find contract. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lloydwatkin
force-pushed
the
add-edit-to-gem
branch
from
August 14, 2026 15:15
b60bddf to
f9d79a2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a basic
updateMCP tool — the first write operation — that modifies a single record while enforcing the same three rules as the ActiveAdmin UI::updateaction (resource.defined_actions). Resources registeredactions :index, :showstay read-only.adapter.new(config, current_user).authorized?(:update, record)), so CanCanCan/Pundit rules apply for the authenticated MCP user.permit_paramsby driving ActiveAdmin's ownpermitted_params, so only fields the admin form accepts are written. Anything else is dropped (fails closed if permit params can't be resolved).Validation failures return the record's
full_messages; unknown resource / missing record / missing args return clear errors.Usage
Changes
lib/active_admin_mcp/record_updater.rb(new) — the gating + update logiclib/active_admin_mcp/request_handler.rb— newupdatetool schema + dispatch; threadscurrent_userin via the constructorlib/active_admin_mcp/resource_registry.rb—findnow also returns the ActiveAdmin resourceconfigso the updater can inspect actions/authorizationapp/controllers/active_admin_mcp/mcp_controller.rb— passescurrent_mcp_userto the handlerREADME.md— documents the tool and its rulesTests
59 examples, 0 failures.
record_updater_spec.rb(8 examples) covering each gate, validation failures, permitted-field filtering, and anerror-named-attribute regressionrequest_handler_spec.rb—tools/listnow includesupdate, plus dispatch coverage; updatedresource_registry_spec.rbfor the newfindcontractNote — stacked on #2
This branch is built on top of the RSpec suite from #2, so the diff currently also includes those spec-infrastructure commits. Once #2 is merged to
main, this diff will reduce to just theupdatefeature. Please merge #2 first.Follow-up
The permit-params path is unit-tested against a controller double, not a live ActiveAdmin controller (booting a full AA dummy app is a larger lift and needs its own harness). A dummy-app-backed integration spec for
permitted_paramsand the end-to-end update flow is a sensible follow-up before relying on this in production.🤖 Generated with Claude Code