Skip to main content
Glama

limit

Calculate the limit of a function as it approaches a specific value to analyze mathematical behavior and continuity.

Instructions

Calculate the limit of a function as it approaches a value

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionYesFunction to evaluate limit
variableYesVariable approaching the limit
approachYesValue the variable approaches

Implementation Reference

  • The handler function passed to ai.defineTool, which destructures inputs and calls the findLimit helper.
    async ({ expression, variable, approach }) => { return findLimit(expression, variable, approach); }
  • Zod schemas defining the input parameters (expression, variable, approach) and output (number or string).
    inputSchema: z.object({ expression: z.string().describe('Function to evaluate limit'), variable: z.string().describe('Variable approaching the limit'), approach: z.number().describe('Value the variable approaches') }), outputSchema: z.union([z.number(), z.string()]),
  • index.js:324-338 (registration)
    ai.defineTool call that registers the 'limit' tool with name, description, schema, and handler function.
    ai.defineTool( { name: 'limit', description: 'Calculate the limit of a function as it approaches a value', inputSchema: z.object({ expression: z.string().describe('Function to evaluate limit'), variable: z.string().describe('Variable approaching the limit'), approach: z.number().describe('Value the variable approaches') }), outputSchema: z.union([z.number(), z.string()]), }, async ({ expression, variable, approach }) => { return findLimit(expression, variable, approach); } );
  • Supporting function that parses the math expression, evaluates it from left and right of the approach value using mathjs, averages if convergent within epsilon, else returns message or error.
    const findLimit = (expr, variable, approach) => { try { const node = math.parse(expr); const scope = {}; const epsilon = 1e-10; // Evaluate near the approach point scope[variable] = approach + epsilon; const rightLimit = math.evaluate(node, scope); scope[variable] = approach - epsilon; const leftLimit = math.evaluate(node, scope); // Check if limits from both sides are approximately equal if (Math.abs(rightLimit - leftLimit) < epsilon) { return (rightLimit + leftLimit) / 2; } return 'Limit does not exist'; } catch (e) { return `Error: ${e.message}`; } };

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