Skip to main content
Glama

set_precision

Configure decimal precision for calculations in the BC Calculator MCP Server. Set the number of decimal places (0-100) to control rounding in all subsequent mathematical operations.

Instructions

Set the default precision (decimal places) for subsequent calculations. This affects all calculations until changed again.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
precisionYesNumber of decimal places (0-100)

Implementation Reference

  • TypeScript handler for the 'set_precision' MCP tool. Validates the precision argument (0-100), updates the globalPrecision variable used as default for calculations, and returns success response.
    async function handleSetPrecision(args: unknown): Promise<any> { // Validate arguments if (!args || typeof args !== 'object') { return { content: [{ type: 'text', text: 'Invalid arguments: expected an object' }], isError: true }; } const { precision } = args as { precision?: number }; if (precision === undefined) { return { content: [{ type: 'text', text: 'Missing required argument: precision' }], isError: true }; } // Validate precision if (precision < 0 || precision > 100) { return { content: [{ type: 'text', text: 'Invalid precision: must be between 0 and 100' }], isError: true }; } // Update global precision globalPrecision = precision; return { content: [{ type: 'text', text: JSON.stringify({ message: 'Precision updated successfully', precision: globalPrecision }, null, 2) }] }; }
  • src/ts/index.ts:89-105 (registration)
    TypeScript registration of the 'set_precision' tool in the TOOLS array, including schema definition for input validation.
    { name: 'set_precision', description: 'Set the default precision (decimal places) for subsequent calculations. ' + 'This affects all calculations until changed again.', inputSchema: { type: 'object', properties: { precision: { type: 'number', description: 'Number of decimal places (0-100)', minimum: 0, maximum: 100 } }, required: ['precision'] } }
  • Python handler for the 'set_precision' MCP tool. Validates the precision argument (0-100), updates the global_precision variable used as default for calculations, and returns success response.
    async def handle_set_precision(args: dict[str, Any]) -> list[TextContent]: """Handle precision setting requests""" global global_precision precision = args.get("precision") if precision is None: return [TextContent( type="text", text="Missing required argument: precision" )] # Validate precision if precision < 0 or precision > 100: return [TextContent( type="text", text="Invalid precision: must be between 0 and 100" )] # Update global precision global_precision = precision return [TextContent( type="text", text=json.dumps({ "message": "Precision updated successfully", "precision": global_precision }, indent=2) )]
  • Python registration of the 'set_precision' tool in the list_tools() function, including schema definition for input validation.
    Tool( name="set_precision", description=( "Set the default precision (decimal places) for subsequent calculations. " "This affects all calculations until changed again." ), inputSchema={ "type": "object", "properties": { "precision": { "type": "number", "description": "Number of decimal places (0-100)", "minimum": 0, "maximum": 100 } }, "required": ["precision"] } )
  • TypeScript helper method in BCProcess class that sends 'scale={scale}' command to the underlying BC process stdin to set decimal precision.
    async setPrecision(scale: number): Promise<void> { // Validate scale if (scale < 0 || scale > 100) { throw new BCCalculatorError( `Invalid precision: ${scale}. Must be between 0 and 100`, BCErrorCode.VALIDATION_ERROR ); } if (!this.process || !this.process.stdin) { throw new BCCalculatorError( 'BC process not ready', BCErrorCode.BC_NOT_READY ); } // Set scale directly - BC's scale assignment produces no output // so we write directly instead of using evaluate() this.process.stdin.write(`scale=${scale}\n`); this.currentPrecision = scale; // Give BC a moment to process the scale command await new Promise(resolve => setTimeout(resolve, 50)); }

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/cthunter01/MCPCalculator'

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