Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

matlab-mcp

MCP.Pizza Chef: Tsuchijo

The matlab-mcp server is a Model Context Protocol (MCP) server that integrates MATLAB with LLMs, allowing them to create, run, and manage MATLAB scripts and functions through MCP clients like Claude. It requires Python 3.11 and MATLAB R2024a or compatible versions. The server automates MATLAB Engine installation and organizes scripts in a dedicated directory, facilitating real-time MATLAB code execution and interaction within AI workflows. This server empowers developers to leverage MATLAB's computational capabilities directly from language models, enhancing automation and scientific computing tasks.

Use This MCP server To

Execute MATLAB scripts from LLM-driven workflows Automate MATLAB code generation and testing Integrate MATLAB computations into AI assistants Run scientific simulations via language models Generate MATLAB functions dynamically Debug MATLAB code interactively with LLMs

README

MATLAB MCP Server

This Model Context Protocol (MCP) server provides integration with MATLAB, allowing you to create and execute MATLAB scripts and functions through Claude or other MCP clients.

Setup Requirements

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

Installation

  1. Create and set up the 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]"
  1. Install MATLAB Engine The MATLAB Engine will be installed automatically when the server first runs, using the MATLAB installation specified in the MATLAB_PATH environment variable.

Directory Structure

  • matlab_server.py: The main MCP server implementation
  • matlab_scripts/: Directory where all MATLAB scripts and functions are saved (created automatically)
  • pyproject.toml: Python project configuration
  • .python-version: Specifies Python version for uv

Claude Desktop Integration

  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"
            }
        }
    }
}

Make sure to:

  • Replace /absolute/path/to/matlab-mcp with the actual path to your project directory
  • Verify the MATLAB_PATH points to your MATLAB installation
  • Use absolute paths (not relative)

Features

The server provides several tools:

  1. create_matlab_script: Create a new MATLAB script file

    • Scripts are saved in the matlab_scripts directory
    • File names must be valid MATLAB identifiers
  2. create_matlab_function: Create a new MATLAB function file

    • Functions are saved in the matlab_scripts directory
    • Must include valid function definition
  3. execute_matlab_script: Run a MATLAB script and get results

    • Returns output text, generated figures, and workspace variables
    • Can pass arguments to scripts
  4. call_matlab_function: Call a MATLAB function with arguments

    • Returns function output and any generated figures

Testing

You can test the server 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

Example test script:

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

Script Storage

  • All MATLAB scripts and functions are saved in the matlab_scripts directory
  • This directory is created automatically when the server starts
  • Files are named <script_name>.m or <function_name>.m
  • The directory is in the same location as matlab_server.py

Environment Variables

  • MATLAB_PATH: Path to your MATLAB installation
    • Default: /Applications/MATLAB_R2024a.app
    • Set in Claude Desktop config or when running directly

Troubleshooting

  1. MATLAB Engine Installation Fails

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

    • Make sure you're using Python 3.11
    • Check with: python --version
    • Use uv python pin 3.11 if needed
  3. Script Execution Errors

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

Updates and Maintenance

  • Keep your MATLAB installation updated
  • Update Python packages as needed: uv pip install --upgrade mcp[cli]
  • Check MATLAB engine compatibility when updating Python

matlab-mcp FAQ

How do I install the matlab-mcp server?
Set up Python 3.11, create a virtual environment, activate it, install MCP with 'uv add "mcp[cli]"', and run the server to auto-install MATLAB Engine.
Which MATLAB versions are compatible with matlab-mcp?
MATLAB R2024a or compatible versions are supported for seamless integration.
What Python version is required for matlab-mcp?
Python 3.11 is required; versions 3.12 and 3.13 are not supported due to MATLAB Engine limitations.
How does matlab-mcp handle MATLAB script storage?
It automatically creates and uses a 'matlab_scripts/' directory to save all MATLAB scripts and functions.
Can matlab-mcp execute MATLAB code in real-time?
Yes, it allows LLMs to write and execute MATLAB scripts dynamically through MCP clients.
Is MATLAB Engine installation manual?
No, the MATLAB Engine installs automatically on the first server run using the MATLAB_PATH environment variable.
What MCP clients can interact with matlab-mcp?
Any MCP client like Claude or others can connect to this server to run MATLAB scripts.
Does matlab-mcp support multiple LLM providers?
Yes, it is provider-agnostic and works with OpenAI, Claude, Gemini, and other LLMs.