Skip to main content
Glama
devashish234073

my-mcp-server

calculate

Evaluate math expressions directly using the tool on my-mcp-server. Input any valid equation like '2 + 2' to get instant results for basic calculations.

Instructions

Perform basic math calculations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYesMath expression to evaluate (e.g., '2 + 2')

Implementation Reference

  • The handler for the 'calculate' tool. It sanitizes the input math expression by removing disallowed characters, evaluates it using eval(), and returns the result or an error message in the tool response format.
    case "calculate": try { // Simple math evaluation (sanitized) const sanitized = args.expression.replace(/[^0-9+\-*/().\s]/g, ""); const result = eval(sanitized); return { content: [ { type: "text", text: `${args.expression} = ${result}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error calculating "${args.expression}": ${error.message}`, }, ], isError: true, }; }
  • server1.js:40-53 (registration)
    Registration of the 'calculate' tool in the ListToolsRequestSchema handler, including its name, description, and input schema.
    { name: "calculate", description: "Perform basic math calculations", inputSchema: { type: "object", properties: { expression: { type: "string", description: "Math expression to evaluate (e.g., '2 + 2')", }, }, required: ["expression"], }, },
  • Input schema definition for the 'calculate' tool, specifying an object with a required 'expression' string property.
    inputSchema: { type: "object", properties: { expression: { type: "string", description: "Math expression to evaluate (e.g., '2 + 2')", }, }, required: ["expression"], },

Other Tools

Related 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/devashish234073/my-mcps'

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