SymPy MCP server

Provides a stateful symbolic mathematics engine for precise algebraic operations, calculus, vector analysis, tensor calculations, and differential equation solving without hallucinations.
Back to servers
Provider
Stephen Diehl
Release date
May 18, 2025
Language
Python
Stats
19 stars

Symbolic Algebra MCP Server is a tool that allows language models to perform symbolic mathematics and computer algebra operations through the Model Context Protocol (MCP). It exposes SymPy's powerful symbolic manipulation capabilities to LLMs, enabling them to solve complex mathematical problems accurately without hallucinating results.

Installation

Before installing the server, you need to have uv package manager installed:

  • Homebrew:
    brew install uv
    
  • Curl:
    curl -LsSf https://astral.sh/uv/install.sh | sh
    

Standard Installation

# Clone the repository
git clone https://github.com/sdiehl/sympy-mcp.git
cd sympy-mcp
uv sync

# Install the server to Claude Desktop
uv run mcp install server.py

# Run the server
uv run mcp run server.py

Quick Standalone Installation

For a single-command installation (use with caution):

uv run --with https://github.com/sdiehl/sympy-mcp/releases/download/0.1/sympy_mcp-0.1.0-py3-none-any.whl python server.py

Installing General Relativity Support

For general relativity calculations, install the additional dependency:

uv sync --group relativity

Docker Installation

You can also run the server in a Docker container:

# Pull the pre-built image
docker pull ghcr.io/sdiehl/sympy-mcp:latest

# Run the container
docker run -p 8081:8081 --rm ghcr.io/sdiehl/sympy-mcp:latest

Or build and run locally:

# Build the Docker image
docker build -t sympy-mcp .

# Run the Docker container
docker run -p 8081:8081 sympy-mcp

Client Setup

Claude Desktop

The mcp install command should automatically add the server to your Claude Desktop configuration. If not, edit your config file manually:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Add this to the mcpServers object:

{
  "mcpServers": {
    "sympy-mcp": {
      "command": "/opt/homebrew/bin/uv",
      "args": [
        "run",
        "--with",
        "einsteinpy",
        "--with",
        "mcp[cli]",
        "--with",
        "pydantic",
        "--with",
        "sympy",
        "mcp",
        "run",
        "/ABSOLUTE_PATH_TO_SYMPY_MCP/server.py"
      ]
    }
  }
}

VS Code Setup

VS Code supports MCP in agent mode. You can use one-click setup or manually add to settings.json:

{
  "mcp": {
    "servers": {
      "sympy-mcp": {
        "command": "uv",
        "args": [
          "run",
          "--with",
          "einsteinpy",
          "--with",
          "mcp[cli]",
          "--with",
          "pydantic",
          "--with",
          "sympy",
          "mcp",
          "run",
          "/ABSOLUTE_PATH_TO_SYMPY_MCP/server.py"
        ]
      }
    }
  }
}

Cline Setup

For Cline:

  1. Run the MCP server using the commands in the Installation section
  2. Open Cline and select "MCP Servers" at the top
  3. Select "Remote Servers" and add:
    • Server Name: sympy-mcp
    • Server URL: http://127.0.0.1:8081/sse

5ire Setup

For 5ire:

  1. Open 5ire and go to Tools -> New
  2. Set:
    • Tool Key: sympy-mcp
    • Name: SymPy MCP
    • Command: /opt/homebrew/bin/uv run --with einsteinpy --with mcp[cli] --with pydantic --with sympy mcp run /ABSOLUTE_PATH_TO/server.py

Available Tools

The server provides these mathematical tools:

Basic Operations

  • Variable Introduction (intro): Introduces variables with specified assumptions
  • Multiple Variables (intro_many): Introduces multiple variables simultaneously
  • Expression Parser (introduce_expression): Parses mathematical expressions
  • LaTeX Printer (print_latex_expression): Outputs expressions in LaTeX format
  • Simplifier (simplify_expression): Simplifies expressions
  • Substitution (substitute_expression): Replaces variables in expressions

Equation Solving

  • Algebraic Solver (solve_algebraically): Solves algebraic equations
  • Linear Solver (solve_linear_system): Solves systems of linear equations
  • Nonlinear Solver (solve_nonlinear_system): Solves nonlinear equation systems

Calculus

  • Integration (integrate_expression): Integrates expressions
  • Differentiation (differentiate_expression): Differentiates expressions
  • Function Variable (introduce_function): Creates function variables
  • ODE Solver (dsolve_ode): Solves ordinary differential equations
  • PDE Solver (pdsolve_pde): Solves partial differential equations

Vector Calculus

  • Coordinates (create_coordinate_system): Creates 3D coordinate systems
  • Vector Field (create_vector_field): Creates vector fields
  • Curl (calculate_curl): Calculates curl of vector fields
  • Divergence (calculate_divergence): Calculates divergence of vector fields
  • Gradient (calculate_gradient): Calculates gradient of scalar fields

General Relativity

  • Standard Metric (create_predefined_metric): Creates predefined spacetime metrics
  • Metric Search (search_predefined_metrics): Searches available metrics
  • Tensor Calculator (calculate_tensor): Calculates tensors from metrics
  • Custom Metric (create_custom_metric): Creates custom metric tensors
  • Tensor LaTeX (print_latex_tensor): Formats tensors in LaTeX

Matrix Operations

  • Matrix Creator (create_matrix): Creates matrices
  • Determinant (matrix_determinant): Calculates matrix determinants
  • Matrix Inverse (matrix_inverse): Calculates matrix inverses
  • Eigenvalues (matrix_eigenvalues): Calculates matrix eigenvalues
  • Eigenvectors (matrix_eigenvectors): Calculates matrix eigenvectors

Units

  • Unit Converter (convert_to_units): Converts between units
  • Unit Simplifier (quantity_simplify_units): Simplifies units in expressions

Usage Examples

Example 1: Solving Differential Equations

You can solve differential equations like a damped harmonic oscillator:

Solve the damped harmonic oscillator with forcing term:
m(d²x/dt²) + c(dx/dt) + kx = F(t)
where m is mass, c is damping coefficient, k is spring constant, and F(t) is external force.

The server will:

  1. Introduce variables (t, m, c, k)
  2. Define the function x(t)
  3. Create the differential equation
  4. Solve it symbolically

Example 2: General Relativity Calculations

You can perform tensor calculations:

Compute the trace of the Ricci tensor R_μν using the inverse metric g^μν for Anti-de Sitter spacetime 
to determine its constant scalar curvature R.

The server will:

  1. Create the Anti-de Sitter metric
  2. Calculate the Ricci tensor
  3. Calculate the Ricci scalar
  4. Display the results in LaTeX format

Security Considerations

This server runs Python code on your computer, including using Sympy's parse_expr which utilizes eval() under the hood. This means it can potentially execute arbitrary code. Consider the following:

  • Review the code generated by the LLM before executing
  • Running in Docker provides some isolation
  • Be aware of the security implications when using this server

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later