Skip to main content
Glama
nykznykz

Example MCP Server

by nykznykz

calculate

Evaluate mathematical expressions safely to get calculation results. Use this tool to perform basic arithmetic operations like addition, multiplication, and division.

Instructions

Evaluate a mathematical expression safely.

Args: expression: A mathematical expression to evaluate (e.g., "2 + 2", "10 * 5")

Returns: The result of the calculation as a string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler function for the 'calculate' MCP tool, registered with the @mcp.tool() decorator. It delegates execution to the internal _calculate helper.
    @mcp.tool()
    def calculate(expression: str) -> str:
        """
        Evaluate a mathematical expression safely.
    
        Args:
            expression: A mathematical expression to evaluate (e.g., "2 + 2", "10 * 5")
    
        Returns:
            The result of the calculation as a string
        """
        return _calculate(expression)
  • Internal helper function implementing the core logic of the calculate tool, performing safe evaluation of mathematical expressions with character validation and error handling.
    def _calculate(expression: str) -> str:
        """
        Evaluate a mathematical expression safely.
    
        Args:
            expression: A mathematical expression to evaluate (e.g., "2 + 2", "10 * 5")
    
        Returns:
            The result of the calculation as a string
        """
        try:
            # Simple evaluation for basic math operations
            # In production, you'd want a more secure math parser
            allowed_chars = set("0123456789+-*/.() ")
            if not all(c in allowed_chars for c in expression):
                return f"Error: Invalid characters in expression '{expression}'"
    
            result = eval(expression)
            return f"The result of '{expression}' is {result}"
        except Exception as e:
            return f"Error calculating '{expression}': {str(e)}"
  • Pydantic model defining the input schema for the calculate tool, specifying the 'expression' parameter.
    class CalculateRequest(BaseModel):
        """Request model for calculate tool."""
    
        expression: str
  • The @mcp.tool() decorator registers the 'calculate' function as an MCP tool.
    @mcp.tool()
Behavior4/5

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

With no annotations provided, the description carries the full burden. It discloses the key behavioral trait of 'safely' evaluating expressions, which suggests error handling or security considerations. However, it doesn't detail specific safety mechanisms, rate limits, or authentication needs.

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 appropriately sized and front-loaded: the first sentence states the core purpose, followed by clear sections for Args and Returns. Every sentence adds value without redundancy, making it efficient and well-structured.

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?

Given the tool's low complexity, no annotations, and the presence of an output schema (which covers return values), the description is mostly complete. It explains the purpose, parameter, and return behavior, though it could add more on safety specifics or error cases.

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?

The schema description coverage is 0%, so the description must compensate fully. It adds significant meaning beyond the schema by explaining that 'expression' is a mathematical expression and providing concrete examples ('2 + 2', '10 * 5'), which clarifies the expected format and usage.

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 the tool's purpose with a specific verb ('evaluate') and resource ('mathematical expression'), plus the qualifier 'safely' distinguishes it from generic calculation tools. It explicitly tells what the tool does without restating the name.

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

Usage Guidelines3/5

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

The description implies usage through the example expressions provided, but doesn't explicitly state when to use this tool versus alternatives. With only one sibling tool ('greet') that's unrelated, there's no need for sibling differentiation, but no explicit guidance on context or exclusions is given.

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/nykznykz/mcp_example'

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