Get the FREE Ultimate OpenClaw Setup Guide →

matlab

Model Context Protocol server to let LLMs write and execute matlab scripts

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio tsuchijo-matlab-mcp uv --directory /absolute/path/to/matlab-mcp run matlab_server.py \
  --env MATLAB_PATH="/Applications/MATLAB_R2024a.app"

How to use

This MATLAB MCP server provides a bridge to MATLAB from MCP clients (e.g., Claude or MCP Inspector). It lets you create MATLAB scripts and functions, execute them, and capture outputs, figures, and workspace variables. The server exposes tools such as create_matlab_script for creating new .m script files, create_matlab_function for generating MATLAB function files, execute_matlab_script to run a MATLAB script and retrieve results, and call_matlab_function to invoke a MATLAB function with arguments. Configure MATLAB_PATH to point to your MATLAB installation, and start the server via uv within your project directory. Once running, you can interact with the server through MCP clients to manage MATLAB scripts, run analyses, visualize results, and fetch results back into your workflow.

How to install

Prerequisites:

  • Python 3.11 (MATLAB Engine requires 3.11; 3.12/3.13 are not supported by MATLAB Engine)
  • MATLAB R2024a (or compatible)
  • uv (Python package manager)
  1. Pin the Python version and create a virtual environment:
uv python pin 3.11
uv venv
  1. Activate the virtual environment:
  • On Unix/macOS:
source .venv/bin/activate
  1. Install MCP CLI inside the virtual environment:
uv add "mcp[cli]"
  1. Ensure MATLAB Engine will be installed automatically when the server first runs, using the MATLAB installation specified by MATLAB_PATH. Set MATLAB_PATH to your MATLAB installation path (see env vars below).

  2. Start the MATLAB MCP server (example in the Claude Desktop config guidance uses uv with run matlab_server.py). Ensure you point to the correct directory where matlab_server.py resides.

Additional notes

Tips and known considerations:

  • MATLAB_PATH should point to your MATLAB installation (e.g., /Applications/MATLAB_R2024a.app). The engine will be installed automatically based on this path when the server starts.
  • Use absolute paths for all directory references (e.g., the project directory passed to --directory).
  • If you encounter MATLAB Engine installation failures, verify MATLAB_PATH is correct and consider manual engine installation from $MATLAB_PATH/extern/engines/python (cd into that directory and run python setup.py install).
  • The matlab_scripts directory is created automatically when the server starts and stores .m files for scripts and functions. File names should be valid MATLAB identifiers.
  • To test locally, set MATLAB_PATH in the environment when invoking the server, for example: MATLAB_PATH=/Applications/MATLAB_R2024a.app mcp dev matlab_server.py
  • When updating Python packages, you can run uv pip install --upgrade mcp[cli].
  • If you modify Python dependencies or MATLAB integration, restart the server to pick up changes.

Related MCP Servers

Sponsor this space

Reach thousands of developers