Skip to main content
Glama

Teach a persistent counterparty → account rule

create_counterparty_rule
Idempotent

Creates (or updates) a persistent per-org rule mapping a counterparty to an account, then BACK-APPLIES it to every pending review event from that counterparty — each is properly approved (journal lines written, audit entry, ledger sync queued), not bulk edited. After this, future events from the counterparty auto-classify and never reach review. This is how you act on get_pending_by_counterparty: "categorise all my AWS as infrastructure" becomes one call. This WRITES financial data — only call it with an account you are confident in. The counterparty is matched on a normalised key, so "AWS, Inc." and "AWS EMEA" resolve to the same rule. Idempotent: re-running updates the single rule and re-approves nothing already approved. actor_id is optional — it defaults to the organisation entity, and if provided must belong to this org. GUARDRAIL (OOB approval): if the rule would back-apply to an unusually large set (many events, a large aggregate, or a large rolling-hour total across recent applies), it returns status "approval_required" and writes ONLY an approval request — YOU CANNOT BOOK IT YOURSELF; confirm:true does not bypass it. Your human gets an email and approves on the dashboard, at which point the action books automatically — do NOT retry the call; verify later by re-reading the books (e.g. get_pending_by_counterparty). If the response says the request was denied recently, do not re-ask for 24h. Small approvals apply immediately (status "applied").

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
org_idNoOptional. Defaults to the organisation the authenticated API key is bound to, so you normally omit it and never need to ask the user for their organisation UUID. If provided, it must match the key’s org or the request is rejected.0e91146d-511c-469f-bdee-5c867b26ae0d
reasonYesWhy this mapping is correct. Stored verbatim in the audit trail.
confirmNoDEPRECATED — no longer bypasses the guardrail. Above-guard applies always return status "approval_required" (your human approves out-of-band); re-calling with confirm:true changes nothing. Kept for wire compatibility.
actor_idNoOptional. Defaults to the organisation entity (correct for an org-scoped key). If provided, it must be an entity belonging to this organisation — arbitrary UUIDs are rejected, so the audit trail cannot be attributed to someone else.
directionNoRestrict the rule to one direction (inbound = money in, outbound = money out). Null applies it to both. Use outbound for a vendor you pay (an expense).
counterpartyYesThe counterparty name to make a rule for (e.g. "AWS"). Normalised to a key, so any variant of the same vendor matches.
approved_categoryYesThe account future and pending events from this counterparty are classified as: a numeric chart code (4000 SaaS Revenue, 4100 Usage Revenue, 4900 Other Income, 5000 API & Compute Costs, 5100 Payment Processing Fees, 5200 Platform Commission, 6100 Software Subscriptions, 6200 Contractor & Freelancer, 6300 Marketing & Ads, 6400 Banking & Finance Fees, 6500 Payroll, 6600 Taxes, 6700 Foreign Exchange Gain/Loss, 6750 Unrealized FX Gain/Loss, 6800 Office & Equipment, 6810 Travel, 6820 Meals & Entertainment, 6830 Professional Services, 6840 Insurance, 6900 Other Expenses, 2100 Accounts Payable, 3900 Owner Contributions & Transfers, 1100 Cash & Bank, 1150 Stripe Receivable, 1160 App Store / Play Receivable, 1200 Stripe Settlement) or a rollup category (revenue → 4000, cost_of_goods → 5000, operating_expense → 6100).

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
statusYes
messageNo
rule_idNo
categoryYes
currencyNo
directionYes
account_codeYes
applied_countNo
pending_countNo
approval_stateNo
counterparty_keyYes
approval_request_idNo
pending_total_centsNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond the annotations (readOnlyHint=false, idempotentHint=true, destructiveHint=false), the description discloses crucial behaviors: it back-applies to pending events with proper approvals, it matches on a normalised key, it is idempotent, and it can require out-of-band approval returning 'approval_required'. This significantly exceeds what annotations alone convey. No contradiction with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is dense but well-organized: it leads with the core behavior, then the workflow context, then the write warning, then idempotency, then the guardrail. Every sentence adds information; the only minor issue is the length and the somewhat dense guardrail paragraph, but no sentence is wasted.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity — 7 parameters, an OOB approval guardrail, idempotency, and a back-application behavior — the description covers everything an agent needs to call it correctly: what happens, what to avoid, what to do when approval_required is returned, and what the response statuses mean. The output schema is present, so return values don't need to be spelled out.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already documents every parameter. The description adds value by explaining how counterparty normalisation affects the counterparty parameter, clarifying that actor_id defaults to the organisation entity, and reinforcing the deprecated confirm parameter's non-bypass behavior. It doesn't add per-parameter detail for every field, but the schema already covers those.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Creates (or updates) a persistent per-org rule mapping a counterparty to an account, then BACK-APPLIES it to every pending review event from that counterparty.' It clearly distinguishes itself from siblings like update_counterparty_rule and get_pending_by_counterparty by explaining the back-application behavior and the workflow it belongs to.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly tells when to use this tool: 'This is how you act on get_pending_by_counterparty: "categorise all my AWS as infrastructure" becomes one call.' It also states the guardrail condition and what to do instead ('confirm:true does not bypass it... do NOT retry the call; verify later by re-reading the books'), effectively providing when-not-to-use and alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources