Skip to main content
Glama

advanced_calculate

Execute advanced mathematical operations such as factorial, logarithm, combinations, and permutations with precision and ease on the example-mcp-server-stdio platform.

Instructions

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

Input Schema

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

Implementation Reference

  • The main handler function for the 'advanced_calculate' tool. It processes operations like factorial, log, combinations, and permutations, validates inputs, performs calculations using helper functions, adds to history, and returns structured output. Handles errors appropriately.
    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 }, ); } }
  • Zod schemas defining the input parameters (operation, n, optional k and base) and output structure (value, expression, calculationId) for the 'advanced_calculate' tool.
    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)
    The server.registerTool call that registers the 'advanced_calculate' tool, specifying its name, title, description, input/output schemas, and handler function.
    server.registerTool( 'advanced_calculate', { title: 'Advanced Calculate', description: 'Perform advanced mathematical operations (factorial, log, combinations, permutations)', inputSchema: advancedCalculateInputSchema, outputSchema: advancedCalculateOutputSchema, }, handleAdvancedCalculate, );

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

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