This MCP server integrates MATLAB with Claude and other MCP clients, allowing you to create and execute MATLAB scripts and functions through a convenient interface. It enables seamless interaction with MATLAB's computational capabilities directly from your AI assistant.
First, create and configure your 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]"
The MATLAB Engine is installed automatically when the server first runs, using the MATLAB installation specified in the MATLAB_PATH
environment variable.
To integrate with Claude Desktop:
# On macOS
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"matlab": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/matlab-mcp",
"run",
"matlab_server.py"
],
"env": {
"MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
}
}
}
}
Important: Replace /absolute/path/to/matlab-mcp
with the absolute path to your project directory and verify the MATLAB_PATH
points to your MATLAB installation.
The server provides several tools for interacting with MATLAB:
matlab_scripts
directoryYou can test the server functionality 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
Try this example test script:
t = 0:0.01:2*pi;
y = sin(t);
plot(t, y);
title('Test Plot');
xlabel('Time');
ylabel('Amplitude');
If the MATLAB Engine installation fails:
MATLAB_PATH
is correctcd $MATLAB_PATH/extern/engines/python
python setup.py install
If you encounter Python version problems:
python --version
uv python pin 3.11
if neededWhen scripts fail to execute properly:
matlab_scripts
directory existsTo add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "matlab" '{"command":"uv","args":["--directory","/absolute/path/to/matlab-mcp","run","matlab_server.py"],"env":{"MATLAB_PATH":"/Applications/MATLAB_R2024a.app"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"matlab": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/matlab-mcp",
"run",
"matlab_server.py"
],
"env": {
"MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"matlab": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/matlab-mcp",
"run",
"matlab_server.py"
],
"env": {
"MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect