Skip to main content
Glama
nbiish
by nbiish

derivative

Calculate derivatives of mathematical expressions to solve calculus problems, analyze functions, and find rates of change in variables.

Instructions

Calculate the derivative of a mathematical expression

Input Schema

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

Implementation Reference

  • index.js:9-17 (handler)
    Core handler function that parses the mathematical expression using mathjs and computes its derivative with respect to the specified variable.
    const derivative = (expr, variable = 'x') => { try { const node = math.parse(expr); const derivativeExpr = math.derivative(node, variable); return derivativeExpr.toString(); } catch (e) { return `Error: ${e.message}`; } };
  • Defines the input schema (expression string required, variable string optional) and output schema (string) for the derivative tool.
    inputSchema: z.object({ expression: z.string().describe('Mathematical expression (e.g., "x^2", "e^x", "sin(x)")'), variable: z.string().optional().describe('Variable to differentiate with respect to (default: x)') }), outputSchema: z.string(),
  • index.js:80-93 (registration)
    Registers the 'derivative' tool with Genkit using ai.defineTool, providing name, description, schema, and a wrapper handler that delegates to the core derivative function.
    ai.defineTool( { name: 'derivative', description: 'Calculate the derivative 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 differentiate with respect to (default: x)') }), outputSchema: z.string(), }, async ({ expression, variable = 'x' }) => { return derivative(expression, variable); } );
  • Thin wrapper handler function that calls the core derivative helper with the input parameters.
    async ({ expression, variable = 'x' }) => { return derivative(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