Skip to main content
Glama
cthunter01

BC Calculator MCP Server

by cthunter01

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));
    }
Behavior3/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. It describes the tool's effect ('affects all calculations until changed again') which is useful context, but doesn't mention potential side effects, error conditions, or what happens if precision is set to extreme values. The description doesn't contradict annotations since none exist.

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 perfectly concise with two sentences that each earn their place. The first sentence states the core purpose, and the second explains the persistence effect. No wasted words or redundant information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter configuration tool with no annotations and no output schema, the description provides adequate but minimal context. It explains what the tool does and its persistence effect, but doesn't address potential limitations, error scenarios, or how this interacts with sibling calculation tools.

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 already fully documents the single 'precision' parameter with its type, range, and description. The description doesn't add any additional parameter semantics beyond what's in the schema, which meets the baseline expectation when schema coverage is complete.

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

Purpose4/5

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

The description clearly states the tool's purpose with specific verb ('Set') and resource ('default precision for subsequent calculations'). It explains what the tool does (sets decimal places for calculations) but doesn't explicitly differentiate from sibling tools like 'calculate' or 'calculate_advanced'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies when to use this tool ('for subsequent calculations') and mentions persistence ('affects all calculations until changed again'), but doesn't provide explicit guidance on when to use this versus the sibling calculation tools or any prerequisites for usage.

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

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