mathematica-mcp
This MCP server lets you run and interact with a local Wolfram Language kernel through four tools.
Evaluate Wolfram Language code in a persistent kernel, with variables/definitions surviving between calls and output/messages captured.
Export Wolfram Language results, plots, images, or data to png, svg, pdf, csv, txt, json, or tex files.
Inspect kernel status (pid, uptime, call count, detection source), restart it, or interrupt it (implemented as restart).
Look up Wolfram Language symbol information such as attributes, context, option count, and definitions.
All evaluation runs locally against a licensed Mathematica or Wolfram Engine; no cloud API or API keys are used.
Connects a locally installed Wolfram kernel (Mathematica or the free Wolfram Engine) to an MCP client, letting agents evaluate Wolfram Language code in a persistent kernel, export expressions to png/svg/pdf/csv/txt/json/tex, check or restart the kernel, and look up symbol attributes and definitions.
Provides tools for evaluating Wolfram Language code in a persistent local kernel with state preserved between calls, plus export of Graphics/Image/data to multiple file formats and symbol information lookups (attributes, context, options, definitions).
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mathematica-mcp evaluate the integral of x^2 sin(x) from 0 to pi"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mathematica-mcp
A zero-dependency MCP server that connects a locally installed Wolfram Language kernel (Mathematica or the free Wolfram Engine) to any Model Context Protocol client: Claude Desktop, Cursor, VS Code, Cline, DeepSeek Harness, or your own agent.
It starts a persistent math.exe / WolframKernel process on the same machine and exposes four tools
over stdio JSON-RPC:
Tool | What it does |
| Evaluate Wolfram Language code in a persistent kernel and return the result ( |
| Evaluate an expression and export it to png / svg / pdf / csv / txt / json / tex; returns the file path and size. |
| Report kernel status, restart it, or interrupt it (interrupt = restart). |
| Look up attributes, context, option count and definitions for Wolfram Language symbols. |
Variables and definitions survive between calls: a = 17 in one call, a + 1 in the next returns 18.
Everything runs in a local kernel process — no cloud API, no API keys, no network requests.
Runtime dependencies: none. Node.js ≥ 18 at runtime; no npm packages, no Wolfram paclet, no build step.
Transport: newline-delimited JSON-RPC 2.0 (MCP stdio); stdout carries protocol frames only, diagnostics go to stderr.
Kernel discovery: ordered candidate probing that skips unlicensed or broken installations and falls back to the next candidate.
mathematica-mcp/
├── bin/mathematica-mcp.js # executable entry point (package.json "bin")
├── src/server.js # MCP protocol, tool schemas, tool handlers
├── src/kernel.js # kernel process bridge: queue, framing, timeouts, restart
├── src/detect.js # kernel discovery + license/health probe
├── test/ # node:test suite (skips kernel tests when no kernel is installed)
├── dsh/ # DSH plugin bundle: MCP tools (vendors this server)
├── notebook/ # DSH plugin: interactive sidebar notebook (Host + browser halves)
├── market/ # DSH plugin-market index for these bundles
└── docs/ # client setup, DSH install, notebook maintainers, publishing notesPrior art (read this first)
This project is not the first Mathematica/Wolfram MCP integration, and it makes no claim to be first, only, or comprehensive. Related projects include:
WolframResearch/AgentTools — Wolfram Research's official WL paclet that runs an MCP server from inside a Wolfram kernel. Install the paclet, then point an MCP client at its server.
Zhen-WushuiLingchun/dsh-wolfram-bundle — an MIT-licensed DeepSeek Harness bundle that wraps AgentTools and exposes its tools in DSH.
hatter123/dsh-wolfram — a minimal single-tool DSH plugin that calls
wolframscript -code.
What this project adds, factually:
a standalone Node MCP stdio server that works with any MCP client, with no Wolfram paclet, no npm install and no build step on the server side (zero runtime dependencies);
persistent kernel state across tool calls, with a bridge-level timeout/restart/watchdog;
graphics and data export (png, svg, pdf, csv, txt, json, tex) as a first-class tool;
an optional DeepSeek Harness plugin bundle + plugin-market index in
dsh/andmarket/, which vendors the same server;a DeepSeek Harness sidebar notebook plugin in
notebook/: an interactive Wolfram notebook with code cells, typeset output, real.nbfiles and agent edits — with its own kernel process (see the two-kernel note).
These projects are independent; this one is not affiliated with them.
Related MCP server: Mathematica MCP Server
Requirements
A locally licensed Mathematica or a free Wolfram Engine on the same machine. There is no cloud/API fallback: if no licensed kernel is found, the tools return an actionable error.
Node.js ≥ 18 to run the server (no packages to install).
For the optional DSH bundle: a DeepSeek Harness profile that ships
@deepseek-ai/dsh-mcp-client(any standard profile does).
The server finds the kernel automatically. The first usable candidate wins; each candidate is probed
by starting it and evaluating a trivial program, so unlicensed installs
(No valid password found., exit code 69) and broken binaries are skipped:
--kernel <path>command-line argument (highest priority),MATHEMATICA_EXEorMATHEMATICA_KERNELenvironment variable,~/.mathematica-mcp.jsonwith{"kernelPath": "<path>"},well-known install locations, newest version first. On Windows, desktop
...\Wolfram\<ver>\math.exeand...\Mathematica\<ver>\math.exeare preferred over...\Wolfram Engine\<ver>\math.exe;math.exeis used rather thanMathKernel.exebecause onlymath.exeis a reliable stdio REPL.
Wolfram Engine is a first-class fallback. When Mathematica is not installed — or its kernel is unlicensed/unusable — probing continues with an activated Wolfram Engine and the MCP tools keep working with it. If a kernel that was already selected later disappears (for example Mathematica is removed or upgraded away), the cached selection is dropped and the next call re-detects candidates, so an activated Wolfram Engine can take over without restarting the MCP client. To prefer the Engine even when Mathematica is installed, point the server at it explicitly:
setx MATHEMATICA_EXE "C:\Program Files\Wolfram Research\Wolfram Engine\15.0\math.exe"Example (Windows):
setx MATHEMATICA_EXE "C:\Program Files\Wolfram Research\Wolfram\15.0\math.exe"Linux/macOS:
export MATHEMATICA_EXE="/usr/local/Wolfram/Mathematica/15.0/Executables/math"
export MATHEMATICA_EXE="/Applications/Mathematica.app/Contents/MacOS/WolframKernel"Install and run
From a git clone
git clone https://github.com/yhbcode000/mathematica-mcp.git
cd mathematica-mcp
node bin/mathematica-mcp.js --version # mathematica-mcp 0.1.1
node bin/mathematica-mcp.js --helpThe server speaks MCP on stdin/stdout and is normally started by an MCP client, not by hand.
From npm (after publication)
npx -y mathematica-mcp
# or
npm install -g mathematica-mcp
mathematica-mcp --versionThe npm package is zero-dependency;
npxonly downloads this package itself.
MCP client configuration
The server is a plain stdio MCP server. Use an absolute path to bin/mathematica-mcp.js (and an
absolute node path if your GUI client does not inherit PATH). JSON configs below use forward
slashes; on Windows both C:/... and escaped C:\\... are accepted.
Claude Desktop
claude_desktop_config.json (Settings → Developer → Edit Config):
{
"mcpServers": {
"mathematica": {
"command": "node",
"args": ["D:/tools/mathematica-mcp/bin/mathematica-mcp.js"],
"env": {
"MATHEMATICA_EXE": "C:/Program Files/Wolfram Research/Wolfram/15.0/math.exe"
}
}
}
}The env block is only needed when auto-detection does not find the kernel.
Cursor
.cursor/mcp.json in your project (or the global equivalent):
{
"mcpServers": {
"mathematica": {
"command": "node",
"args": ["D:/tools/mathematica-mcp/bin/mathematica-mcp.js"]
}
}
}Generic stdio client
Any client that launches a command and speaks newline-delimited JSON-RPC 2.0 on its stdin/stdout can use the server:
{
"command": "node",
"args": ["/opt/mathematica-mcp/bin/mathematica-mcp.js", "--kernel", "/usr/local/Wolfram/Mathematica/15.0/Executables/math"],
"cwd": "/opt/mathematica-mcp",
"env": {}
}See docs/mcp-clients.md for more client-specific notes.
DeepSeek Harness (DSH)
This repository also ships a companion DSH plugin bundle in dsh/ (dsh-mathematica-mcp).
It vendors this server and inserts the shipped @deepseek-ai/dsh-mcp-client bridge, registering
the tools as mcp__mathematica__mathematica_evaluate, mcp__mathematica__mathematica_export,
mcp__mathematica__mathematica_kernel_status and mcp__mathematica__mathematica_information.
From a local checkout (no git required):
# 1. Copy bin/ + src/ into the bundle's vendored server directory
node dsh/scripts/sync-server.mjs
# 2. Ask the agent to install the bundle, or call plugin_manager with:
# { "action": "install_bundle", "target": "<absolute path to checkout>/dsh" }From the plugin market (requires git on PATH), add the raw index URL
https://raw.githubusercontent.com/yhbcode000/mathematica-mcp/main/market/index.json in
Discover and install Mathematica MCP.
Full install and manual cordis.patch.yml instructions:
dsh/README.md and docs/dsh-install.md.
Design notes: docs/architecture.md.
Sidebar notebook plugin (DeepSeek Harness)
This repository also ships a separate DSH plugin in notebook/:
dsh-mathematica-notebook — an interactive Mathematica notebook docked in the DSH right sidebar,
next to the chat. It is independent of the MCP server above; install either or both.
Feature | Detail |
Sidebar notebook tab | Open from the right-sidebar guide (New Mathematica notebook) or by opening any |
Code cells + rich output | Run Wolfram Language cells; results render as text, typeset SVG (2D plots, formulas, tables) or a PNG image (3D graphics and raster images). |
Real | New notebooks are written immediately as valid Wolfram notebooks; saves are revision-checked so a tab and the agent cannot silently overwrite each other. |
Agent tool | List/create/read/edit/run notebooks in the same store the tab uses, e.g. "在 notebook 里加一节,导出这张图的 CSV". |
Open in Mathematica | Hands the current |
v1 limits | Code cells only; imported foreign |
Requirements are the same as the MCP server: a locally licensed Mathematica or the free Wolfram
Engine. Install it with plugin_manager install_bundle pointing at <checkout>/notebook, or from
the same plugin-market index once released. Keep the vendored kernel bridge current with
node notebook/scripts/sync-kernel.mjs.
Two kernels, not one. The notebook plugin starts and owns its own Wolfram kernel, separate
from the kernel running inside the mcp__mathematica__* MCP server process. Definitions and state do
not cross between them; each runs, times out and restarts independently, and each uses its own kernel
process memory and license seat. Move data between the two through files.
Full user guide: notebook/README.md. Maintainer notes (RPC channel, .nb
codec, revision model, native launcher, security, roadmap):
docs/notebook-plugin.md.
Tool reference
Every tool result is a single MCP content block of type text whose text is a JSON object. Tool
failures use isError: true (the MCP connection itself stays healthy).
mathematica_evaluate
Evaluate Wolfram Language code in the persistent kernel.
Parameter | Type | Default | Description |
| string (required) | — | Wolfram Language source. May be multi-line; newline-separated statements are evaluated in order. |
| number |
| Evaluation time limit. On timeout the evaluation is aborted ( |
Example call:
{ "name": "mathematica_evaluate", "arguments": { "code": "Integrate[Sin[x]^2, {x, 0, Pi}] // N" } }Example success result:
{
"ok": true,
"result": 1.5707963267948966,
"result_inputform": "1.5707963267948966`",
"output": "",
"duration_ms": 12
}Fields:
result— decoded value when the result is a plain string or number (omitted for compound expressions).result_inputform— the raw MathematicaInputFormof the result; always present.output— text printed during the evaluation (e.g.Print[...]), when any.messages— message names such asPower::infy, when messages were generated.duration_ms— wall-clock duration of the call.
A syntax error or an aborted evaluation returns isError: true with error: "evaluation_failed" /
error: "timeout", a human-readable message, and the kernel stays alive for the next call.
mathematica_export
Evaluate an expression and write its result to a file.
Parameter | Type | Default | Description |
| string (required) | — | Wolfram Language expression to export (a |
| enum (required) | — |
|
| string | timestamped file under the OS temp dir | Absolute output path (relative paths resolve against the server's CWD). Parent directories are created. |
| number | — | For png/svg/pdf: |
| number | — | For png/svg/pdf: |
| number |
| Export time limit. The first raster/vector export in a kernel session can take several seconds (rasterizer initialisation), hence the generous default. |
Example:
{ "name": "mathematica_export", "arguments": { "code": "Plot[Sin[x], {x, 0, 2 Pi}]", "format": "png", "width": 900 } }Result:
{
"ok": true,
"path": "C:\\Users\\you\\AppData\\Local\\Temp\\mathematica-mcp\\mathematica-export-20260101-120000-ab12cd.png",
"format": "png",
"width": 900,
"bytes": 74261,
"duration_ms": 4100
}Default artifact directory: %TEMP%\mathematica-mcp on Windows,
$TMPDIR/mathematica-mcp on macOS/Linux.
mathematica_kernel_status
Parameter | Type | Default | Description |
| enum |
|
|
statusreports kernel state: running/ready, pid, uptime, call count, detection source, and the candidate-probe results (tried). It never starts a kernel; before first useresolution_attemptedisfalseandcandidateslists the paths that will be probed.restartkills and respawns the kernel: all in-memory state is lost.interruptis implemented honestly as a restart — a batchmath.exeprocess cannot be reliably interrupted from another thread — and the result says so.
mathematica_information
Parameter | Type | Description |
| string[] (required) | Symbol names, e.g. |
Returns attributes, context, option count and (possibly truncated) definition for each symbol.
Example: {"symbols": ["Plot"]} returns "Attributes" -> "{HoldAll, Protected, ReadProtected}",
"Context" -> "System", "OptionsCount" -> 68, and the Options[Plot]` definition. Per-symbol
definitions are truncated at 8000 characters to keep tool responses context-friendly.
Configuration
Setting | How | Notes |
Kernel executable |
| Highest priority; wins over everything below. |
Kernel executable |
| Checked in that order. |
Kernel executable |
| Aliases |
Default evaluate timeout | tool argument | Default 60 s; max 3600 s. |
Default export timeout | tool argument | Default 180 s. |
Artifact location | tool argument | Omit to write under the OS temp dir. |
CLI options:
mathematica-mcp [--kernel <path>] [--help] [--version]There are no other environment variables and no configuration files written by the server.
How it works
The MCP server reads newline-delimited JSON-RPC frames from stdin and writes responses to stdout.
initialize,ping,tools/list,tools/call,resources/list,prompts/listare implemented; unknown methods return-32601, malformed JSON returns-32700.On first tool use the server probes kernel candidates (spawn, trivial evaluation, 20 s budget), caches the first working kernel, then starts a long-lived kernel with
-nopromptand$CharacterEncoding = "UTF-8". Before every call the cached kernel executable is checked again; if it is gone (or a start attempt fails) the cache is dropped and candidates are re-probed, so a removed Mathematica falls back to an activated Wolfram Engine without a client restart.Each evaluation is serialized through a queue (the kernel is single-threaded) and wrapped in one WL
Block[...]expression: the user program is passed as a string and evaluated withToExpression, so syntax errors become ordinary$Failedresults (plusToExpression::sntx*messages) instead of wedging the input parser. Results and messages are returned through length-prefixedWriteString[$Output, ...]frames, which is what keeps multi-line/Unicode results intact.A
TimeConstrainedlimit aborts long evaluations; a hard watchdog kills and respawns a kernel that stops responding entirely. stdout is reserved for the MCP protocol — never for kernel chatter.
Security notes
The server executes arbitrary Wolfram Language code with the privileges of the user running it. Anything the kernel can do, the MCP client can do: read and write files, run
RunProcess, make network requests, import/export files, etc. Only connect MCP clients you trust and only evaluate code you trust.Files created by
mathematica_exportare written wherever you ask (or under the OS temp directory). Treat any output path from an untrusted prompt as sensitive.The transport is stdio only. Do not expose this server over a network socket; if you need remote access, wrap it in your own authenticated transport.
Nothing is sent to Wolfram or any cloud service; all evaluation is local. Wolfram licence requirements still apply (see below).
Troubleshooting
No working Mathematica kernel was found / kernel-start errors
The error lists every candidate that was probed and the reason each failed. Point the server at a licensed executable:
setx MATHEMATICA_EXE "C:\Program Files\Wolfram Research\Wolfram\15.0\math.exe"Check it manually first:
& "C:\Program Files\Wolfram Research\Wolfram\15.0\math.exe" -noprompt
# then type: 2+2 and press Enter twiceNo valid password found. / exit code 69
That candidate is an unlicensed Wolfram Engine installation. The server skips it automatically and
tries the next candidate. Use a desktop Mathematica math.exe, or activate the Wolfram Engine licence
(free Wolfram account → Engine download page → "Activate"). Once an Engine is activated it is used
automatically whenever no licensed Mathematica kernel is available.
MathKernel.exe does not respond
Use math.exe instead — it is the documented stdio REPL launcher. The server never selects
MathKernel.exe/WolframKernel.exe on Windows for this reason.
evaluation_failed / syntax errors
The code could not be parsed (ToExpression::sntx*). This is an ordinary tool error; the kernel stays
usable. Check parentheses/brackets and retry.
timeout errors
The evaluation exceeded timeout_seconds, was aborted, and the kernel is still usable. Raise
timeout_seconds for long-running computations. An evaluation that cannot be aborted at all is killed
by a hard watchdog and the next call starts a fresh kernel (state is lost).
First PNG/PDF export is slow
The first export in a kernel session initialises the rasterizer (and may install a one-time paclet) and can take several seconds; later exports are fast. The default export timeout is 180 s.
The client reports no tools / server exits immediately
Run node bin/mathematica-mcp.js --help; check stderr (the client usually shows server logs). If node
is not on the GUI client's PATH, use an absolute node path in the command. On Windows, prefer forward
slashes in JSON paths.
A restart cleared my variables
mathematica_kernel_status {action: "restart"} (and interrupt) drop in-memory state by design;
re-run the definitions you need.
Testing
The test suite uses the built-in node:test runner and speaks raw JSON-RPC against the real server:
npm test
# or, without npm:
node --testThe suite includes protocol/JSON-RPC checks, unit tests for kernel detection, and integration tests
against a real Mathematica kernel. Kernel integration tests are skipped automatically when no kernel
is installed, so the suite is green on CI machines without Mathematica. The same node --test
auto-discovery also runs the DSH notebook plugin's tests (under notebook/test/ once the
implementation lands).
Vendored copies must stay current (CI checks both):
node dsh/scripts/sync-server.mjs --check
node notebook/scripts/sync-kernel.mjs --checkForce-skip kernel tests (for example in CI):
MATHEMATICA_MCP_TEST_SKIP_KERNEL=1 npm testTest-only environment variables:
Variable | Purpose |
| Skip all kernel integration tests. |
| Use this kernel for integration tests instead of auto-detection. |
| Also used by the tests (normal kernel configuration). |
Note: run the runner without a directory argument (node --test), or with explicit files/glob
(node --test "test/*.test.js"). On recent Node versions a bare directory argument
(node --test test/) is treated as a single test file and fails; node --test auto-discovery works on
Node 18+.
License and trademarks
MIT-licensed software; see LICENSE. Using it requires your own licensed Mathematica or free Wolfram Engine — this project does not include, redistribute or sublicense Wolfram software.
Wolfram, Mathematica, Wolfram Language and Wolfram Engine are trademarks of Wolfram Research, Inc. This project is not affiliated with or endorsed by Wolfram Research.
DeepSeek Harness and DSH are part of the DeepSeek Harness project; this project's dsh/ and
notebook/ plugins are community integrations.
Available Tools
4 toolsmathematica_evaluateEvaluate Wolfram Language codeA
Evaluate Wolfram Language (Mathematica) code in a persistent local kernel and return the result in InputForm. Variables and function definitions persist between calls. Printed output is captured in "output", and printed messages are listed in "messages". Requires a locally licensed Mathematica or the free Wolfram Engine.
Inputs: code (required), timeout_seconds.
mathematica_exportExport Mathematica graphics or data to a fileA
Evaluate Wolfram Language code and export its result to a file on the local machine. Returns the absolute path and byte size of the created file. Useful for plots (png/svg/pdf), tables/data (csv/json/txt) and LaTeX (tex).
Inputs: code (required), format (required), width, height, +2 more.
mathematica_informationLook up Wolfram Language symbol informationA
Return information about Wolfram Language symbols: attributes, context, option count and definitions (for user-defined symbols). Useful for discovering how to use a built-in function such as Plot or Table.
Inputs: symbols (required).
mathematica_kernel_statusInspect or restart the Mathematica kernelA
Report whether the local Mathematica kernel is running (pid, uptime, call count), restart it, or interrupt it. Restarting clears all in-memory state. Interrupt is implemented as a restart because a batch math.exe cannot be reliably interrupted.
Inputs: action.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool has a clearly distinct purpose: evaluating code, exporting results to files, managing/inspecting the kernel process, and querying symbol documentation. There is no overlap between execution, file output, process control, and introspection, so an agent can select unambiguously.
All tools follow a uniform `mathematica_<noun/verb>` snake_case pattern with a consistent server prefix. The verbs (evaluate, export, information) and the noun_status form read predictably and consistently.
Four tools is well-scoped for a Mathematica kernel bridge: evaluation handles nearly all computation, while export, kernel_status, and information cover the few things evaluation cannot do. Each tool earns its place with no redundancy.
The surface covers the core lifecycle: run code, persist state, write results to disk, inspect the kernel, and look up symbols. Minor gaps exist — no tool to read/import existing files back into the kernel or to cleanly shut down the kernel — but these are workable via evaluate or ignored.
Maintenance
Related MCP Connectors
Host any HTTP API as a standard MCP server; auto-distribute to 12+ mainstream agent platforms.
QuLab MCP remote server (Streamable HTTP) for computational science and lab tools.
Build and run AI workflows, agents, data tables and 1000+ API integrations from any MCP client.
MCP server for mandates, delegation, policy-gated execution, credential grants, and audit.
Related MCP Servers
- AlicenseAqualityFmaintenanceAn MCP server that connects AI assistants to a local Wolfram Engine, enabling symbolic math, numerical analysis, and data visualization through Wolfram Language. It provides secure expression filtering, client authentication, and supports both local stdio and HTTP transports.232MIT
- AlicenseBqualityDmaintenanceEnables MCP clients to execute Mathematica code via wolframscript and verify mathematical derivations.224MIT
- AlicenseAqualityDmaintenanceEnables evaluating Wolfram Language code and retrieving Wolfram Engine version/license info through an MCP interface.439 PyPI8MIT
- FlicenseNot gradedqualityCmaintenanceA local MCP server for reading, writing, and executing Jupyter notebooks using jupyter_client for direct kernel communication.-