Skip to main content

An MCP server for allowing LLMs to interact with MATLAB and Simulink

Project description

MATLAB Simulink MCP Server

This Model Context Protocol (MCP) server lets MCP clients (such as Claude Desktop or other LLM-based agents) to interact with MATLAB and Simulink in real time. It runs locally, is built on FastMCP 2.0, and communicates with MATLAB and Simulink via the MATLAB Engine for Python API.

Features

  • Allows an LLM client to

    • Read, write, and execute MATLAB code and scripts
    • Parse and interact with Simulink models
    • Access workspace and results (inculding visualizations)
  • Execution Safety

    • Basic safeguards against unsafe commands
    • Restricted to current working directory (only manually changeable)
  • Robust Runtime

    • Non-blocking execution (asyncronous MATLAB engine calls)
    • Automatic installation of MATLAB Engine library if unavailable

Requirements

  • MATLAB R2022b or later
  • Python 3.10–3.12 (check which version is supported by your MATLAB installation)

Installation

  1. Create and activate a Python virtual environment (uv is recommended, automatically installs Python version if missing):

    uv venv --python 3.12           # match Python to your MATLAB-supported version
    source .venv/Scripts/activate   # on macOS/Linux: source .venv/bin/activate
    

    Without uv, you will first need to download and install the required Python version manually:

    python3.12 -m venv .venv        # match Python to your MATLAB-supported version
    source .venv/Scripts/activate   # on macOS/Linux: source .venv/bin/activate
    
  2. Install:

    uv pip install matlab-simulink-mcp
    # or without uv
    pip install matlab-simulink-mcp
    
  3. On the first run, if MATLAB Engine is not found, the server will open a console window and guide you through installation.

Configuration

Claude Desktop

  1. Open Claude Desktop Settings → Developer → Edit Config.

  2. In the claude_desktop_config.json, add or update:

    {
    "mcpServers": {
        "MATLAB_Simulink_MCP": {
            "command": "<absolute-path-to>/.venv/Scripts/python.exe", // absolute path to your Python environment executable
            "args": [
                "-m", 
                "matlab_simulink_mcp"
                ],
            "env": {
                "LOG_DIR": "<absolute-path-to>/logs" // Optional: absolute path to a folder for logs
                }
            }
        }
    }
    
  3. Save and restart Claude Desktop. (Ensure it is fully closed in Task Manager/Activity Monitor.)

  4. Server's status can be checked from Settings → Developer, or the equalizer button in Claude's chat box.

Claude Code / Codex CLI

  1. Run the following command in terminal:

    claude mcp add MATLAB_Simulink_MCP --env LOG_DIR="<absolute-path-to>/logs" -- "<absolute-path-to>/.venv/bin/python" -m matlab_simulink_mcp
    

    For Codex CLI, use codex instead of claude.

  2. Restart by opening a new terminal.

  3. To check server status, run claude mcp list or codex mcp list.

For more information, see documentation for Claude Code or Codex CLI.

Notes

  1. On macOS/Linux, use <absolute-path-to>/.venv/bin/python instead for the path to Python.

  2. Only use / or \\ in the paths, not \.

  3. On first launch, the server may open multiple consoles to install MATLAB Engine. Interact with one, complete installation, then restart the application if needed.

  4. Any client is restricted to the current MATLAB working directory, which can only be changed manually for safety reasons.

  5. The server logs outputs and errors its own log file as well. To keep a log file tracking console open, add "--console" to config args. The log file is in the folder specified via environment variable LOG_DIR, or otherwise in the user log directory.

Debugging

FastMCP 2.0 includes an MCP Inspector for manual testing and debugging without an LLM client. It launches a web UI to send dummy requests directly to the server. The inspector finds and runs a server object named mcp itself. So you will need to import matlab_simulink_mcp.server.mcp as mcp in a script and then run it:

fastmcp dev script_name.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matlab_simulink_mcp-0.1.6.tar.gz (74.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matlab_simulink_mcp-0.1.6-py3-none-any.whl (76.3 kB view details)

Uploaded Python 3

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page