MATLAB
STDIOMATLAB脚本创建与执行的MCP服务器
MATLAB脚本创建与执行的MCP服务器
This Model Context Protocol (MCP) server provides integration with MATLAB, allowing you to create and execute MATLAB scripts and functions through Claude or other MCP clients.
# 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]"
MATLAB_PATH environment variable.matlab_server.py: The main MCP server implementationmatlab_scripts/: Directory where all MATLAB scripts and functions are saved (created automatically)pyproject.toml: Python project configuration.python-version: Specifies Python version for uv# 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" } } } }
Make sure to:
/absolute/path/to/matlab-mcp with the actual path to your project directoryMATLAB_PATH points to your MATLAB installationThe server provides several tools:
create_matlab_script: Create a new MATLAB script file
matlab_scripts directorycreate_matlab_function: Create a new MATLAB function file
matlab_scripts directoryexecute_matlab_script: Run a MATLAB script and get results
call_matlab_function: Call a MATLAB function with arguments
You can test the server 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
Example test script:
t = 0:0.01:2*pi; y = sin(t); plot(t, y); title('Test Plot'); xlabel('Time'); ylabel('Amplitude');
matlab_scripts directory<script_name>.m or <function_name>.mmatlab_server.pyMATLAB_PATH: Path to your MATLAB installation
/Applications/MATLAB_R2024a.appMATLAB Engine Installation Fails
cd $MATLAB_PATH/extern/engines/python python setup.py install
Python Version Issues
python --versionuv python pin 3.11 if neededScript Execution Errors
matlab_scripts directory existsuv pip install --upgrade mcp[cli]