Skip to main content
Glama

calculate

Compute mathematical expressions to solve calculations, from basic arithmetic to trigonometric functions, within the Slim MCP server.

Instructions

Calculate the result of a mathematical expression. Args: expression: A mathematical expression as a string (e.g. "2 + 2", "sin(30)")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'calculate' tool. It safely evaluates mathematical expressions using a restricted eval environment with math functions.
    def calculate(expression: str) -> str:
        """Calculate the result of a mathematical expression.
        Args:
            expression: A mathematical expression as a string (e.g. "2 + 2", "sin(30)")
        """
        try:
            # Replace common math functions with their python equivalents
            expression = expression.replace("^", "**")
            
            # Create a safe namespace with only math functions
            safe_dict = {
                'abs': abs, 'round': round,
                'sin': math.sin, 'cos': math.cos, 'tan': math.tan,
                'asin': math.asin, 'acos': math.acos, 'atan': math.atan,
                'sqrt': math.sqrt, 'log': math.log, 'log10': math.log10,
                'pi': math.pi, 'e': math.e
            }
            
            # Evaluate the expression in the safe namespace
            result = eval(expression, {"__builtins__": {}}, safe_dict)
            return f"Result: {result}"
        except Exception as e:
            return f"Error: {str(e)}"
  • Registers the 'calculate' tool using mcp.tool() decorator.
    def register_calculator_tools(mcp):
        """Register all calculator tools with the MCP server."""
        mcp.tool()(calculate)
  • Type hints and docstring defining the input schema for the 'calculate' tool.
    def calculate(expression: str) -> str:
        """Calculate the result of a mathematical expression.
        Args:
            expression: A mathematical expression as a string (e.g. "2 + 2", "sin(30)")
        """
Behavior2/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 states the tool calculates results but lacks details on behavioral traits: it doesn't specify error handling (e.g., for invalid expressions), performance characteristics, or output format. The description is minimal and doesn't compensate for the absence of 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 appropriately sized and front-loaded: the first sentence states the purpose clearly, followed by parameter details. It's efficient with no wasted words, though it could be slightly more structured (e.g., bullet points).

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

Completeness3/5

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

Given the tool's low complexity (1 parameter, no nested objects) and the presence of an output schema, the description is somewhat complete but has gaps. It covers the basic purpose and parameter semantics but lacks usage guidelines and behavioral transparency. The output schema likely handles return values, so that's not needed here, but overall it's minimally adequate.

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?

The description adds significant meaning beyond the input schema. The schema has 0% description coverage, so the description compensates by explaining the 'expression' parameter as 'A mathematical expression as a string' with examples like '2 + 2' and 'sin(30)'. This clarifies the expected format and usage, though it could be more detailed (e.g., supported operators).

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Calculate the result of a mathematical expression.' It specifies the verb ('calculate') and resource ('mathematical expression'), making it unambiguous. However, it doesn't differentiate from siblings (like get_current_time), which are unrelated, so it's not a perfect 5.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention any prerequisites, limitations, or comparisons to other tools (e.g., when to use calculate vs. other computational methods). This leaves the agent without context for appropriate selection.

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/webdevtodayjason/slim-MCP'

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