Skip to main content

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

Metadata

Release files for iflow-mcp_tsuchijo-matlab-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_tsuchijo-matlab-mcp 0.1.0
File Size Uploaded
iflow_mcp_tsuchijo_matlab_mcp-0.1.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_tsuchijo-matlab-mcp 0.1.0
File Interpreter ABI Platform
iflow_mcp_tsuchijo_matlab_mcp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / iflow_mcp_tsuchijo_matlab_mcp-0.1.0.tar.gz

Download URL iflow_mcp_tsuchijo_matlab_mcp-0.1.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8f7d8b0f65b551e433f36bf8514501570c613d65e862ef95a360ddea329a69a8
BLAKE2b-256 checksum
How to use checksums
cfbba3e834112cf7b2147973ac5a22aeaf9a37b4832787fe64d9302edcf2b508
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iflow_mcp_tsuchijo_matlab_mcp-0.1.0-py3-none-any.whl

Download URL iflow_mcp_tsuchijo_matlab_mcp-0.1.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
feb7dda3ab52d9484aba56751de6948a6075047bb76103f5b00cec0b270a6fd0
BLAKE2b-256 checksum
How to use checksums
d3d06f1bcf3f6889b1ee4af3544699541030f20e4b752b7c2974bcf0a2fc2767
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page