Skip to main content
Glama

add_numeric_expression

Create a Numeric Expression — Settings > Assignment & Formulas > Numeric Expressions > Create Expression in the builder. A Numeric Expression is a named, computed number built from question scores (and, optionally, other already-created expressions) combined with +, -, *, / and parenthesized grouping, given here as a structured terms list instead of free text; ordinary arithmetic precedence applies (* and / bind tighter than + and - unless grouped). Example: total = 20 + Q1 - Q6 is terms: [{value:20}, {questionId, operator:"+"}, {questionId, operator:"-"}]; and ratio = trait-score / Q3 * 100 (using an earlier expression) is [{expressionId}, {questionId, operator:"/"}, {value:100, operator:"*"}]. Each term is exactly one of a question (questionId/position), another expression (expressionId/expressionLabel — must already be defined EARLIER in the survey's expression list; a forward reference is refused with a clear error), a literal number (value), or a parenthesized sub-formula (group, itself an array of terms — use this when precedence needs forcing, e.g. (a + b) / c). Unanswered questions count as 0, and a divide-by-zero result is displayed as 0, as in the builder. Optionally add conditional overrides via conditions: each is an "IF when conditions match, THEN use thenTerms instead of the base formula" rule (same condition shape as add_display_logic's). If none of the conditions match for a given respondent, the base terms formula is used as the fallback, so it is still meaningful when conditions are present. recalculateFlag (default false) mirrors the builder's "Recalculate expression on the results screen" checkbox; executeOncePerResponse (default false) mirrors "Evaluate once and fix result" (freezes the value after the first successful computation instead of recomputing on every later answer). The response includes recallToken ({{exp:<id>}}) for later use — ONLY if the user separately asks to display this score somewhere (e.g. "show the total score on the thank you screen"), paste that exact string into update_question's label/description or update_thankyou_screen's title/description. Do not insert it anywhere on your own initiative just because the expression was created — creating the formula and displaying it are separate asks. Refused for the reserved built-in names (e.g. "score"), for "price" (already exists on every survey — use update_numeric_expression with expressionId: "price" instead), and for any name already used by another expression or a Text Variable.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "surveyId": "<surveyId>",
      "label": "<label>",
      "terms": "<terms>"
    },
    "name": "add_numeric_expression"
  }
}

Input Schema

NameRequiredDescriptionDefault
labelYesThe expression's name (letters, numbers, "-", "_" only, no spaces) — e.g. "total_score". This is how it's identified afterward and shown in the builder's recall list.
termsYesThe formula's terms, applied in order — see the tool description for the term shapes and how operators/precedence work.
teamIdNoWhich team workspace to act in (ids come from get_account_info or list_surveys). Optional: if omitted, the server uses the team that owns the given surveyId, or your only team. Required for create_survey when you belong to several teams.
surveyIdYesThe Survey ID to add the expression to
conditionsNoOptional conditional overrides — see the tool description.
recalculateFlagNoRecalculate this expression live on the results screen. Defaults to false.
executeOncePerResponseNoFreeze the computed value after the first time it's set for a given response, instead of recomputing on every later answer. Defaults to false.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.4/5.0
Behavior3/5

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

With annotations present (readOnlyHint=false, destructiveHint=false, idempotentHint=false, openWorldHint=true) the bar is lower, and the description adds genuine runtime semantics the annotations cannot convey: unanswered questions count as 0, divide-by-zero renders as 0, forward references and duplicate/reserved names are rejected with clear errors, and conditions fall back to base terms when nothing matches. It does not restate or contradict the safety profile, and it does not mention that repeat calls create additional expressions despite idempotentHint=false, but that gap is minor.

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 long but front-loaded: the action, the definition, then term shapes with examples, then conditions, then the recallToken caveat, then the refusal list. Most sentences earn their place given nested terms and conditions arrays. There is some redundancy — operator precedence is stated twice within the description and again in the schema, and the formula-box mirroring is mentioned repeatedly — but nothing is padded filler.

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?

For a tool with 7 parameters, recursive term objects, and no output schema, the description covers everything an agent needs: term variants and exclusivity, precedence and grouping, condition override semantics with fallback, both flag behaviors, refusal conditions, and what the response returns (recallToken) and how to use it. Nothing material is left to inference.

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 already 100%, so the baseline is 3; the description still earns extra credit by supplying worked examples that map a free-text formula (`total = 20 + Q1 - Q6`) onto the structured `terms` array and by explaining when to use `group` to force precedence. It also clarifies the fallback meaning of base `terms` when `conditions` are present and that `executeOncePerResponse` freezes the value after first computation — neither of which is in the schema. Precedence itself is repeated from the schema, which keeps this from a 5.

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?

Opens with a specific verb+resource ("Create a Numeric Expression") and anchors it to the exact builder location, then defines what the object is (a named computed number from question scores with arithmetic operators). It is clearly distinguishable from update_numeric_expression, get_numeric_expression and delete_numeric_expression by name and by the explicit note that "price" must go through update_numeric_expression instead.

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?

States when-and-when-not explicitly: use update_numeric_expression with expressionId "price" instead of creating, forward references to later expressions are refused, reserved names are refused, and the recallToken should only be pasted when the user separately asks to display the score. It even warns against proactively inserting the token, which removes the main failure mode for this tool.

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