MATLAB MCP Tool MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
git clone https://github.com/neuromechanist/matlab-mcp-tools
cd matlab-mcp-tools

Then follow the repository README for any remaining dependency or build steps before continuing.

2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add matlab-mcp -- node "<FULL_PATH_TO_MATLAB_MCP_TOOLS>/dist/index.js"

Replace <FULL_PATH_TO_MATLAB_MCP_TOOLS>/dist/index.js with the actual folder you prepared in step 1.

README.md

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

  1. Script Execution - Run complete scripts, individual sections (by index, title, or line range), maintain workspace context between executions, capture plots
  2. 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
  3. Figure Analysis - Extract figure metadata (axes, labels, legends), get raw plot data, prepare figures for LLM-based analysis with custom prompts
  4. Code Quality - Lint MATLAB code via checkcode with severity filtering, supports inline code and file paths
  5. 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:

  1. Clone this repository:
git clone [repository-url]
cd matlab-mcp-tools
  1. Set custom MATLAB path (optional - installer auto-detects):
# Only needed if MATLAB is in unusual location
export MATLAB_PATH=/path/to/your/matlab/installation
  1. Run installer:
./install-matlab-mcp.sh

Legacy Installation (Manual)

Click to expand legacy manual installation steps
  1. Install uv package manager:
# Install uv using Homebrew
brew install uv
# OR install using pip
pip install uv
  1. 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"
  1. Run legacy setup script:
./scripts/setup-matlab-mcp.sh
  1. 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

  1. 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.

  1. 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__)".

  1. 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 file
execute_sectionExecute by line range
execute_section_by_indexExecute by section index (0-based)
execute_section_by_titleExecute by section title (partial match)
get_script_sectionsList sections with titles and previews
create_matlab_scriptCreate a new .m file
get_workspaceGet all workspace variables
get_variableGet specific variable with field/depth/size control
get_struct_infoGet struct field metadata without data transfer
list_workspace_variablesList/filter variables by name pattern or type
get_figure_metadataExtract axes, labels, legends, subplot info
get_plot_dataGet raw x/y/z data from plot lines
analyze_figurePrepare figure image and metadata for LLM analysis
get_analysis_promptGet or customize the figure analysis prompt
matlab_lintRun checkcode on code or files

Environment Variables

MATLAB_PATHPath to the MATLAB installation directory

Configuration

claude_desktop_config.json
{"mcpServers": {"matlab": {"command": "/path/to/matlab-mcp-tools/.venv/bin/matlab-mcp-server", "env": {"MATLAB_PATH": "/Applications/MATLAB_R2024b.app"}}}}

Try it

Run the script 'data_analysis.m' and tell me the mean value of the resulting 'results' variable.
List all variables currently in my MATLAB workspace and identify any that are structs.
Analyze the current figure and explain what the axes labels and legend indicate about the data.
Lint my 'process_signal.m' file to check for potential code quality issues.
Execute the second section of my current script and retrieve the 'final_matrix' variable.

Frequently Asked Questions

What are the key features of MATLAB MCP Tool?

Execute complete MATLAB scripts or specific code sections with persistent context. Manage and inspect MATLAB workspace variables with filtering and metadata support. Extract and analyze figure metadata, plot data, and visual content for LLM interpretation. Perform code quality checks using MATLAB's built-in checkcode linter. Create and manage MATLAB script files directly through MCP resources.

What can I use MATLAB MCP Tool for?

Automating data processing pipelines by running MATLAB scripts from an AI chat interface. Debugging complex MATLAB code by inspecting workspace variables in real-time. Generating AI-assisted explanations for scientific plots and visualizations. Refactoring and linting legacy MATLAB codebases with AI guidance.

How do I install MATLAB MCP Tool?

Install MATLAB MCP Tool by running: ./install-matlab-mcp.sh

What MCP clients work with MATLAB MCP Tool?

MATLAB MCP Tool works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep MATLAB MCP Tool docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare