Skip to main content
Glama

Create Rule

lexq_rules_create

Create a rule in a DRAFT version. Requires name, condition tree, and actions array. priority is auto-assigned (appended last); use lexq_rules_reorder to change order.

Before creating rules with new fact keys, call lexq_facts_list to check existing facts. If a required key is missing, ask the user to confirm the type, isRequired, and description before calling lexq_facts_create — registering facts enables type validation, Console UI autocomplete, and the dry-run requirements analyzer.

After saving, lexq_facts_unregistered lists any keys this version references but has not defined (non-blocking, version-wide) — use it to decide what to register.

Condition: { type: "SINGLE", field, operator, value, valueType } or { type: "GROUP", operator: "AND"|"OR", children: [...] } Value types: STRING, NUMBER, BOOLEAN, LIST_STRING, LIST_NUMBER

Operators are constrained by the LEFT fact's type (from lexq_facts_list). Using one outside its type is rejected by the server — check the fact type before choosing an operator.

  • STRING fact: EQUALS, NOT_EQUALS, CONTAINS, IN, NOT_IN

  • NUMBER fact: EQUALS, NOT_EQUALS, GREATER_THAN, GREATER_THAN_OR_EQUAL, LESS_THAN, LESS_THAN_OR_EQUAL, IN, NOT_IN

  • BOOLEAN fact: EQUALS, NOT_EQUALS

  • LIST_* fact: HAS_ANY, HAS_ALL, HAS_NONE (only these)

HAS_* query list-typed facts. Value is always an array whose element type matches the fact:

  • HAS_ANY: fact has at least one of the given values

  • HAS_ALL: fact has all of the given values

  • HAS_NONE: fact has none of the given values Example: { "type": "SINGLE", "field": "userTags", "operator": "HAS_ANY", "value": ["VIP","GOLD"], "valueType": "LIST_STRING" }

Do NOT use CONTAINS on a list fact — CONTAINS is substring match on STRING facts only. IN is the mirror of HAS_*: IN takes a scalar fact with a list value; HAS_* takes lists on both sides.

Actions: [{ type, parameters }]

Action parameter schemas:

  • MUTATE_FACT: { targetVar: string, operator: "ASSIGN"|"ADD"|"SUB"|"MUL"|"DIV", method: "PERCENTAGE"|"AMOUNT", operand: number, refVar?: string, rounding?: RoundingOption } targetVar is the fact this action reads and writes. It must exist in facts at execution time as a number — supplied as an input fact or written by a prior action in this rule. A missing required fact throws (no 0 default). operand is the arithmetic operand; the unit is dictated by method (percent when PERCENTAGE, absolute amount when AMOUNT). Ranges are not constrained — negative values and >100 percentages are valid (refunds, surcharges). refVar is the base for percentage calculation and is OPTIONAL — omit it to use targetVar itself. It is only meaningful in PERCENTAGE × {ASSIGN, ADD, SUB}; specifying it in any other cell is an error. Use it when the base differs from the target, e.g. "points += orderTotal × 5%" → { targetVar: "points", refVar: "orderTotal", operator: "ADD", method: "PERCENTAGE", operand: 5 }. operator × method matrix: ASSIGN targetVar = operand | targetVar = refVar × operand/100 ADD targetVar += operand | targetVar += refVar × operand/100 SUB targetVar -= operand | targetVar -= refVar × operand/100 MUL targetVar *= operand | targetVar *= (operand/100 + 1) DIV targetVar /= operand | invalid Constraints: DIV + PERCENTAGE is invalid (use MUL with the inverse). DIV + AMOUNT requires operand !== 0.

  • SET_FACT: { targetVar: string, value: string|number|boolean } Creates the fact if absent — this is the only action that does. MUTATE_FACT requires the target to already exist.

  • BLOCK: { reason: string } Records a rejection decision. It does NOT halt rule execution — subsequent actions and subsequent winning rules still run. Enforcement is the caller's responsibility; the decision surfaces as the isBlocked fact.

RoundingOption (optional, MUTATE_FACT only): { scale: integer (0..34), mode?: "HALF_UP"|"HALF_DOWN"|"HALF_EVEN"|"FLOOR"|"CEILING"|"DOWN"|"UP" } mode defaults to HALF_UP. When omitted, calculator output is preserved at full precision (lossless).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ruleYesJSON string of CreateRuleRequest: { name, condition, actions, mutexGroup?, mutexMode?, mutexStrategy?, mutexLimit?, isEnabled? }
groupIdYesPolicy group ID
versionIdYesVersion ID

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changed
    • changedInput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • removedInput schema / additionalProperties
      Removed value: -false
    • addedInput schema / properties / groupId / pattern
      Added value: +"^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    • addedInput schema / properties / versionId / pattern
      Added value: +"^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
  2. Changed1 schema field changed
    • changedInput schema / properties / rule / description
      Previous value: -"JSON string of CreateRuleRequest: { name, priority, condition, actions, mutexGroup?, mutexMode?, mutexStrategy?, mutexLimit?, isEnabled? }"New value: +"JSON string of CreateRuleRequest: { name, condition, actions, mutexGroup?, mutexMode?, mutexStrategy?, mutexLimit?, isEnabled? }"
  3. First observed

TDQS

A5/5.0
Behavior5/5

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

Annotations only declare readOnlyHint=false and destructiveHint=false, leaving the description to carry the behavioral burden — and it does so richly: priority auto-assignment (appended last), server rejection of out-of-type operators, MUTATE_FACT throwing on missing facts (no 0 default), BLOCK not halting execution with enforcement left to the caller, DIV+PERCENTAGE being invalid, and rounding defaults. The description far exceeds what annotations provide and does not contradict them (readOnlyHint=false aligns with 'create').

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

Conciseness5/5

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

The description is long but each section earns its place: it front-loads the core purpose and priority behavior, then layers workflow prerequisites, condition format, operator constraints, and action schemas in a logical reading order. The operator×method matrix and the HAS_* example are high-density reference material rather than padding. Not a word is wasted — this is appropriately sized for the complexity of the rule structure it documents.

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 significant complexity (nested condition trees, typed operators, multiple action schemas, no output schema) the description is exceptionally complete. It covers workflow prerequisites (fact checks), edge cases (DIV+PERCENTAGE invalid, negative percentages and >100 valid, refVar constraints, DIV+AMOUNT operand !== 0), and the operator×method matrix exhaustively. An agent receives everything needed to construct a valid rule payload and understand failure modes, with no gap requiring inference.

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

Parameters5/5

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

Schema coverage is 100%, so baseline is 3, but the description massively exceeds the schema's value. The lone 'rule' parameter (a JSON string) receives a full specification: condition tree format (SINGLE/GROUP), value types (STRING/NUMBER/BOOLEAN/LIST_*), per-fact-type operator constraints with explicit lists, HAS_* semantics with a worked example, the operator×method matrix for MUTATE_FACT, refVar usage rules, SET_FACT creation semantics, BLOCK behavior, and RoundingOption details. This is a textbook case of description compensating for and enriching an opaque JSON-string parameter.

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+resource: 'Create a rule in a DRAFT version' and lists required components (name, condition tree, actions array). It distinguishes itself from siblings by naming lexq_rules_reorder as the alternative for priority changes, and the surrounding siblings (update, delete, toggle, get, list) are implicitly differentiable from 'create in draft.' An agent can identify this tool's role without opening the schema.

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 provides explicit workflow guidance with named alternatives: check lexq_facts_list before creating rules with new fact keys, confirm type/isRequired/description before calling lexq_facts_create, and use lexq_facts_unregistered after saving to decide what to register. It also routes priority changes to lexq_rules_reorder. This is explicit when-to-use/when-not guidance with concrete alternative tools named.

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