Enables interactive MATLAB development and execution via MCP
MATLAB MCP Tool
A Model Context Protocol (MCP) server that provides tools for developing and running MATLAB files. Integrates with Claude Code, Cursor, and other MCP-compatible clients.
Prerequisites
- Python 3.10+
- MATLAB with Python Engine installed
- uv package manager (required)
Features
- Script Execution - Run complete scripts, individual sections (by index, title, or line range), maintain workspace context between executions, capture plots
- Workspace Management - Get full workspace, retrieve specific variables with field/depth/size control, inspect struct metadata, list and filter variables by name pattern or type
- Figure Analysis - Extract figure metadata (axes, labels, legends), get raw plot data, prepare figures for LLM-based analysis with custom prompts
- Code Quality - Lint MATLAB code via
checkcodewith severity filtering, supports inline code and file paths - Script Management - Create scripts, list sections with previews, read script content via MCP resource
Installation
Quick Start (Recommended)
One-command installation with auto-detection:
./install-matlab-mcp.sh
That's it! The installer will:
- ✅ Auto-detect MATLAB installations (including external volumes like
/Volumes/S1/) - ✅ Auto-install UV package manager if needed
- ✅ Create optimized virtual environment with MATLAB-compatible Python version
- ✅ Install all dependencies including MATLAB Python engine
- ✅ Generate MCP configuration ready for Cursor/Claude Code
- ✅ Verify installation works correctly
- ✅ Optionally configure Cursor automatically
Reduces installation time from 15+ minutes to ~2 minutes!
Advanced Installation
If you need custom configuration:
- Clone this repository:
git clone [repository-url]
cd matlab-mcp-tools
- Set custom MATLAB path (optional - installer auto-detects):
# Only needed if MATLAB is in unusual location
export MATLAB_PATH=/path/to/your/matlab/installation
- Run installer:
./install-matlab-mcp.sh
Legacy Installation (Manual)
Click to expand legacy manual installation steps
- Install uv package manager:
# Install uv using Homebrew
brew install uv
# OR install using pip
pip install uv
- Set MATLAB path environment variable:
# For macOS (auto-detection searches common locations)
export MATLAB_PATH=/Applications/MATLAB_R2024b.app
# For Windows (use Git Bash terminal)
export MATLAB_PATH="C:/Program Files/MATLAB/R2024b"
- Run legacy setup script:
./scripts/setup-matlab-mcp.sh
- Configure Cursor manually:
cp mcp-pip.json ~/.cursor/mcp.json
Testing Installation
Test your installation:
./scripts/test-matlab-mcp.sh
Installation complete! The MATLAB MCP server is now ready to use with Cursor/Claude Code.
Usage
- Start the MCP server:
matlab-mcp-server
This is equivalent to running:
python -m matlab_mcp.server
You should see a startup message confirming the server is running with 15 tools available.
- Configure your MCP client. For Claude Code, add to
.mcp.json:
{
"mcpServers": {
"matlab": {
"command": "/path/to/matlab-mcp-tools/.venv/bin/matlab-mcp-server",
"env": {
"MATLAB_PATH": "/Applications/MATLAB_R2024b.app"
}
}
}
}
For Cursor, use the auto-generated mcp-pip.json or add to ~/.cursor/mcp.json.
Hint: Find the MATLAB engine path with python -c "import matlab; print(matlab.__file__)".
- Available Tools (15):
| Category | Tool | Description |
|---|---|---|
| Scripts | execute_script |
Run MATLAB code or script file |
execute_section |
Execute by line range | |
execute_section_by_index |
Execute by section index (0-based) | |
execute_section_by_title |
Execute by section title (partial match) | |
get_script_sections |
List sections with titles and previews | |
create_matlab_script |
Create a new .m file | |
| Workspace | get_workspace |
Get all workspace variables |
get_variable |
Get specific variable (with field/depth/size control) | |
get_struct_info |
Get struct field metadata without data transfer | |
list_workspace_variables |
List/filter variables by name pattern or type | |
| Figures | get_figure_metadata |
Extract axes, labels, legends, subplot info |
get_plot_data |
Get raw x/y/z data from plot lines | |
analyze_figure |
Prepare figure image + metadata for LLM analysis | |
get_analysis_prompt |
Get/customize the figure analysis prompt | |
| Quality | matlab_lint |
Run checkcode on code or files |
Resource: matlab://scripts/{script_name} - Read script content
Examples
1. Simple Script Execution with Plot
This example demonstrates running a complete MATLAB script that generates a plot:
% test_plot.m
x = lin
Tools (15)
execute_scriptRun MATLAB code or script fileexecute_sectionExecute by line rangeexecute_section_by_indexExecute by section index (0-based)execute_section_by_titleExecute by section title (partial match)get_script_sectionsList sections with titles and previewscreate_matlab_scriptCreate a new .m fileget_workspaceGet all workspace variablesget_variableGet specific variable with field/depth/size controlget_struct_infoGet struct field metadata without data transferlist_workspace_variablesList/filter variables by name pattern or typeget_figure_metadataExtract axes, labels, legends, subplot infoget_plot_dataGet raw x/y/z data from plot linesanalyze_figurePrepare figure image and metadata for LLM analysisget_analysis_promptGet or customize the figure analysis promptmatlab_lintRun checkcode on code or filesEnvironment Variables
MATLAB_PATHPath to the MATLAB installation directoryConfiguration
{"mcpServers": {"matlab": {"command": "/path/to/matlab-mcp-tools/.venv/bin/matlab-mcp-server", "env": {"MATLAB_PATH": "/Applications/MATLAB_R2024b.app"}}}}