home / mcp / mathematica mcp server

Mathematica MCP Server

Provides a Model Context Protocol server to execute Wolfram Language code in a secure, session-based environment.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "aac6fef-mathematica_mcp": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/your/project/my_mcp",
        "run",
        "wolfram_mathematica.py"
      ],
      "env": {
        "ANIMALID_SECRET_KEY": "default-secret-key-for-dev"
      }
    }
  }
}

You can run Wolfram Language code from an MCP-compatible client through a secure, session-based Mathematica engine. This server lets you initialize sessions, execute code within those sessions, and cleanly terminate them, enabling LLMs to perform complex computations and return results safely.

How to use

Connect to the Mathematica MCP server from your MCP client by configuring the client to launch the local MCP endpoint. You will first start a Mathematica session, then send Wolfram Language code to be executed in that session, and finally close the session when you are done. The server manages one or more sessions and returns results for each execution.

Key capabilities include creating a new Mathematica session and receiving a session ID, running Wolfram Language snippets within a chosen session, and terminating sessions to release resources. Use these capabilities in sequence to perform computations that require a persistent kernel state.

How to install

# Prerequisites
python3 --version
uv --version
wolframclient --version 2>/dev/null || echo "Install wolframclient as needed"

# Environment setup
export ANIMALID_SECRET_KEY='your-super-secret-and-long-key-here'

# Reveal how to run the MCP server from a client environment
# This project expects you to configure a local MCP client to point at the following stdio-based server

Set up the MCP client configuration to connect to the local server by including a stdio MCP entry that launches the UVX runner with the Mathematica script. Ensure you replace the path to your project appropriately.

Configuration and security

Security is enforced by using a secret key to generate secure session IDs. You must set this as an environment variable before starting the server. This key should be kept confidential and never embedded in code or shared in insecure ways.

Environment variable to set on your system before launching the MCP client-configured server: export ANIMALID_SECRET_KEY='your-super-secret-and-long-key-here'

Example client configuration (for the MCP client) includes the stdio-based command that runs the Mathematica MCP server locally. Use the path to your project directory to enable the server to locate its script.

Notes and troubleshooting

If you encounter issues starting the session, verify that the secret key is exported in the environment where the MCP client launches the server. Check that the UV runner and the Mathematica tooling are installed and accessible from the shell where you initiate the MCP connection.

When testing, ensure the Wolfram Engine or Mathematica is installed locally, and that the Python environment has the wolframclient library available.

Available tools

create_mathematica_session

Initializes a new Wolfram Language session and returns a unique session ID.

execute_mathematica_code

Executes Wolfram Language code within a specified session.

close_mathematica_session

Terminates a session and releases its resources.

Mathematica MCP Server - aac6fef/mathematica_mcp