Skip to main content
Glama

generate_python_function

Compile verified symbolic derivations into a reusable Python function. Input verification steps, parameters, and return variables to generate executable code.

Instructions

    Generate a Python function from VERIFIED derivation steps.

    ═══════════════════════════════════════════════════════════════════════
    ⚠️ PREREQUISITE: All expressions must be verified with SymPy-MCP first!
    ═══════════════════════════════════════════════════════════════════════

    Correct workflow:
    1. Use SymPy-MCP to derive and verify each expression
    2. Use print_latex_expression() to show results to user
    3. User confirms the derivation is correct
    4. Call this tool with the verified expressions

    The generated code assembles the provided expressions into a Python
    function; it does not perform new symbolic calculations. The expressions
    must already be verified before calling this tool.

    Args:
        name: Function name (e.g., "calculate_seatbelt_tension")
        description: Function docstring description
        parameters: List of {"name": str, "type": str, "description": str}
        steps: List of {"description": str, "expression": str, "result_var": str}
        return_vars: Variables to return

    Returns:
        dict with keys ``success``, ``code`` (the generated Python function),
        ``function_name``, ``parameters``, and ``returns``.

    Example:
        generate_python_function(
            name="calculate_tension",
            description="Calculate seatbelt tension from collision",
            parameters=[
                {"name": "M1", "type": "float", "description": "Vehicle 1 mass (kg)"},
                {"name": "M2", "type": "float", "description": "Vehicle 2 mass (kg)"},
                {"name": "v", "type": "float", "description": "Initial velocity (m/s)"},
                {"name": "m", "type": "float", "description": "Person mass (kg)"},
                {"name": "k", "type": "float", "description": "Seatbelt constant (N/m)"},
            ],
            steps=[
                {"description": "Final velocity after collision",
                 "expression": "M1 * v / (M1 + M2)",
                 "result_var": "v_f"},
                {"description": "Velocity change",
                 "expression": "v - v_f",
                 "result_var": "delta_v"},
                {"description": "Maximum tension",
                 "expression": "delta_v * sqrt(m * k)",
                 "result_var": "T_max"},
            ],
            return_vars=["v_f", "delta_v", "T_max"]
        )
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
stepsYes
parametersYes
descriptionYes
return_varsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior5/5

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

No annotations provided, so description carries full burden. It discloses the tool assembles expressions into a function without performing calculations, and specifies the return structure. This provides sufficient behavioral context.

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 well-structured with sections, but slightly verbose; the example is helpful but could be trimmed. However, every part adds value.

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 and lack of annotations, the description provides a complete picture: purpose, workflow, parameters, return values, and an example. It stands alone without needing supplementary info.

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 0%, but the description adds detailed parameter definitions and a full example, significantly enhancing understanding beyond the schema titles.

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 clearly states it generates a Python function from verified derivation steps. It differentiates from siblings by emphasizing no new symbolic calculations, and the example and workflow clarify the purpose.

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?

Explicitly provides a 4-step workflow with prerequisites, warning that expressions must be verified first. It tells the agent when to call (after verification) and when not to (for new calculations, use other tools).

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/LBurny/symkit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server