Skip to main content
Glama
joeguo911

MCP Demo Server

by joeguo911

calculate

Perform basic mathematical operations like addition, subtraction, multiplication, and division using two numerical inputs.

Instructions

Perform basic mathematical operations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesMathematical operation to perform
xYesFirst operand
yYesSecond operand

Implementation Reference

  • demo.ts:132-188 (handler)
    The handler for the 'calculate' tool within the CallToolRequestSchema handler. It destructures the arguments, performs the specified arithmetic operation (add, subtract, multiply, divide) on x and y, handles division by zero and invalid operations, and returns a formatted result text.
    if (name === "calculate") {
      const { operation, x, y } = args as {
        operation: string;
        x: number;
        y: number;
      };
    
      let result: number;
      let operationSymbol: string;
    
      switch (operation) {
        case "add":
          result = x + y;
          operationSymbol = "+";
          break;
        case "subtract":
          result = x - y;
          operationSymbol = "-";
          break;
        case "multiply":
          result = x * y;
          operationSymbol = "×";
          break;
        case "divide":
          if (y === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: "Error: Division by zero is not allowed",
                },
              ],
            };
          }
          result = x / y;
          operationSymbol = "÷";
          break;
        default:
          return {
            content: [
              {
                type: "text",
                text: `Error: Unknown operation "${operation}"`,
              },
            ],
          };
      }
    
      return {
        content: [
          {
            type: "text",
            text: `${x} ${operationSymbol} ${y} = ${result}`,
          },
        ],
      };
    }
  • demo.ts:65-83 (schema)
    The input schema for the 'calculate' tool, defining the required parameters: operation (enum of arithmetic ops), and numbers x and y.
    inputSchema: {
      type: "object",
      properties: {
        operation: {
          type: "string",
          description: "Mathematical operation to perform",
          enum: ["add", "subtract", "multiply", "divide"],
        },
        x: {
          type: "number",
          description: "First operand",
        },
        y: {
          type: "number",
          description: "Second operand",
        },
      },
      required: ["operation", "x", "y"],
    },
  • demo.ts:62-84 (registration)
    Registration of the 'calculate' tool in the ListToolsRequestSchema handler's tools array, including its name, description, and input schema.
    {
      name: "calculate",
      description: "Perform basic mathematical operations",
      inputSchema: {
        type: "object",
        properties: {
          operation: {
            type: "string",
            description: "Mathematical operation to perform",
            enum: ["add", "subtract", "multiply", "divide"],
          },
          x: {
            type: "number",
            description: "First operand",
          },
          y: {
            type: "number",
            description: "Second operand",
          },
        },
        required: ["operation", "x", "y"],
      },
    },
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 only states 'Perform basic mathematical operations' without mentioning error handling (e.g., division by zero), output format, or any constraints like rate limits or permissions. This leaves significant gaps in understanding the tool's behavior.

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 a single, efficient sentence with no wasted words. It is front-loaded and clear in its brevity, though it could be more informative. Every word earns its place, but it might be too concise given the lack of other details.

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 complexity (a mathematical tool with 3 parameters) and no annotations or output schema, the description is incomplete. It doesn't explain what the tool returns, error conditions, or usage context, leaving the agent with insufficient information for reliable invocation.

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 input schema fully documents the parameters (operation, x, y) with descriptions and an enum for operation. The description adds no additional meaning beyond what the schema provides, such as examples or edge cases. Baseline 3 is appropriate as 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 what the tool does in general terms but is vague about scope and specifics. It mentions 'basic mathematical operations' which aligns with the name 'calculate', but doesn't specify what types of operations or distinguish it from sibling tools like 'add' (which might be a more specific operation).

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 sibling tools like 'add' or 'greet', nor does it specify contexts or exclusions for usage. The agent must infer usage solely from the tool name and parameters.

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/joeguo911/mcp-demo'

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