Skip to content

neuromechanist/matlab-mcp-tools

Repository files navigation

MATLAB MCP Tool

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.

Prerequisites

  • Python 3.8+
  • MATLAB with Python Engine installed
  • MCP SDK for Python (pip install modelcontextprotocol)
  • MATLAB Engine for Python (pip install matlabengine)

Features

  1. Execute MATLAB Scripts

    • Run complete MATLAB scripts
    • Execute individual script sections
    • Maintain workspace context between executions
    • Capture and display plots
  2. Interactive Debugging

    • Set breakpoints in MATLAB scripts
    • Debug script execution
    • Inspect workspace variables
  3. Section-based Execution

    • Execute specific sections of MATLAB files
    • Support for cell mode (%% delimited sections)
    • Maintain workspace context between sections

Installation

  1. Clone this repository:
git clone [repository-url]
cd matlab-mcp-tool
  1. Create and activate a conda environment:
conda create -n matlab-mcp python=3.8
conda activate matlab-mcp
  1. Install dependencies:
pip install modelcontextprotocol matlabengine

Usage

  1. Start the MCP server:
python src/matlab_bridge.py
  1. 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"
      }
    }
  }
}
  1. 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]
    }

Output Directory

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

Error Handling

  • Script execution errors are captured and returned with detailed error messages
  • Workspace state is preserved even after errors
  • Debug sessions are properly cleaned up

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

License

BSD-3-Clause

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published