Skip to main content
Glama
shaleen-wonder-ent

Simple MCP Server

calculator

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

Instructions

Perform basic mathematical operations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesThe mathematical operation to perform
aYesThe first number
bYesThe second number

Implementation Reference

  • Implements the calculator tool handler: parses input arguments using the schema, performs the specified arithmetic operation (add, subtract, multiply, divide), handles division by zero, and returns the result in the MCP response format.
    case 'calculator': {
      const parsed = CalculatorArgsSchema.parse(args);
      let result: number;
    
      switch (parsed.operation) {
        case 'add':
          result = parsed.a + parsed.b;
          break;
        case 'subtract':
          result = parsed.a - parsed.b;
          break;
        case 'multiply':
          result = parsed.a * parsed.b;
          break;
        case 'divide':
          if (parsed.b === 0) {
            throw new Error('Division by zero is not allowed');
          }
          result = parsed.a / parsed.b;
          break;
        default:
          throw new Error(`Unknown operation: ${parsed.operation}`);
      }
    
      return {
        content: [
          {
            type: 'text',
            text: `Result is from my Simple MCP Server:=> ${parsed.a} ${parsed.operation} ${parsed.b} = ${result}`,
          },
          {
            type: 'text',
            text: 'Ans is from Simple MCP Server.',
          },
        ],
      };
    }
  • Defines the Zod validation schema for the calculator tool's input: operation (enum), and two numbers a and b.
    // Schema for the calculator tool input  
    const CalculatorArgsSchema = z.object({
      operation: z.enum(['add', 'subtract', 'multiply', 'divide']).describe('The mathematical operation to perform'),
      a: z.number().describe('The first number'),
      b: z.number().describe('The second number'),
    });
  • src/index.ts:58-79 (registration)
    Registers the calculator tool in the ListTools response, providing name, description, and JSON schema mirroring the Zod schema for input validation.
      name: 'calculator',
      description: 'Perform basic mathematical operations',
      inputSchema: {
        type: 'object',
        properties: {
          operation: {
            type: 'string',
            enum: ['add', 'subtract', 'multiply', 'divide'],
            description: 'The mathematical operation to perform',
          },
          a: {
            type: 'number',
            description: 'The first number',
          },
          b: {
            type: 'number',
            description: 'The second number',
          },
        },
        required: ['operation', 'a', 'b'],
      },
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but only states the function without mentioning error handling (e.g., division by zero), performance characteristics, or output format. It lacks details on what the tool returns or any behavioral traits beyond the minimal purpose.

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 waste, front-loading the core purpose without unnecessary elaboration. It's appropriately sized for a simple tool, making it easy 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 moderate complexity (3 parameters, no output schema, no annotations), the description is incomplete. It doesn't explain return values, error cases, or behavioral context, leaving gaps that could hinder an agent's ability to use the tool effectively despite the good schema coverage.

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?

Schema description coverage is 100%, so the schema fully documents the parameters (operation, a, b). The description adds no additional meaning beyond what the schema provides, such as examples or constraints, but the baseline is 3 since the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Perform basic mathematical operations' states a general purpose but lacks specificity about what constitutes 'basic' operations or which resources are involved. It doesn't distinguish from sibling tools (current_time, echo) since they serve completely different functions, but the description remains vague about scope.

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?

No guidance is provided on when to use this tool versus alternatives or in what contexts it's appropriate. The description doesn't mention any prerequisites, limitations, or comparisons to other tools, leaving the agent with no usage instructions beyond the basic function stated.

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/shaleen-wonder-ent/simple-mcp-server'

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