- Home
- MCP servers
- MATLAB
MATLAB
- python
37
GitHub Stars
python
Language
6 months ago
First Indexed
2 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
Installation
Add the following to your MCP client configuration file.
Configuration
View docs{
"mcpServers": {
"tsuchijo-matlab-mcp": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/matlab-mcp",
"run",
"matlab_server.py"
],
"env": {
"MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
}
}
}
}You can run MATLAB scripts and functions from MCP clients through this server, enabling seamless integration between MATLAB and Claude or other MCP clients. This setup lets you create, store, and execute MATLAB code in a controlled environment, returning outputs, figures, and workspace data to your MCP client.
How to use
Install and run the server in a local environment, then connect using an MCP client. You will be able to create MATLAB scripts and functions, execute them, and pass arguments to them. The server stores all scripts in a dedicated directory and returns results such as text output, figures, and workspace variables.
Typical usage patterns include creating a new MATLAB script, saving it in the matlab_scripts directory, and invoking it from your MCP client with optional arguments. You can also create MATLAB functions, call them with parameters, and process the outputs produced by MATLAB.
To connect from Claude Desktop, configure an MCP server entry that runs the local server via the uv runtime using the provided command and arguments. The server will read the MATLAB installation path from the MATLAB_PATH environment variable.
How to install
Prerequisites you need before installation: Python 3.11, MATLAB R2024a (or compatible), and the uv package manager.
# 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]"
Configuration and startup
The server is started locally using uv and a MATLAB server script. Place the MATLAB server script at the root alongside the matlab_scripts directory created automatically when the server runs.
{
"mcpServers": {
"matlab": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/matlab-mcp",
"run",
"matlab_server.py"
],
"env": {
"MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
}
}
}
}
Testing the server
Activate the virtual environment and start the MCP dev server to verify the setup.
# Ensure you're in the virtual environment
source .venv/bin/activate
# Run the inspector locally (adjust MATLAB_PATH as needed)
MATLAB_PATH=/Applications/MATLAB_R2024a.app mcp dev matlab_server.py
Example test MATLAB script
% Simple test script to verify plotting
t = 0:0.01:2*pi;
y = sin(t);
plot(t, y);
title('Test Plot');
lxlabel('Time');
ylabel('Amplitude');
Script storage and environment
All MATLAB scripts and functions are saved in the matlab_scripts directory. This directory is created automatically when the server starts and resides alongside matlab_server.py.
Environment variables you need to know about include MATLAB_PATH, which should point to your MATLAB installation. You can set it in the Claude Desktop config or when starting the server.
Troubleshooting
MATLAB Engine installation might fail if the MATLAB_PATH is incorrect. Verify that the path points to a valid MATLAB installation and try installing the engine manually from the MATLAB deployment: navigate to $MATLAB_PATH/extern/engines/python and run python setup.py install.
If you encounter Python version issues, ensure you are using Python 3.11 and pin it if needed with uv. Check the version with python --version.
For script execution errors, confirm that the matlab_scripts directory exists and that scripts have valid MATLAB syntax. Review the MATLAB output for specific error messages.
Updates and maintenance
Keep your MATLAB installation up to date and manage Python packages as needed using uv. When updating Python, verify the MATLAB Engine compatibility with the new Python version.
Notes
The server uses a local stdio approach for MCP interactions. You can run the server with the directory option pointing to your project and execute the main MATLAB server script. The MATLAB_PATH environment variable is required to locate your MATLAB installation.
Available tools
create_matlab_script
Create a new MATLAB script file. Scripts are saved in the matlab_scripts directory and must have a valid MATLAB identifier as the filename.
create_matlab_function
Create a new MATLAB function file. Functions are saved in the matlab_scripts directory and must include a valid function definition.
execute_matlab_script
Run a MATLAB script and return output text, generated figures, and workspace variables. You can pass arguments to the script.
call_matlab_function
Call a MATLAB function with arguments and receive the function output, including any generated figures.