Skip to main content
Glama
codewithmsunke

MCP Math Server

sqrt

Calculate the square root of a number with results rounded to two decimal places for precise mathematical computations.

Instructions

Calculate the square root of a number (rounded to two decimals)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xYes

Implementation Reference

  • The handler function that computes the square root of the input 'x' using Math.sqrt, returns an error for negative inputs, rounds the result to two decimal places, and formats the response as MCP content.
    async ({ x }) => { if (x < 0) { return { content: [ { type: "text", text: `Error: Square root of negative number is not allowed.` } ], isError: true }; } const result = Math.sqrt(x); const rounded = Math.round(result * 100) / 100; return { content: [ { type: "text", text: `The square root of ${x} is ${rounded}` } ] }; }
  • Defines the input schema for the 'sqrt' tool using Zod: expects a single number parameter 'x'. Includes title and description.
    { title: "Square Root tool", description: "Calculate the square root of a number (rounded to two decimals)", inputSchema: { x: z.number() }, },
  • src/index.ts:32-56 (registration)
    Registers the 'sqrt' tool with the MCP server, providing the tool name, schema/metadata, and handler function.
    server.registerTool( "sqrt", { title: "Square Root tool", description: "Calculate the square root of a number (rounded to two decimals)", inputSchema: { x: z.number() }, }, async ({ x }) => { if (x < 0) { return { content: [ { type: "text", text: `Error: Square root of negative number is not allowed.` } ], isError: true }; } const result = Math.sqrt(x); const rounded = Math.round(result * 100) / 100; return { content: [ { type: "text", text: `The square root of ${x} is ${rounded}` } ] }; } );

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/codewithmsunke/MCPMathTools'

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