#3819·sure

MCP: rule tools with a mandatory preview (get/preview/create/update/apply)

Author: scragnogCreated Sep 28, 2026Updated Sep 28, 2026

Problem

MCP clients can find transactions and edit them one at a time (update_transaction, and match_transfer in #3818), but they can't see or manage rules. The REST API can only read rules (GET /api/v1/rules, /rule_runs). So an assistant that has just worked out "every payment named 57001806593401 from this account is a loan repayment" can't turn that into a rule. It has to walk the user through Settings → Rules instead.

The risk is also real. A rule applies to every matching transaction, and an active rule runs again on every family sync (Family::Syncer). A small slip, such as greater than 300 instead of equal to 300, silently rewrites transactions and keeps doing so. I hit exactly that while setting up loan overpayment rules. So a rules tool needs a preview step, more than most write tools do.

Proposal

Five tools on top of the existing Rule model and registry (Rule#affected_resource_count, #matching_transaction_ids, #apply_later, RuleRun):

Tool Read/write What it does
get_rules read Rules with conditions and actions in readable form (account, category and tag ids resolved to names), active, effective_date, and the latest RuleRun summary.
get_rule_options read The condition types, operators and action types the registry supports, with valid values. Rule::ConditionFilter#as_json and Rule::ActionExecutor#as_json already describe these, so a client can build a valid rule without guessing.
preview_rule read For a saved rule_id or an unsaved rule definition: the number of matching transactions and a sample of them (id, date, account, name, amount), plus what each action would change.
create_rule / update_rule write Saves a rule definition, validated through the registry. Always saved inactive. Returns the same preview as preview_rule.
apply_rule write Activates a rule and applies it to existing transactions, like the UI's Apply. It requires expected_count from a preview and refuses if the current match count differs, so a stale preview can't be applied.

Safety defaults:

  • The only way to activate a rule is apply_rule, after a preview. create_rule can't make an active rule.
  • Actions that call an AI model (auto_categorize, auto_detect_merchants) aren't allowed through MCP at first. They cost money, and the UI shows a cost estimate before applying them. They could come later, with an estimate included in the preview.
  • The same family and account-permission rules as the web UI apply. get_rules, get_rule_options and preview_rule would declare themselves read-only for the scopes proposed in #3580.
  • No delete_rule in the first version: update_rule with active: false is enough and can be undone.

Questions for maintainers

  1. Is there appetite for rule-writing tools over MCP at all, or should MCP stay read-only for rules (get_rules + preview_rule)?
  2. Always available, or preview-gated (like record_valuation) for a first release?
  3. Is refusing AI-backed actions the right default?

I'm happy to build this once the direction is agreed. It follows #3818, which adds transfer matching.