A Model Context Protocol (MCP) server that provides tools for developing, running, and debugging MATLAB files. This tool integrates with Cline and other MCP-compatible clients to provide interactive MATLAB development capabilities.
- Python 3.8+
- MATLAB with Python Engine installed
- MCP SDK for Python (
pip install modelcontextprotocol
) - MATLAB Engine for Python (
pip install matlabengine
)
-
Execute MATLAB Scripts
- Run complete MATLAB scripts
- Execute individual script sections
- Maintain workspace context between executions
- Capture and display plots
-
Interactive Debugging
- Set breakpoints in MATLAB scripts
- Debug script execution
- Inspect workspace variables
-
Section-based Execution
- Execute specific sections of MATLAB files
- Support for cell mode (%% delimited sections)
- Maintain workspace context between sections
- Clone this repository:
git clone [repository-url]
cd matlab-mcp-tool
- Create and activate a conda environment:
conda create -n matlab-mcp python=3.8
conda activate matlab-mcp
- Install dependencies:
pip install modelcontextprotocol matlabengine
- Start the MCP server:
python src/matlab_bridge.py
- Configure Cline to use the MATLAB MCP server by adding to your Cline configuration:
{
"mcpServers": {
"matlab": {
"command": "python",
"args": ["/path/to/matlab-mcp-tool/src/matlab_bridge.py"],
"env": {
"PYTHONPATH": "/path/to/matlab/engine/installation"
}
}
}
}
- Available Tools:
-
execute_matlab_script
{ "script": "x = 1:10;\nplot(x, x.^2);", "isFile": false }
-
execute_matlab_section
{ "filePath": "analysis.m", "sectionStart": 1, "sectionEnd": 10 }
-
debug_matlab_script
{ "script": "debug_script.m", "breakpoints": [5, 10, 15] }
The tool creates an output
directory in the current working directory to store:
- Plot images generated during script execution
- Debug output files
- Other temporary files
- Script execution errors are captured and returned with detailed error messages
- Workspace state is preserved even after errors
- Debug sessions are properly cleaned up
- Fork the repository
- Create a feature branch
- Submit a pull request
BSD-3-Clause