MATLAB MCP server

Integrates MATLAB's numerical computing capabilities, enabling execution of MATLAB scripts and functions for data analysis, signal processing, and visualization.
Back to servers
Setup instructions
Provider
Tsuchijo
Release date
Jan 10, 2025
Language
Python
Stats
19 stars

This MCP server integrates MATLAB with Claude and other MCP clients, allowing you to create and execute MATLAB scripts and functions through a convenient interface. It enables seamless interaction with MATLAB's computational capabilities directly from your AI assistant.

Requirements

  • Python 3.11 (Python 3.13 and 3.12 are not supported by MATLAB Engine)
  • MATLAB R2024a (or compatible version)
  • uv package manager

Installation

Setting Up the Python Environment

First, create and configure your Python environment:

# Pin Python version
uv python pin 3.11

# Create virtual environment
uv venv

# Activate virtual environment
source .venv/bin/activate

# Install MCP
uv add "mcp[cli]"

Installing MATLAB Engine

The MATLAB Engine is installed automatically when the server first runs, using the MATLAB installation specified in the MATLAB_PATH environment variable.

Configuring Claude Desktop

To integrate with Claude Desktop:

  1. Open your Claude Desktop configuration:
# On macOS
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
  1. Add the MATLAB server configuration:
{
    "mcpServers": {
        "matlab": {
            "command": "uv",
            "args": [
                "--directory",
                "/absolute/path/to/matlab-mcp",
                "run",
                "matlab_server.py"
            ],
            "env": {
                "MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
            }
        }
    }
}

Important: Replace /absolute/path/to/matlab-mcp with the absolute path to your project directory and verify the MATLAB_PATH points to your MATLAB installation.

Using the Server

Available Features

The server provides several tools for interacting with MATLAB:

Creating Scripts and Functions

  • Create MATLAB scripts - Scripts are saved in the matlab_scripts directory
  • Create MATLAB functions - Functions are saved with proper definitions in the same directory

Executing MATLAB Code

  • Execute scripts - Run MATLAB scripts and get results including output text, generated figures, and workspace variables
  • Call functions - Call MATLAB functions with arguments and receive function output and any generated figures

Testing the Server

You can test the server functionality using the MCP Inspector:

# Make sure you're in your virtual environment
source .venv/bin/activate

# Run the inspector
MATLAB_PATH=/Applications/MATLAB_R2024a.app mcp dev matlab_server.py

Try this example test script:

t = 0:0.01:2*pi;
y = sin(t);
plot(t, y);
title('Test Plot');
xlabel('Time');
ylabel('Amplitude');

Troubleshooting

MATLAB Engine Installation Problems

If the MATLAB Engine installation fails:

  • Verify the MATLAB_PATH is correct
  • Try installing the engine manually:
cd $MATLAB_PATH/extern/engines/python
python setup.py install

Python Version Issues

If you encounter Python version problems:

  • Ensure you're using Python 3.11 with python --version
  • Use uv python pin 3.11 if needed

Script Execution Errors

When scripts fail to execute properly:

  • Check that the matlab_scripts directory exists
  • Verify your script syntax is valid MATLAB code
  • Look for error messages in the MATLAB output

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 "matlab" '{"command":"uv","args":["--directory","/absolute/path/to/matlab-mcp","run","matlab_server.py"],"env":{"MATLAB_PATH":"/Applications/MATLAB_R2024a.app"}}'

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": {
        "matlab": {
            "command": "uv",
            "args": [
                "--directory",
                "/absolute/path/to/matlab-mcp",
                "run",
                "matlab_server.py"
            ],
            "env": {
                "MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
            }
        }
    }
}

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": {
        "matlab": {
            "command": "uv",
            "args": [
                "--directory",
                "/absolute/path/to/matlab-mcp",
                "run",
                "matlab_server.py"
            ],
            "env": {
                "MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
            }
        }
    }
}

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