Skip to main content
Glama
Symbolic Algebra MCP Server

Symbolic Algebra MCP Server

substitute_expression

Substitute a variable in a symbolic expression with another expression and return a new expression key for further symbolic algebra.

Instructions

Substitutes a variable in an expression with another expression using SymPy's subs method.

Args:
    expr_key: The key of the expression to perform substitution on.
    var_name: The name of the variable to substitute.
    replacement_expr_key: The key of the expression to substitute in place of the variable.

Example:
    # Create variables x and y
    intro("x", [], [])
    intro("y", [], [])

    # Create expressions
    expr1 = introduce_expression("x**2 + y**2")
    expr2 = introduce_expression("sin(x)")

    # Substitute y with sin(x) in x^2 + y^2
    result = substitute_expression(expr1, "y", expr2)
    # Results in x^2 + sin^2(x)

Returns:
    A key for the resulting expression after substitution.

Input Schema

NameRequiredDescriptionDefault
expr_keyYes
var_nameYes
replacement_expr_keyYes

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.2/5.0
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It does disclose that the operation is non-destructive to inputs (a new key is returned) and names the underlying SymPy subs semantics, but it says nothing about error behavior for unknown keys, a variable absent from the expression, or any state/lifecycle effects on the expression registry.

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?

Front-loaded with the one-sentence purpose, then Args, then a compact runnable example, then Returns. Each block adds distinct information and the example is short enough to earn its space.

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

Completeness4/5

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

With an output schema present, the return value needn't be explained in depth, and the description still states it returns a key. Three required params are fully documented. The remaining gap is failure modes and whether expression keys persist or are consumed by the operation.

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 0% — properties carry only titles — so the Args block is the sole documentation. It correctly clarifies the important asymmetry that expr_key and replacement_expr_key are registry keys while var_name is a plain variable name, and the example reinforces that distinction concretely.

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 first sentence names a specific verb and resource — substituting a variable inside an expression via SymPy's subs — and the Args section identifies exactly which three artifacts are involved. This is clearly distinguishable from neighboring expression tools like simplify_expression, expand_expression, or introduce_expression.

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

Usage Guidelines4/5

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

The worked example demonstrates the intended call pattern: create variables with intro, build expressions with introduce_expression, then pass the resulting keys into substitute_expression. It conveys the workflow context but never states when not to use it or names an alternative for overlapping tasks.

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