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
Setup instructions
Provider
Stephen Diehl
Release date
May 18, 2025
Language
Python
Stats
31 stars

The Symbolic Algebra MCP Server enables language models to perform symbolic mathematics and computer algebra by providing access to SymPy's functionality. It allows LLMs to handle symbolic manipulation tasks they typically struggle with, such as solving equations, performing calculus, and working with vector and tensor mathematics.

Installation

Prerequisites

First, install uv:

  • Using Homebrew:
    brew install uv
    
  • Using 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 Installation

For a standalone version that runs with a single command:

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

Additional Dependencies

For general relativity calculations, install the Einstein library:

uv sync --group relativity

Docker Installation

You can use Docker to run the server:

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

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

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 Configuration

Claude Desktop

The mcp install command should automatically configure Claude Desktop. If not, edit the config file:

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

Add the following 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

VS Code supports MCPs in agent mode. Enable Chat > Agent: Enable in settings.

Manual Configuration: Add to your 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"
        ]
      }
    }
  }
}

Or for Docker:

{
  "mcp": {
    "servers": {
      "sympy-mcp": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "-p",
          "8081:8081",
          "--rm",
          "ghcr.io/sdiehl/sympy-mcp:main"
        ]
      }
    }
  }
}

Cline

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

5ire

In 5ire, go to Tools -> New and 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 over 30 symbolic mathematics tools, including:

  • Variable introduction tools (intro, intro_many)
  • Expression handling (introduce_expression, print_latex_expression)
  • Equation solving (solve_algebraically, solve_linear_system, solve_nonlinear_system)
  • Differential equations (dsolve_ode, pdsolve_pde)
  • Calculus (integrate_expression, differentiate_expression)
  • General relativity (create_predefined_metric, calculate_tensor)
  • Vector calculus (create_vector_field, calculate_curl, calculate_divergence)
  • Matrix operations (create_matrix, matrix_determinant, matrix_eigenvalues)

Usage Examples

Differential Equations

You can solve differential equations like the damped harmonic oscillator:

m*d²x/dt² + c*dx/dt + kx = F(t)

The server will:

  1. Introduce variables and functions
  2. Parse the equation
  3. Solve it using SymPy's ODE solver

General Relativity

For tensor calculations, you can:

Compute the trace of the Ricci tensor using the inverse metric for Anti-de Sitter spacetime

The server will:

  1. Create the appropriate metric
  2. Calculate the Ricci tensor
  3. Display the result in LaTeX format
  4. Calculate the Ricci scalar

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

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

See the official Claude Code MCP documentation for more details.

For 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 > Tools & Integrations and click "New MCP Server".

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

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

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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

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

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

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