Skip to main content
Glama
Garoth

WolframAlpha LLM MCP Server

by Garoth

ask_llm

Query WolframAlpha to receive structured, LLM-optimized responses in multiple formats for natural language questions.

Instructions

Ask WolframAlpha a query and get LLM-optimized structured response with multiple formats

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe query to ask WolframAlpha

Implementation Reference

  • The main handler function for the 'ask_llm' tool. It invokes the WolframLLMService.query method, processes the response by trimming assumption sections and formatting the output text with query, interpretation, result, and URL.
    handler: async (args: QueryArgs): Promise<ToolResponse> => {
      const response = await wolframLLMService.query(args.query);
      if (!response.success || !response.result) {
        throw new Error(response.error || 'Failed to get LLM response from WolframAlpha');
      }
    
      // Get the raw result text
      let rawText = response.result.result;
      
      // Find the second "Assumption:" section and remove everything after it
      const lines = rawText.split('\n\n');
      const firstAssumptionIndex = lines.findIndex(line => line.startsWith('Assumption:'));
      
      let processedLines = lines;
      if (firstAssumptionIndex >= 0) {
        const secondAssumptionIndex = lines.findIndex((line, i) => 
          i > firstAssumptionIndex && line.startsWith('Assumption:')
        );
        
        if (secondAssumptionIndex > 0) {
          // Keep only the content up to the second assumption
          processedLines = lines.slice(0, secondAssumptionIndex);
          
          // Check if there's a URL section and add it back if needed
          const urlLine = lines.find(line => line.startsWith('Wolfram|Alpha website result'));
          if (urlLine && !processedLines.includes(urlLine)) {
            processedLines.push(urlLine);
          }
        }
      }
      
      // Reconstruct the text
      let text = `Query: ${response.result.query}\n`;
      if (response.result.interpretation) {
        text += `Interpretation: ${response.result.interpretation}\n`;
      }
      text += `\nResult: ${processedLines.join('\n\n')}\n`;
      
      if (response.result.url) {
        text += `\nFull results: ${response.result.url}`;
      }
    
      return {
        content: [{
          type: "text",
          text
        }]
      };
    }
  • Input schema defining the 'query' parameter as a required string for the 'ask_llm' tool.
    inputSchema: {
      type: "object",
      properties: {
        query: {
          type: "string",
          description: "The query to ask WolframAlpha"
        }
      },
      required: ["query"]
    },
  • src/index.ts:25-29 (registration)
    MCP server capabilities registration declaring 'ask_llm' as an available tool.
    tools: {
      ask_llm: true,
      get_simple_answer: true,
      validate_key: true
    },
  • Core helper method WolframLLMService.query() that performs the HTTP request to WolframAlpha LLM API and basic parsing, called by the tool handler.
    async query(input: string): Promise<LLMQueryResult> {
      try {
        // Build query URL with parameters
        const params = new URLSearchParams({
          appid: this.config.appId,
          input
        });
    
        // Make request to LLM API
        const response = await axios.get(`${this.baseUrl}?${params.toString()}`);
        
        // Store raw response for error reporting
        const rawResponse = response.data;
    
        // Log raw response for debugging
        console.log('Raw API Response:', JSON.stringify(rawResponse, null, 2));
    
        if (typeof rawResponse !== 'string') {
          console.error('Unexpected response format:', rawResponse);
          return {
            success: false,
            error: 'Invalid response format from WolframAlpha API',
            rawResponse
          };
        }
    
        const result = this.parseQueryResponse(rawResponse);
    
        return {
          success: true,
          result
        };
    
      } catch (error) {
        console.error('WolframAlpha LLM API Error:', error);
        
        // Get raw response if available
        let rawResponse: unknown;
        if (axios.isAxiosError(error) && error.response?.data) {
          rawResponse = error.response.data;
          console.error('Raw API Response:', rawResponse);
        }
    
        if (axios.isAxiosError(error) && error.response?.status === 501) {
          return {
            success: false,
            error: 'Input cannot be interpreted. Try rephrasing your query.',
            rawResponse
          };
        }
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Failed to query WolframAlpha LLM API',
          rawResponse
        };
      }
    }
  • TypeScript interface QueryArgs used by the 'ask_llm' handler for input validation.
    export interface QueryArgs {
      query: string;
    }
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. It mentions 'LLM-optimized structured response with multiple formats,' which hints at output behavior, but fails to cover critical aspects like rate limits, authentication needs, error handling, or whether it's read-only or destructive. For a tool with no annotations, this is insufficient.

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 a single, efficient sentence that front-loads key information: the action, target, and outcome. There is no wasted text, and it directly communicates the tool's core functionality without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of querying an external service (WolframAlpha) and the lack of annotations and output schema, the description is incomplete. It doesn't explain the response formats, error cases, or operational constraints, leaving significant gaps for an AI agent to understand tool behavior fully.

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?

The input schema has 100% description coverage, with the 'query' parameter clearly documented. The description adds no additional parameter semantics beyond what the schema provides, such as query format examples or constraints. With high schema coverage, the baseline is 3, as the description doesn't compensate but doesn't need to.

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: 'Ask WolframAlpha a query and get LLM-optimized structured response with multiple formats.' It specifies the action (ask), target (WolframAlpha), and outcome (structured response with multiple formats). However, it doesn't explicitly distinguish this from sibling tools like 'get_simple_answer' or 'validate_key', which would require a 5.

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. It doesn't mention sibling tools like 'get_simple_answer' or 'validate_key', nor does it specify contexts, prerequisites, or exclusions for usage. This lack of comparative guidance limits its effectiveness for an AI agent.

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

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/Garoth/wolframalpha-llm-mcp'

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