Skip to main content
Glama
srafi26

MCP Server

by srafi26

calculate

Perform basic mathematical operations like addition, subtraction, multiplication, and division with two numbers to solve calculation problems.

Instructions

Perform basic mathematical calculations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesThe mathematical operation to perform
aYesFirst number
bYesSecond number

Implementation Reference

  • The execution logic for the 'calculate' tool. Validates inputs using helper functions, performs the arithmetic operation based on the 'operation' parameter, handles errors like division by zero, and returns the result.
    case 'calculate':
      const operation = validateString(args.operation, 'operation');
      const a = validateNumber(args.a, 'a');
      const b = validateNumber(args.b, 'b');
      
      let result: number;
    
      switch (operation) {
        case 'add':
          result = a + b;
          break;
        case 'subtract':
          result = a - b;
          break;
        case 'multiply':
          result = a * b;
          break;
        case 'divide':
          if (b === 0) {
            throw new Error('Division by zero is not allowed');
          }
          result = a / b;
          break;
        default:
          throw new Error(`Unknown operation: ${operation}`);
      }
    
      return {
        content: [
          {
            type: 'text',
            text: `Result: ${result}`,
          } as TextContent,
        ],
      };
  • The tool definition and input schema for 'calculate' used in tool listing (registration). Defines required parameters: operation (enum), a and b (numbers).
    {
      name: 'calculate',
      description: 'Perform basic mathematical calculations',
      inputSchema: {
        type: 'object',
        properties: {
          operation: {
            type: 'string',
            enum: ['add', 'subtract', 'multiply', 'divide'],
            description: 'The mathematical operation to perform',
          },
          a: {
            type: 'number',
            description: 'First number',
          },
          b: {
            type: 'number',
            description: 'Second number',
          },
        },
        required: ['operation', 'a', 'b'],
      },
    },
  • Helper function for input validation of numbers, used in the calculate handler.
    const validateNumber = (value: unknown, fieldName: string): number => {
      const num = Number(value);
      if (isNaN(num)) {
        throw new Error(`${fieldName} must be a valid number`);
      }
      return num;
    };
  • Helper function for input validation of strings, used in the calculate handler for operation.
    const validateString = (value: unknown, fieldName: string): string => {
      if (typeof value !== 'string') {
        throw new Error(`${fieldName} must be a string`);
      }
      return value;
    };
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 of behavioral disclosure. It states the tool performs calculations but lacks details on error handling (e.g., division by zero), performance limits, or output format. This is a significant gap for a tool with no structured safety or behavioral hints.

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 a single, efficient sentence with zero wasted words. It is appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given the tool's complexity (basic math with 3 parameters) and lack of annotations and output schema, the description is incomplete. It doesn't explain return values, error cases, or behavioral traits, leaving gaps that could hinder correct tool invocation by an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting all three parameters (operation, a, b) with enums and types. The description adds no additional meaning beyond the schema, such as explaining parameter interactions or constraints, so it meets the baseline for high schema coverage without enhancing parameter understanding.

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 'Perform basic mathematical calculations' clearly states the tool's function with a specific verb ('perform') and resource ('calculations'), distinguishing it from sibling tools like 'echo' and 'uppercase'. However, it doesn't specify the exact operations or differentiate between types of calculations beyond 'basic', which prevents a perfect score.

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 context, prerequisites, or exclusions, such as handling complex math or other tools. This leaves the agent without direction on appropriate usage scenarios.

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/srafi26/mcp-server'

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