Skip to main content
Glama
yigitkonur

example-mcp-server-stdio

by yigitkonur

Advanced Calculate

advanced_calculate

Perform advanced mathematical operations including factorial, logarithm, combinations, and permutations calculations for mathematical analysis and problem-solving.

Instructions

Perform advanced mathematical operations (factorial, log, combinations, permutations)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYes
nYesPrimary input
kNoSecondary input for combinations/permutations
baseNoBase for logarithm (default: e)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
valueYes
expressionYes
calculationIdYes

Implementation Reference

  • The main handler function for the 'advanced_calculate' tool. It processes operations like factorial, logarithm, combinations, and permutations. Performs validation for required parameters (e.g., k for combinations), calls helper functions, logs to history, and returns structured output with error handling.
    async function handleAdvancedCalculate({
      operation,
      n,
      k,
      base,
    }: {
      operation: 'factorial' | 'log' | 'combinations' | 'permutations';
      n: number;
      k?: number | undefined;
      base?: number | undefined;
    }) {
      log.info(`Executing advanced calculation: ${operation}`);
      requestCount++;
    
      try {
        let result: number;
        let expression: string;
    
        switch (operation) {
          case 'factorial':
            result = factorial(n);
            expression = `${n}! = ${result}`;
            break;
          case 'log':
            if (base) {
              result = Math.log(n) / Math.log(base);
              expression = `log${base}(${n}) = ${result}`;
            } else {
              result = Math.log(n);
              expression = `ln(${n}) = ${result}`;
            }
            break;
          case 'combinations':
            if (k === undefined)
              throw new McpError(
                ErrorCode.InvalidParams,
                'The parameter "k" is required for the "combinations" operation',
              );
            result = combinations(n, k);
            expression = `C(${n}, ${k}) = ${result}`;
            break;
          case 'permutations':
            if (k === undefined)
              throw new McpError(
                ErrorCode.InvalidParams,
                'The parameter "k" is required for the "permutations" operation',
              );
            result = permutations(n, k);
            expression = `P(${n}, ${k}) = ${result}`;
            break;
          default:
            throw new McpError(ErrorCode.InvalidParams, `Unknown operation: ${operation}`);
        }
    
        const historyEntry = createHistoryEntry(operation, n, k, result);
        addToHistory(historyEntry);
    
        return {
          content: [
            {
              type: 'text' as const,
              text: expression,
            },
          ],
          structuredContent: {
            value: result,
            expression,
            calculationId: historyEntry.id,
          },
        };
      } catch (error) {
        log.error(
          `Advanced calculation failed: ${error instanceof Error ? error.message : String(error)}`,
        );
        throw new McpError(
          ErrorCode.InvalidParams,
          `Advanced calculation failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
          { operation, n, k, base },
        );
      }
    }
  • Input and output schemas using Zod for the 'advanced_calculate' tool. Defines parameters: operation (enum), n (required), k/base (optional). Output includes value, expression, and calculationId.
    const advancedCalculateInputSchema = {
      operation: z.enum(['factorial', 'log', 'combinations', 'permutations']),
      n: z.number().describe('Primary input'),
      k: z.number().optional().describe('Secondary input for combinations/permutations'),
      base: z.number().optional().describe('Base for logarithm (default: e)'),
    };
    
    const advancedCalculateOutputSchema = {
      value: z.number(),
      expression: z.string(),
      calculationId: z.string(),
    };
  • src/server.ts:560-570 (registration)
    Registration of the 'advanced_calculate' tool with the MCP server inside registerExtendedTools function. Associates name, title, description, schemas, and handler.
    server.registerTool(
      'advanced_calculate',
      {
        title: 'Advanced Calculate',
        description:
          'Perform advanced mathematical operations (factorial, log, combinations, permutations)',
        inputSchema: advancedCalculateInputSchema,
        outputSchema: advancedCalculateOutputSchema,
      },
      handleAdvancedCalculate,
    );
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. While it mentions the types of operations, it doesn't describe important behavioral aspects: error handling (e.g., for invalid inputs like negative factorial), computational limits, whether operations are exact or approximate, or what the output format looks like. The description is purely functional without behavioral context.

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 extremely concise - a single sentence that efficiently lists all supported operations. Every word earns its place by specifying the tool's scope. The front-loaded structure immediately communicates the tool's purpose without unnecessary elaboration.

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?

Given that an output schema exists (per context signals), the description doesn't need to explain return values. However, for a mathematical tool with 4 parameters and no annotations, the description should ideally provide more context about operation specifics, constraints, or examples. The description is minimally adequate but leaves gaps in understanding the tool's full behavior and limitations.

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?

With 75% schema description coverage (3 of 4 parameters have descriptions), the schema already documents most parameters well. The description adds minimal value beyond the schema - it lists the operation types (which the enum already shows) but doesn't explain parameter relationships (e.g., that 'k' is only needed for combinations/permutations, or that 'base' is optional for log). Baseline 3 is appropriate given the good schema coverage.

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: 'Perform advanced mathematical operations' with specific examples (factorial, log, combinations, permutations). This distinguishes it from simpler calculation tools like 'calculate' or 'batch_calculate' by specifying 'advanced' operations. However, it doesn't explicitly differentiate from 'solve_math_problem' which might also handle similar operations.

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. With sibling tools like 'calculate', 'batch_calculate', 'solve_math_problem', and 'calculator_assistant', there's no indication of when this 'advanced' tool is preferred over those other mathematical tools. The description only lists operations without context about appropriate use cases.

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/yigitkonur/example-mcp-server-stdio'

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