Skip to main content
Glama

integral

Calculate indefinite integrals of mathematical expressions like x^2, e^x, or sin(x) with respect to a specified variable. This tool performs symbolic calculus for integration problems.

Instructions

Calculate the indefinite integral of a mathematical expression

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYesMathematical expression (e.g., "x^2", "e^x", "sin(x)")
variableNoVariable to integrate with respect to (default: x)

Implementation Reference

  • index.js:19-41 (handler)
    Core implementation of the integral computation logic, handling basic polynomials and predefined integration rules for common functions.
    const integral = (expr, variable = 'x') => { try { // For basic polynomials const powerMatch = expr.match(new RegExp(`${variable}\\^(\\d+)`)); if (powerMatch) { const n = parseInt(powerMatch[1]); return `${variable}^${n + 1}/${n + 1}`; } // For basic functions const rules = { 'e^x': 'e^x', '1/x': `ln|${variable}|`, [`sin(${variable})`]: `-cos(${variable})`, [`cos(${variable})`]: `sin(${variable})`, 'x': 'x^2/2' }; return rules[expr] || 'Cannot compute integral'; } catch (e) { return `Error: ${e.message}`; } };
  • Tool schema definition including input parameters (expression and optional variable) and string output schema.
    name: 'integral', description: 'Calculate the indefinite integral of a mathematical expression', inputSchema: z.object({ expression: z.string().describe('Mathematical expression (e.g., "x^2", "e^x", "sin(x)")'), variable: z.string().optional().describe('Variable to integrate with respect to (default: x)') }), outputSchema: z.string(), },
  • index.js:95-108 (registration)
    Registration of the 'integral' tool with Genkit's ai.defineTool, linking schema to the handler wrapper that invokes the core integral function.
    ai.defineTool( { name: 'integral', description: 'Calculate the indefinite integral of a mathematical expression', inputSchema: z.object({ expression: z.string().describe('Mathematical expression (e.g., "x^2", "e^x", "sin(x)")'), variable: z.string().optional().describe('Variable to integrate with respect to (default: x)') }), outputSchema: z.string(), }, async ({ expression, variable = 'x' }) => { return integral(expression, variable); } );

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/nbiish/mcp-calc-tools'

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