Get the FREE Ultimate OpenClaw Setup Guide →

MathAgent

This repository contains an MCP (Model Context Protocol) server for mathematical calculations.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio arjunkrish7356-mathagent uvx run agent.py \
  --env groq_key="Your Groq API key" \
  --env logfire_key="Your Logfire token"

How to use

MathAgent is a minimal math assistant that offloads all calculations to an MCP server. It exposes a set of math tools via the MCP interface: add, subtract, multiply, divide, power, and log. When you interact with the agent, it forwards each arithmetic request to the MCP server, which executes the corresponding tool and returns a result. This ensures calculations are consistent, auditable, and centralized through the MCP tooling chain. The agent itself acts as a thin wrapper that delegates all math work to the MCP tools, so no client-side math is performed directly by the agent.

To use MathAgent effectively, you’ll rely on the MCP tool names to perform operations: add(a, b), subtract(a, b), multiply(a, b), divide(a, b), power(base, exponent), and log(base, value). The MCP server handles input validation and error cases (e.g., division by zero) and returns the computed result. You can access these capabilities by interacting with the agent in your workflow or through any integration that speaks the MCP protocol exposed by the server described in the README. If you need modulus in the future, that tool is planned as Coming soon.

How to install

Prerequisites:

  • Python 3.13+
  • uv (Python package/dependency manager)
  • A Groq API key (for the LLM model)
  • A Logfire token (for instrumentation)

Step-by-step installation:

  1. Clone the repository git clone https://github.com/your-username/mathagent.git cd mathagent

  2. Create an environment file with required keys Create a file named .env (or environment file of your choice) and add:

    groq_key=YOUR_GROQ_API_KEY logfire_key=YOUR_LOGFIRE_TOKEN

  3. Install dependencies

    Ensure you are using Python 3.13+ and have uv installed

    pip install -r requirements.txt

  4. Run the MCP-enabled agent via uv uv run agent.py

  5. Optional: set up environment variables for your session export groq_key=YOUR_GROQ_API_KEY export logfire_key=YOUR_LOGFIRE_TOKEN

Note: The agent is configured to use the Groq model qwen/qwen3-32b (as referenced in agent.py). You can swap models as needed by editing agent.py. All calculations will route through the MCP tools defined in mcp-server.py.

Additional notes

Tips and common issues:

  • Ensure your Groq API key and Logfire token are valid and set in the environment before starting the agent.
  • The agent explicitly rejects non-math questions to enforce the MCP-driven calculation workflow.
  • If you see errors related to MCP tool availability, verify that the MCP server (fastmcp-backed) is running and exposing the add, subtract, multiply, divide, power, and log tools.
  • When updating tools or adding modulus in the future, update both the MCP server implementation and the agent's tool handling to ensure consistency.
  • If you need to run locally without uv, you can adapt the command to your environment, but using uv as documented ensures dependencies are resolved correctly.
  • Check logs (via Logfire) for instrumentation and debugging information if calculations aren’t returning expected results.

Related MCP Servers

Sponsor this space

Reach thousands of developers