Mathematica MCP Server
Enables MCP clients to execute Mathematica code via wolframscript and verify mathematical derivations.
README
Mathematica MCP Server
This repository contains a Model Context Protocol (MCP) server that allows MCP clients (like Cursor) to execute Mathematica code via wolframscript and verify mathematical derivations.
Overview
This server acts as a bridge, enabling applications that support MCP to leverage the power of a local Mathematica installation for tasks such as:
- Performing complex mathematical calculations.
- Verifying mathematical derivation steps provided by humans or AI models.
- Generating LaTeX or Mathematica string representations of expressions.
Prerequisites
- Mathematica must be installed on your system.
- The
wolframscriptcommand-line utility must be available in your system's PATH. You can test this by runningwolframscript -helpin your terminal. - Node.js (Recommended: v16 or later, as inferred from
tsconfig.jsontargetES2022).
Installation
- Clone the repository:
git clone <repository-url> cd <repository-directory> - Install dependencies:
npm install - Build the server:
This command compiles the TypeScript source code fromnpm run buildsrc/into JavaScript in thebuild/directory and makes the main script executable.
Running the Server
To start the MCP server, run the following command in your terminal:
node build/index.js
The server will start and listen for connections from MCP clients via standard input/output (stdio). Keep this terminal window open while you intend to use the server.
For more robust deployments, consider using a process manager like pm2 to run the server in the background and manage restarts.
Integration with MCP Clients (e.g., Cursor, Cline, Claude Desktop)
MCP clients generally discover and communicate with running MCP servers. The exact configuration steps can vary depending on the client application.
General Steps:
- Start the Mathematica MCP Server: Ensure the server is running in a terminal:
node build/index.js - Configure Your MCP Client: Add the server to your client's configuration. This often involves editing a JSON settings file. See client-specific instructions below.
- Restart Your MCP Client: After starting the server or changing configuration, restart your client application to ensure it detects the Mathematica server.
Client-Specific Configuration:
-
Cline: According to the Cline MCP Server Development Protocol, you typically configure servers in a settings file (often
settings.jsonwithin the Cline configuration directory). You would add an entry like this:{ "mcpServers": { "mathematica-server": { "command": "node", "args": ["/full/path/to/mcp-server-mathematica/build/index.js"], // Replace with the actual absolute path "disabled": false, "autoApprove": [] // Optional: Add tool names to auto-approve } // ... other servers ... } }Replace
/full/path/to/mcp-server-mathematica/build/index.jswith the absolute path to the builtindex.jsfile on your system. -
Cursor: Cursor might require editing a specific settings file, potentially like
~/Library/Application Support/Cursor/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json(though this path might change). The structure would be similar to the Cline example above. -
Other Clients (e.g., Claude Desktop): Consult the documentation for your specific MCP client. Look for sections on "MCP Servers," "Tool Configuration," or "External Tools." The configuration generally involves specifying the command (
node), the path to the server script (build/index.js), and potentially environment variables if needed.
Available Tools
The server exposes the following tools to MCP clients:
1. execute_mathematica
Executes arbitrary Mathematica code and returns the result.
Input Schema:
{
type: "object",
properties: {
code: {
type: "string",
description: "Mathematica code to execute"
},
format: {
type: "string",
description: "Output format (text, latex, or mathematica)",
enum: ["text", "latex", "mathematica"],
default: "text"
}
},
required: ["code"]
}
Example Usage (Client Request):
- Natural Language: "Calculate the integral of x^2 from 0 to 1 using Mathematica and format as LaTeX"
- Direct Tool Call:
{ "tool_name": "execute_mathematica", "arguments": { "code": "Integrate[x^2, {x, 0, 1}]", "format": "latex" } }
2. verify_derivation
Verifies a sequence of mathematical expressions to check if each step logically follows from the previous one using Simplify[prev == current].
Input Schema:
{
type: "object",
properties: {
steps: {
type: "array",
description: "Array of mathematical expressions (as strings) representing steps in a derivation. Requires at least two steps.",
items: {
type: "string"
}
},
format: {
type: "string",
description: "Output format for the verification report (text, latex, or mathematica)",
enum: ["text", "latex", "mathematica"],
default: "text"
}
},
required: ["steps"]
}
Example Usage (Client Request):
- Natural Language: "Verify this derivation: ['x^2 - y^2', '(x-y)(x+y)']"
- Direct Tool Call:
{ "tool_name": "verify_derivation", "arguments": { "steps": [ "x^2 - y^2", "(x-y)*(x+y)" ], "format": "text" } }
Troubleshooting
- Server Not Found/Not Responding:
- Ensure the server is running in a terminal (
node build/index.js). - Check if
wolframscriptis installed and accessible in your PATH (wolframscript -help). - Restart your MCP client application.
- Check the client's MCP configuration.
- Ensure the server is running in a terminal (
- Tool Errors:
- Check the server's terminal output (stderr) for logs and error messages from
wolframscript. - Verify the syntax of the Mathematica
codeorstepsprovided. - Ensure the
stepsarray forverify_derivationhas at least two elements.
- Check the server's terminal output (stderr) for logs and error messages from
- Mathematica Issues: Ensure your Mathematica installation is licensed and working correctly.
Project Structure
src/: TypeScript source code for the server.build/: Compiled JavaScript output (generated bynpm run build).package.json: Project metadata and dependencies.tsconfig.json: TypeScript compiler configuration.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。