Group Abstract Group Abstract

Message Boards Message Boards

Mathematica MCP: give your AI agent full control of your Wolfram kernel and notebooks

Built this over few weekends, an MCP server that connects AI agents (Claude, Codex etc) directly to your local Mathematica.
It lets the agent run Wolfram Language code, manipulate frontend notebooks, export plots, and query Wolfram Alpha(82 tools total). You don't even need to know every Mathematica command, as the agent can look up functions and documentation on its own. Watch it in action: https://youtu.be/TjGSkvVyc1Y

Would love for people in this community to give it a try. Your feedback would help me keep improving it.

Mathematica MCP Demo


An AI agent solving math, generating plots, and controlling a live Mathematica notebook. Errors are returned directly to the agent, no copy-pasting notebook output back into chat.


Documentation

Why This Exists

LLMs can write Mathematica code, but they can't run it, verify it, or interact with live notebooks. This MCP server bridges that gap:

  • Live notebook control: create, edit, evaluate, and screenshot Mathematica notebooks directly from your AI agent
  • Symbolic + numeric + visual in one MCP: ~82 tools covering algebra, calculus, plotting, data import/export, Wolfram Alpha, and interactive UIs
  • Agent-optimized: compact response shaping, session state tools, and computation journaling designed for how LLM agents actually work
  • Error-aware execution: Mathematica errors and warnings are returned directly to the agent, so it can debug without you manually copying notebook output back into chat
  • Local and private: core execution runs on your machine — optional tools like wolfram_alpha and repository search contact Wolfram's cloud services when invoked

Ask your agent for a derivation, a 3D plot, a notebook edit, or a verification step, and it can actually do it.


Who This Is For

enter image description here


What You Can Ask For

"Integrate x^2 sin(x) from 0 to pi, then verify the result."

execute_code("Integrate[x^2 Sin[x], {x, 0, Pi}]")  =>  -4 + Pi^2
verify_derivation(steps=["Integrate[...", "-4 + Pi^2"])  =>  All steps valid

"Plot the sombrero function in a new notebook."

create_notebook(title="Sombrero")
execute_code("Plot3D[Sinc[Sqrt[x^2+y^2]], {x,-4,4}, {y,-4,4}]", style="notebook")
=> [3D surface plot rendered in live notebook]

"Interactive: slider for Sin[n x]"

execute_code("Manipulate[Plot[Sin[n x],{x,0,2Pi}],{n,1,10}]", style="interactive")
=> [Live slider UI in Mathematica frontend]

Beyond these: data import/export (hundreds of formats), Wolfram Alpha queries, notebook reading/analysis, symbolic debugging, and more. See the Technical Reference for the full tool list.


How It Compares

enter image description here

*Core computation runs locally. Optional tools (wolfram_alpha, repository search) contact Wolfram cloud services when invoked.


Quick Start

From install to first working notebook plot in under 2 minutes.

Prerequisites

1- Mathematica 14.0+ with wolframscript in your PATH
- Download Mathematica
- macOS: Add to ~/.zshrc: export PATH="/Applications/Mathematica.app/Contents/MacOS:$PATH"

2- uv package manager

    curl -LsSf https://astral.sh/uv/install.sh | sh

One-Command Setup

# For Claude Desktop
uvx mathematica-mcp-full setup claude-desktop

# For Cursor
uvx mathematica-mcp-full setup cursor

# For VS Code (requires GitHub Copilot Chat extension)
uvx mathematica-mcp-full setup vscode

# For OpenAI Codex CLI
uvx mathematica-mcp-full setup codex

# For Google Gemini CLI
uvx mathematica-mcp-full setup gemini

# For Claude Code CLI
uvx mathematica-mcp-full setup claude-code

# Optional: select a tool profile (default is "full")
uvx mathematica-mcp-full setup claude-desktop --profile notebook

Then restart Mathematica and your editor. Done!

VS Code: Alternative setup via Command Palette

Prerequisite: GitHub Copilot Chat extension must be installed - MCP support is built into Copilot.

  1. Press Cmd+Shift+P (Mac) / Ctrl+Shift+P (Windows)
  2. Type "MCP" -> Select "MCP: Add Server"
  3. Choose "Command (stdio)": not "pip"
  4. Enter command: uvx
  5. Enter args: mathematica-mcp-full
  6. Name it: mathematica
  7. Choose scope: Workspace or User

Alternative: Interactive Installer

bash <(curl -sSL https://raw.githubusercontent.com/AbhiRawat4841/mathematica-mcp/main/install.sh)

Verify Installation

uvx mathematica-mcp-full doctor

Tip: If you encounter errors after updating, clear the cache: bash uv cache clean mathematica-mcp-full && uvx mathematica-mcp-full setup <client>


Execution Styles

Control where results appear with natural language or the style parameter:

enter image description here

If you don't include a keyword, the default depends on your tool profile.


Tool Profiles

Choose how many tools to expose:

enter image description here

Pass --profile during setup or set MATHEMATICA_PROFILE env var.


Built for Agent Workflows

The server is designed for how LLM agents actually work: long conversations with context limits, intermittent failures, and token budgets:

enter image description here

Notebook execution is strict about the requested target: if notebook transport fails, the server returns a notebook error instead of silently rerunning the work through CLI fallback.

Routing Intelligence (opt-in)

For power users, the server can learn from transport outcomes and adapt:

# Observe mode: collect stats, no behavior change
export MATHEMATICA_ROUTING_MEMORY=observe

# Advise mode: + routing hints + enables adaptive routing
export MATHEMATICA_ROUTING_MEMORY=advise
export MATHEMATICA_ROUTING_ACTION=compute_cli_skip  # optional: skip failing transport

The adaptive routing circuit-breaker automatically skips persistently failing compute CLI transport with half-open probe recovery. See the Technical Reference for details.

Privacy: Routing memory stores only aggregate counters; the in-memory journal stores short code/output previews (not persisted). Notebook extraction results are cached to ~/.cache/mathematica-mcp/notebooks/ with mtime-based invalidation; delete the directory to clear the cache.


Manual Installation

For full details, troubleshooting, and advanced configuration, see the Installation Guide.

Quick manual setup

  1. Clone & Install:

    git clone https://github.com/AbhiRawat4841/mathematica-mcp.git
    cd mathematica-mcp
    uv sync
    
  2. Install Mathematica Addon:

    wolframscript -file addon/install.wl
    

    Restart Mathematica after this step.

  3. Configure your editor: add the MCP server to your client's config file. See the Installation Guide for Claude Desktop, Cursor, VS Code, and other client configs.


License

MIT License

7 Replies

Can it be run with a local AI model on Ollama and Wolfram Engine?

POSTED BY: Antonius Paijens

Yes, partially. Wolfram Engine should work for the kernel-only parts: running Wolfram Language code, symbolic/numeric computation, Solve, Integrate, Simplify, Import, Export, etc. I’d run it with MATHEMATICA_PROFILE=math so the notebook/frontend tools are hidden. The part that won’t work with Wolfram Engine alone is live notebook control like creating notebooks, screenshots, selected-cell evaluation, and interactive UI, which need the desktop Mathematica front end.

Ollama, only runs the local model, it doesn’t know how to call MCP tools by itself. You need an app in the middle that supports both Ollama and MCP, for example the Continue extension in VS Code/JetBrains, or any MCP host that can use Ollama/OpenAI-compatible local models.

One thing to note: MCP tool-calling needs a model that is reliably good at structured tool calls. Smaller local models, especially 7B/8B-class models, may produce malformed calls or skip tools entirely. So, use them with caution.

Very cool project!

Without minimizing your work—could you compare/contrast to the official Wolfram MCP implementation? https://resources.wolframcloud.com/PacletRepository/resources/Wolfram/MCPServer/

What are the pros and cons of your implementation?

POSTED BY: Joshua Schrier

Thanks! Good question. The official Wolfram MCPServer feels to me like having a broader and more mature implementation. It is an official paclet from Wolfram, it includes built-in Wolfram tools and server configurations, and it also gives you a framework for defining your own MCP tools and connect them into clients (like Claude Code). My project is basically aimed at a somewhat different workflow and is still improving. It leans more into letting an external AI agent work with a live local Mathematica session directly, creating and evaluating cells in a real notebook window, reading outputs, taking screenshots, and using structured error/message feedback to support retry and debugging loops.

The analogy is kind of like the difference between a web browsing API that you can wire up in all sorts of ways (which is what the paclet offers), versus a browser automation tool that actually opens the browser window and interacts with the page the way a user would.

The tradeoff is that it is a community project rather than an official one. It has more moving parts because it uses a Python MCP server plus the Mathematica addon, and it is still less polished overall than the official paclet, especially around reliability and some frontend edge cases.

What a great project! Thank you for sharing it. I noticed you telling the AI in the video that there were some errors in the notebook. Cannot AI be tuned to auto-check for errors in the notebook and persist with the task until all errors resolved (because it does have access to the notebook)?

BTW here are some potentially relevant Wolfram links:

POSTED BY: Vitaliy Kaurov

Thanks!! And yeah, that demo video is from the very first version, things have come a long way since then. On the error detection question, yes, it already does this now.

Every execution returns structured error data back to the AI agent: which errors fired (like Part::partw, Power::infy), whether they're errors vs warnings, and suggested fixes. There's also a "check syntax" tool that catches broken brackets and such before running anything, and a "get messages" tool that lets the AI agent review the full error history of the session. So the loop you're describing- spot the error, figure out what went wrong, fix it, re-run, that's exactly how it works today. No special tuning needed, the AI agent just naturally persists because it gets clear feedback on what broke.

Thanks for sharing those links btw, hadn't come across those before. Will definitely check them out.

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard