matlab-simulink-mcp 0.1.0__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. matlab_simulink_mcp-0.1.2/LICENSE +21 -0
  2. matlab_simulink_mcp-0.1.2/PKG-INFO +95 -0
  3. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/README.md +16 -16
  4. matlab_simulink_mcp-0.1.2/README_pypi.md +73 -0
  5. matlab_simulink_mcp-0.1.2/pyproject.toml +52 -0
  6. matlab_simulink_mcp-0.1.2/src/matlab_simulink_mcp/data/helpers/describe_system.m +64 -0
  7. matlab_simulink_mcp-0.1.2/src/matlab_simulink_mcp/data/helpers/format_system.m +21 -0
  8. matlab_simulink_mcp-0.1.2/src/matlab_simulink_mcp/data/helpers/get_images.m +14 -0
  9. matlab_simulink_mcp-0.1.2/src/matlab_simulink_mcp/data/helpers/get_ports_connections.m +124 -0
  10. matlab_simulink_mcp-0.1.2/src/matlab_simulink_mcp/data/helpers/snapshot_system.m +18 -0
  11. matlab_simulink_mcp-0.1.2/src/matlab_simulink_mcp/data/helpers/validate_code.m +2 -0
  12. matlab_simulink_mcp-0.1.2/src/matlab_simulink_mcp.egg-info/PKG-INFO +95 -0
  13. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp.egg-info/SOURCES.txt +8 -0
  14. matlab_simulink_mcp-0.1.0/PKG-INFO +0 -169
  15. matlab_simulink_mcp-0.1.0/pyproject.toml +0 -33
  16. matlab_simulink_mcp-0.1.0/src/matlab_simulink_mcp.egg-info/PKG-INFO +0 -169
  17. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/setup.cfg +0 -0
  18. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/__init__.py +0 -0
  19. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/__main__.py +0 -0
  20. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/data/__init__.py +0 -0
  21. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/data/blacklist.txt +0 -0
  22. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/data/simlib_db.json +0 -0
  23. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/functions.py +0 -0
  24. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/installer/__init__.py +0 -0
  25. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/installer/installer.py +0 -0
  26. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/installer/launcher.py +0 -0
  27. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/installer/win_elevate.py +0 -0
  28. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/log_utils.py +0 -0
  29. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/security.py +0 -0
  30. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/server.py +0 -0
  31. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp/state.py +0 -0
  32. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp.egg-info/dependency_links.txt +0 -0
  33. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp.egg-info/entry_points.txt +0 -0
  34. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp.egg-info/requires.txt +0 -0
  35. {matlab_simulink_mcp-0.1.0 → matlab_simulink_mcp-0.1.2}/src/matlab_simulink_mcp.egg-info/top_level.txt +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Rohail Malik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.4
2
+ Name: matlab-simulink-mcp
3
+ Version: 0.1.2
4
+ Summary: An MCP server for allowing LLMs to interact with MATLAB and Simulink
5
+ Author: Rohail
6
+ License: MIT
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Scientific/Engineering
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: <3.13,>=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: fastmcp>=2.12.2
20
+ Requires-Dist: platformdirs>=4.4.0
21
+ Dynamic: license-file
22
+
23
+ # MATLAB Simulink MCP Server
24
+
25
+ This Model Context Protocol (MCP) server allows 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 top of the [FastMCP 2.0](https://gofastmcp.com/getting-started/welcome) library, and uses MATLAB Engine for Python API to communicate with MATLAB and Simulink.
26
+
27
+ ## Features
28
+
29
+ - Read, write, and run MATLAB code and scripts
30
+ - Parse and interact with Simulink files
31
+ - Access MATLAB workspace variables and outputs (including visualizations)
32
+ - Basic safety layer to prevent execution of unsafe commands (configurable)
33
+ - Non-blocking execution (async MATLAB engine calls)
34
+ - Automatic installation of MATLAB Engine package if unavailable
35
+
36
+ ## Requirements
37
+
38
+ - **MATLAB** R2022b or later
39
+ - **Python** 3.10–3.12 (check MATLAB's [supported versions](https://www.mathworks.com/support/requirements/python-compatibility.html))
40
+
41
+ ## Installation
42
+
43
+ 1. Install using:
44
+
45
+ ```bash
46
+ uv pip install matlab-simulink-mcp
47
+ # or
48
+ pip install matlab-simulink-mcp
49
+ ```
50
+
51
+ 2. On the first run, if the MATLAB Engine is not installed, the server will open a console window and guide you through installation.
52
+
53
+ - This requires admin permission and the server will request for it.
54
+ - If you prefer to install manually, install a [matching PyPi version](https://pypi.org/project/matlabengine/#history) or from your [MATLAB installation](https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html).
55
+
56
+ ## Configuration (Claude Desktop)
57
+
58
+ 1. Install [Claude Desktop](https://claude.ai/download).
59
+
60
+ 2. Open Settings → Developer → Edit Config.
61
+
62
+ 3. In the `claude_desktop_config.json`, add or update:
63
+
64
+ ```json
65
+ {
66
+ "mcpServers": {
67
+ "MATLAB_Simulink_MCP": {
68
+ "command": "absolute-path-to/.venv/Scripts/python.exe", // absolute path to your venv/global environment executable
69
+ "args": ["-m", "matlab_simulink_mcp"]
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ On macOS/Linux, use `absolute-path-to/.venv/bin/python` in `command`.
76
+
77
+ **Note**: Only use `/` or `\\` in the paths, not `\`.
78
+
79
+ 4. Save and restart Claude Desktop. (Ensure it is fully closed in Task Manager/Activity Monitor.)
80
+
81
+ 5. On first launch, the server may open multiple consoles to install MATLAB Engine. Interact with one, complete installation, then restart Claude if needed.
82
+
83
+ 6. Check running status in Settings → Developer, or click the equalizer button in Claude's chat box.
84
+
85
+ 7. The server logs outputs and errors to both Claude's and its own log file. To keep a log file tracking console open, add `--console` in Claude config args.
86
+
87
+ - Claude MCP logs (Windows): `%APPDATA%\Claude\logs\mcp-server-MatlabMCP.log`
88
+ - Claude MCP logs (macOS): `~/Library/Logs/Claude/mcp-server-MatlabMCP.log`
89
+ - Server logs: written to your user log directory (or configured via `.env`).
90
+
91
+ ## Debugging
92
+
93
+ FastMCP 2.0 includes an MCP Inspector for manual testing without an LLM client. It launches a UI to send dummy requests directly to the server.
94
+
95
+ To use it, import `mcp` from `matlab_simulink_mcp.server` into a script and run the script using `fastmcp dev script_name.py`
@@ -3,7 +3,7 @@
3
3
  [![PyPI version](https://img.shields.io/pypi/v/matlab-simulink-mcp.svg)](https://pypi.org/project/matlab-simulink-mcp/)
4
4
  [![Python versions](https://img.shields.io/pypi/pyversions/matlab-simulink-mcp.svg)](https://pypi.org/project/matlab-simulink-mcp/)
5
5
 
6
- This [Model Context Protocol (MCP)](https://github.com/modelcontextprotocol) server allows MCP clients (such as Claude Desktop or other LLM-based agents) to interact with **MATLAB** and **Simulink** in real time. It runs locally and is built on top of the [FastMCP 2.0](https://gofastmcp.com/getting-started/welcome) library.
6
+ This Model Context Protocol (MCP) server allows 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 top of the [FastMCP 2.0](https://gofastmcp.com/getting-started/welcome) library, and uses MATLAB Engine for Python API to communicate with MATLAB and Simulink.
7
7
 
8
8
  ## Features
9
9
 
@@ -33,7 +33,7 @@ If you don’t want to interact with Python at all, you can download a prebuilt
33
33
  git clone https://github.com/rohailamalik/matlab-simulink-mcp
34
34
  cd matlab-simulink-mcp
35
35
 
36
- 2. Create a Python virtual environment (recommended: [uv](https://pypi.org/project/uv/0.1.32/)):
36
+ 2. Create a Python virtual environment ([uv](https://pypi.org/project/uv/0.1.32/) is recommended):
37
37
 
38
38
  ```bash
39
39
  uv venv --python 3.12 # match Python to your MATLAB-supported version
@@ -41,11 +41,11 @@ If you don’t want to interact with Python at all, you can download a prebuilt
41
41
  uv sync
42
42
  ```
43
43
 
44
- Without uv, first download a Python version manually:
44
+ Without uv, first download a Python version manually, then run:
45
45
 
46
46
  ```bash
47
- python3.12 -m venv .venv
48
- source .venv/bin/activate
47
+ python3.12 -m venv .venv # match Python to your MATLAB-supported version
48
+ source .venv/Scripts/activate # on macOS/Linux: source .venv/bin/activate
49
49
  pip install -r requirements.txt
50
50
  pip install .
51
51
  ```
@@ -58,7 +58,7 @@ If you don’t want to interact with Python at all, you can download a prebuilt
58
58
  pip install matlab-simulink-mcp
59
59
  ```
60
60
 
61
- 4. On first run, if the MATLAB Engine is not installed, the server will open a console window and guide you through installation.
61
+ 4. On the first run, if the MATLAB Engine is not installed, the server will open a console window and guide you through installation.
62
62
 
63
63
  - This requires admin permission and the server will request for it.
64
64
  - If you prefer to install manually, install a [matching PyPi version](https://pypi.org/project/matlabengine/#history) or from your [MATLAB installation](https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html).
@@ -75,7 +75,7 @@ If you don’t want to interact with Python at all, you can download a prebuilt
75
75
  {
76
76
  "mcpServers": {
77
77
  "MATLAB_Simulink_MCP": {
78
- "command": "C:/Data/Research/Doctoral/src/matlab-simulink-mcp/.venv/Scripts/python.exe",
78
+ "command": "absolute-path-to/.venv/Scripts/python.exe", // absolute path to your venv/global environment executable
79
79
  "args": ["-m", "matlab_simulink_mcp"]
80
80
  }
81
81
  }
@@ -92,7 +92,7 @@ If you don’t want to interact with Python at all, you can download a prebuilt
92
92
 
93
93
  5. On first launch, the server may open multiple consoles to install MATLAB Engine. Interact with one, complete installation, then restart Claude if needed.
94
94
 
95
- 6. Check running status in Settings → Developer, or click the equalizer button in the chat box.
95
+ 6. Check running status in Settings → Developer, or click the equalizer button in Claude's chat box.
96
96
 
97
97
  7. The server logs outputs and errors to both Claude's and its own log file. To keep a log file tracking console open, add `--console` in Claude config args.
98
98
 
@@ -102,7 +102,7 @@ If you don’t want to interact with Python at all, you can download a prebuilt
102
102
 
103
103
  ## Debugging
104
104
 
105
- FastMCP 2.0 includes an MCP Inspector for manual testing without an LLM client. This launches a UI to send dummy requests directly to the server.
105
+ FastMCP 2.0 includes an MCP Inspector for manual testing without an LLM client. It launches a UI to send dummy requests directly to the server.
106
106
 
107
107
  ```bash
108
108
  cd scripts
@@ -138,17 +138,17 @@ matlab-simulink-mcp/
138
138
 
139
139
  ## FAQ
140
140
 
141
- Q: Which Python version should I install?
142
-
143
- A: Match it to the highest Python version supported by your MATLAB release (see MathWorks docs).
141
+ - Q: Which Python version should I install?
142
+
143
+ - A: Match it to the highest Python version supported by your MATLAB release (see MathWorks docs).
144
144
 
145
- Q: The console disappears too quickly!
145
+ - Q: The console disappears too quickly!
146
146
 
147
- A: Add `--console` in your Claude config args to keep the server console open.
147
+ - A: Add `--console` in your Claude config args to keep the server console open.
148
148
 
149
- Q: Multiple installer consoles opened on first run.
149
+ - Q: Multiple installer consoles opened on first run.
150
150
 
151
- A: This is expected if Claude sends multiple startup requests. Complete one installation, then restart Claude Desktop.
151
+ - A: This is expected if Claude sends multiple startup requests. Complete one installation, then restart Claude Desktop.
152
152
 
153
153
  ## Contributing
154
154
 
@@ -0,0 +1,73 @@
1
+ # MATLAB Simulink MCP Server
2
+
3
+ This Model Context Protocol (MCP) server allows 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 top of the [FastMCP 2.0](https://gofastmcp.com/getting-started/welcome) library, and uses MATLAB Engine for Python API to communicate with MATLAB and Simulink.
4
+
5
+ ## Features
6
+
7
+ - Read, write, and run MATLAB code and scripts
8
+ - Parse and interact with Simulink files
9
+ - Access MATLAB workspace variables and outputs (including visualizations)
10
+ - Basic safety layer to prevent execution of unsafe commands (configurable)
11
+ - Non-blocking execution (async MATLAB engine calls)
12
+ - Automatic installation of MATLAB Engine package if unavailable
13
+
14
+ ## Requirements
15
+
16
+ - **MATLAB** R2022b or later
17
+ - **Python** 3.10–3.12 (check MATLAB's [supported versions](https://www.mathworks.com/support/requirements/python-compatibility.html))
18
+
19
+ ## Installation
20
+
21
+ 1. Install using:
22
+
23
+ ```bash
24
+ uv pip install matlab-simulink-mcp
25
+ # or
26
+ pip install matlab-simulink-mcp
27
+ ```
28
+
29
+ 2. On the first run, if the MATLAB Engine is not installed, the server will open a console window and guide you through installation.
30
+
31
+ - This requires admin permission and the server will request for it.
32
+ - If you prefer to install manually, install a [matching PyPi version](https://pypi.org/project/matlabengine/#history) or from your [MATLAB installation](https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html).
33
+
34
+ ## Configuration (Claude Desktop)
35
+
36
+ 1. Install [Claude Desktop](https://claude.ai/download).
37
+
38
+ 2. Open Settings → Developer → Edit Config.
39
+
40
+ 3. In the `claude_desktop_config.json`, add or update:
41
+
42
+ ```json
43
+ {
44
+ "mcpServers": {
45
+ "MATLAB_Simulink_MCP": {
46
+ "command": "absolute-path-to/.venv/Scripts/python.exe", // absolute path to your venv/global environment executable
47
+ "args": ["-m", "matlab_simulink_mcp"]
48
+ }
49
+ }
50
+ }
51
+ ```
52
+
53
+ On macOS/Linux, use `absolute-path-to/.venv/bin/python` in `command`.
54
+
55
+ **Note**: Only use `/` or `\\` in the paths, not `\`.
56
+
57
+ 4. Save and restart Claude Desktop. (Ensure it is fully closed in Task Manager/Activity Monitor.)
58
+
59
+ 5. On first launch, the server may open multiple consoles to install MATLAB Engine. Interact with one, complete installation, then restart Claude if needed.
60
+
61
+ 6. Check running status in Settings → Developer, or click the equalizer button in Claude's chat box.
62
+
63
+ 7. The server logs outputs and errors to both Claude's and its own log file. To keep a log file tracking console open, add `--console` in Claude config args.
64
+
65
+ - Claude MCP logs (Windows): `%APPDATA%\Claude\logs\mcp-server-MatlabMCP.log`
66
+ - Claude MCP logs (macOS): `~/Library/Logs/Claude/mcp-server-MatlabMCP.log`
67
+ - Server logs: written to your user log directory (or configured via `.env`).
68
+
69
+ ## Debugging
70
+
71
+ FastMCP 2.0 includes an MCP Inspector for manual testing without an LLM client. It launches a UI to send dummy requests directly to the server.
72
+
73
+ To use it, import `mcp` from `matlab_simulink_mcp.server` into a script and run the script using `fastmcp dev script_name.py`
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "matlab-simulink-mcp"
7
+ version = "0.1.2"
8
+ description = "An MCP server for allowing LLMs to interact with MATLAB and Simulink"
9
+ authors = [
10
+ { name = "Rohail"}
11
+ ]
12
+ license = { text = "MIT" }
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Topic :: Scientific/Engineering",
22
+ "Topic :: Software Development :: Libraries :: Python Modules"
23
+ ]
24
+ readme = { file = "README_pypi.md", content-type = "text/markdown" }
25
+ requires-python = ">=3.10,<3.13"
26
+ dependencies = [
27
+ "fastmcp>=2.12.2",
28
+ "platformdirs>=4.4.0",
29
+ ]
30
+
31
+ [tool.setuptools]
32
+ include-package-data = true
33
+
34
+ [tool.setuptools.packages.find]
35
+ where = ["src"]
36
+
37
+ [tool.setuptools.package-data]
38
+ "matlab_simulink_mcp" = ["data/*.txt", "data/*.json", "data/helpers/*.m"]
39
+
40
+ [project.scripts]
41
+ matlab_simulink_mcp = "matlab_simulink_mcp.__main__:main"
42
+
43
+ [[tool.uv.index]]
44
+ name = "pypi"
45
+ url = "https://pypi.org/simple"
46
+ publish-url = "https://upload.pypi.org/legacy/"
47
+
48
+ [[tool.uv.index]]
49
+ name = "testpypi"
50
+ url = "https://test.pypi.org/simple"
51
+ publish-url = "https://test.pypi.org/legacy/"
52
+
@@ -0,0 +1,64 @@
1
+ function system_data = describe_system(system_path, main_system, open)
2
+
3
+ % This function returns the information about a system layout as a JSON.
4
+ % It's still problematic with Simscape because some blocks such as
5
+ % SolverConfiguration and PS-Simulink Convertor are defined internally as
6
+ % SubSystems instead of Simscape blocks.
7
+
8
+ load_system(main_system)
9
+
10
+ if open
11
+ open_system(system_path);
12
+ end
13
+
14
+ blocks = find_system(system_path, 'SearchDepth', 1, 'Type', 'Block');
15
+
16
+ elements = {};
17
+ connections = {};
18
+
19
+ for i = 1:length(blocks)
20
+
21
+ blk = blocks{i};
22
+
23
+ if strcmp(blk, system_path) % Skips the subsystem itself if it is being asked for
24
+ continue;
25
+ end
26
+
27
+ blk_source = get_param(blk, 'ReferenceBlock');
28
+
29
+ element = struct();
30
+ element.Name = get_param(blk, 'Name');
31
+ element.Type = get_param(blk, 'BlockType');
32
+
33
+ if blk_source ~= ""
34
+ element.Source = blk_source;
35
+ end
36
+
37
+ if ~strcmp(element.Type, "SimscapeBlock") && ~strcmp(element.Type, "SubSystem") && ~contains("Port", "port", 'IgnoreCase', true)
38
+ % It's a built-in simulink block
39
+ if blk_source ~= ""
40
+ element.Source = ['built-in/' element.Type];
41
+ end
42
+ element.Type = "Block";
43
+
44
+ end
45
+
46
+ [inports, outports, simscapeports, connects] = get_ports_connections(blk, element.Name, element.Type);
47
+
48
+ if ~isempty(inports), element.Inports = inports; end
49
+ if ~isempty(outports), element.Outports = outports; end
50
+ if ~isempty(simscapeports), element.SimscapePorts = simscapeports; end
51
+ if ~isempty(connects), connections = [connections, connects]; end
52
+
53
+ elements{end+1} = element;
54
+
55
+ end
56
+
57
+ system = struct();
58
+ system.Elements = elements;
59
+ system.Connections = connections;
60
+
61
+ %system_data = jsonencode(system);
62
+ system_data = system;
63
+
64
+ end
@@ -0,0 +1,21 @@
1
+ function format_system()
2
+ %function result = format_system(system_path, main_system, arrange)
3
+ %load_system(main_system)
4
+
5
+ %if arrange
6
+ % Simulink.BlockDiagram.arrangeSystem(system_path);
7
+ %end
8
+
9
+ systems = find_system('type','block_diagram');
10
+
11
+ for i = 1:numel(systems)
12
+ sys = systems{i};
13
+ hLines = find_system(sys, 'FindAll', 'on', 'Type', 'line', 'Connected', 'off');
14
+ delete_line(hLines);
15
+ end
16
+
17
+ %hLines = find_system(system_path, 'SearchDepth', 1, 'FindAll', 'on', 'Type', 'Line', 'Connected', 'off');
18
+ %delete_line(hLines);
19
+ %result = "Success";
20
+
21
+
@@ -0,0 +1,14 @@
1
+ function cwds = get_images()
2
+ figs = findall(0, 'type', 'figure');
3
+ num = numel(figs);
4
+ if num == 0
5
+ cwds = {};
6
+ else
7
+ cwds = cell(1, num);
8
+ for k = 1:num
9
+ filename = sprintf('temp_plot_%d.png', k);
10
+ saveas(figs(k), filename);
11
+ cwds{k} = fullfile(pwd, filename);
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,124 @@
1
+ function [inports, outports, simscapeports, connections] = get_ports_connections(blk, blk_name, blk_type)
2
+
3
+ % This function gets, for a given block, its name and type, the names (if
4
+ % it's a subsystem) and tags of its ports and connections.
5
+
6
+ inports = {};
7
+ outports = {};
8
+ simscapeports = {};
9
+ connections = {};
10
+
11
+ is_subsystem = strcmp(blk_type, 'SubSystem');
12
+ PC = get_param(blk, 'PortConnectivity');
13
+
14
+ % First create a list of the port names. Unfortunately, this is only
15
+ % possible for subsystems since only port blocks can have names, not ports themselves
16
+
17
+ % For non-Simscape port blocks, the order through find_system is the
18
+ % same as the ports in PortConnectivity matrix
19
+
20
+ % For Simscape port blocks, the order through find_system is based on the
21
+ % number of the port (displayed visually at the center of PortConnection block)
22
+ % But in PortConnectivity matrix, the ports on Left are listed first and then right
23
+ % Within each type, the order follows the visual number of the port
24
+ % So we first get port blocks on left, and then right, and then concenate all of them
25
+
26
+ if is_subsystem
27
+
28
+ SimulinkPortBlks = find_system(blk, 'Regexp', 'on', 'BlockType', ...
29
+ 'Inport|Outport|EnablePort|TriggerPort|ResetPort|ActionPort');
30
+
31
+ PhyPortBlksLefts = find_system(blk, 'Regexp', 'on', 'BlockType', 'PMIOPort', 'Side', 'Left');
32
+ PhyPortBlksRights = find_system(blk, 'Regexp', 'on', 'BlockType', 'PMIOPort', 'Side', 'Right');
33
+
34
+ PortBlks = [SimulinkPortBlks(:); PhyPortBlksLefts(:); PhyPortBlksRights(:)];
35
+ PortNames = get_param(PortBlks, 'Name');
36
+
37
+ if isempty(PortNames)
38
+ is_subsystem = 0;
39
+ end
40
+
41
+ end
42
+
43
+ % Some Simscape blocks e.g. PS-Simulink Convertor are defined internally as
44
+ % SubSystems instead of Simscape blocks. So the if condition above ensures
45
+ % that if such blocks are counted as subsystems and port names gathered
46
+ % (which would be empty), we flag the block manually as not a subsystem
47
+
48
+ % Loop through the ports. For each port, create a strcuture with tag and
49
+ % name (if the element is a subsystem) fields
50
+ % For connections, first get the Simscape ports (i.e. LConnX and % RConnX).
51
+ % For these ports, DstPort contains the handle of the attached port. So we
52
+ % get the DstBlock's PortHandles through its handle, and then get its tag
53
+ % For non-simscape ports, the DstPort contains -1 the field index of the
54
+ % attached port in the DstBlock's PortConnectivity matrix.
55
+ % Also, only consider outports for these ports as they are easily
56
+ % distinguishable through an empty SrcBlock. For inports, the connections
57
+ % will be gathered when the script is ran for the connected block. This
58
+ % also prevents repitition. Inports also include ports such as trigger etc
59
+
60
+ for i = 1:length(PC)
61
+
62
+ Port = PC(i).Type;
63
+ PortStr = struct('tag', Port);
64
+ if is_subsystem
65
+ try
66
+ PortStr.name = PortNames{i};
67
+ catch
68
+ end
69
+ end
70
+
71
+ if contains(Port, {'LConn', 'RConn'})
72
+
73
+ simscapeports{end+1} = PortStr;
74
+
75
+ for j = 1:length(PC(i).DstBlock)
76
+
77
+ DstBlockHandle = PC(i).DstBlock(j);
78
+ DstBlockName = get_param(DstBlockHandle, 'Name');
79
+
80
+ DstPortHandle = PC(i).DstPort(j);
81
+ DstPH = get_param(DstBlockHandle, 'PortHandles');
82
+
83
+ idxL = find(DstPH.LConn == DstPortHandle, 1);
84
+ idxR = find(DstPH.RConn == DstPortHandle, 1);
85
+
86
+ if ~isempty(idxL)
87
+ DstPort = sprintf('LConn%d', idxL);
88
+ else
89
+ DstPort = sprintf('RConn%d', idxR);
90
+ end
91
+
92
+ connections{end+1} = struct('from', sprintf("%s/%s", blk_name, Port), ...
93
+ 'to', sprintf("%s/%s", DstBlockName, DstPort));
94
+
95
+ end
96
+
97
+ else
98
+
99
+ if isempty(PC(i).SrcBlock)
100
+
101
+ outports{end+1} = PortStr;
102
+
103
+ for j = 1:length(PC(i).DstBlock)
104
+
105
+ DstBlockHandle = PC(i).DstBlock(j);
106
+ DstBlockName = get_param(DstBlockHandle, 'Name');
107
+
108
+ DstPortField = PC(i).DstPort(j) + 1;
109
+ DstPC = get_param(DstBlockHandle, 'PortConnectivity');
110
+ DstPort = DstPC(DstPortField).Type;
111
+
112
+ connections{end+1} = struct('from', sprintf("%s/%s", blk_name, Port), ...
113
+ 'to', sprintf("%s/%s", DstBlockName, DstPort));
114
+
115
+ end
116
+
117
+ else
118
+
119
+ inports{end+1} = PortStr;
120
+
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,18 @@
1
+ function cwd = snapshot_system(system_path, main_system, open)
2
+
3
+ load_system(main_system)
4
+
5
+ if open
6
+ open_system(system_path);
7
+ end
8
+
9
+ dpi = '150';
10
+ path = "-s" + system_path;
11
+ quality = "-r" + dpi;
12
+ file = "snapshot.png";
13
+
14
+ print(path, "-dpng", quality, file);
15
+
16
+ cwd = fullfile(pwd, 'snapshot.png');
17
+
18
+ end
@@ -0,0 +1,2 @@
1
+ function issues = validate_script(file_name)
2
+ issues = {checkcode(file_name).message};
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.4
2
+ Name: matlab-simulink-mcp
3
+ Version: 0.1.2
4
+ Summary: An MCP server for allowing LLMs to interact with MATLAB and Simulink
5
+ Author: Rohail
6
+ License: MIT
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Scientific/Engineering
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: <3.13,>=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: fastmcp>=2.12.2
20
+ Requires-Dist: platformdirs>=4.4.0
21
+ Dynamic: license-file
22
+
23
+ # MATLAB Simulink MCP Server
24
+
25
+ This Model Context Protocol (MCP) server allows 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 top of the [FastMCP 2.0](https://gofastmcp.com/getting-started/welcome) library, and uses MATLAB Engine for Python API to communicate with MATLAB and Simulink.
26
+
27
+ ## Features
28
+
29
+ - Read, write, and run MATLAB code and scripts
30
+ - Parse and interact with Simulink files
31
+ - Access MATLAB workspace variables and outputs (including visualizations)
32
+ - Basic safety layer to prevent execution of unsafe commands (configurable)
33
+ - Non-blocking execution (async MATLAB engine calls)
34
+ - Automatic installation of MATLAB Engine package if unavailable
35
+
36
+ ## Requirements
37
+
38
+ - **MATLAB** R2022b or later
39
+ - **Python** 3.10–3.12 (check MATLAB's [supported versions](https://www.mathworks.com/support/requirements/python-compatibility.html))
40
+
41
+ ## Installation
42
+
43
+ 1. Install using:
44
+
45
+ ```bash
46
+ uv pip install matlab-simulink-mcp
47
+ # or
48
+ pip install matlab-simulink-mcp
49
+ ```
50
+
51
+ 2. On the first run, if the MATLAB Engine is not installed, the server will open a console window and guide you through installation.
52
+
53
+ - This requires admin permission and the server will request for it.
54
+ - If you prefer to install manually, install a [matching PyPi version](https://pypi.org/project/matlabengine/#history) or from your [MATLAB installation](https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html).
55
+
56
+ ## Configuration (Claude Desktop)
57
+
58
+ 1. Install [Claude Desktop](https://claude.ai/download).
59
+
60
+ 2. Open Settings → Developer → Edit Config.
61
+
62
+ 3. In the `claude_desktop_config.json`, add or update:
63
+
64
+ ```json
65
+ {
66
+ "mcpServers": {
67
+ "MATLAB_Simulink_MCP": {
68
+ "command": "absolute-path-to/.venv/Scripts/python.exe", // absolute path to your venv/global environment executable
69
+ "args": ["-m", "matlab_simulink_mcp"]
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ On macOS/Linux, use `absolute-path-to/.venv/bin/python` in `command`.
76
+
77
+ **Note**: Only use `/` or `\\` in the paths, not `\`.
78
+
79
+ 4. Save and restart Claude Desktop. (Ensure it is fully closed in Task Manager/Activity Monitor.)
80
+
81
+ 5. On first launch, the server may open multiple consoles to install MATLAB Engine. Interact with one, complete installation, then restart Claude if needed.
82
+
83
+ 6. Check running status in Settings → Developer, or click the equalizer button in Claude's chat box.
84
+
85
+ 7. The server logs outputs and errors to both Claude's and its own log file. To keep a log file tracking console open, add `--console` in Claude config args.
86
+
87
+ - Claude MCP logs (Windows): `%APPDATA%\Claude\logs\mcp-server-MatlabMCP.log`
88
+ - Claude MCP logs (macOS): `~/Library/Logs/Claude/mcp-server-MatlabMCP.log`
89
+ - Server logs: written to your user log directory (or configured via `.env`).
90
+
91
+ ## Debugging
92
+
93
+ FastMCP 2.0 includes an MCP Inspector for manual testing without an LLM client. It launches a UI to send dummy requests directly to the server.
94
+
95
+ To use it, import `mcp` from `matlab_simulink_mcp.server` into a script and run the script using `fastmcp dev script_name.py`
@@ -1,4 +1,6 @@
1
+ LICENSE
1
2
  README.md
3
+ README_pypi.md
2
4
  pyproject.toml
3
5
  src/matlab_simulink_mcp/__init__.py
4
6
  src/matlab_simulink_mcp/__main__.py
@@ -16,6 +18,12 @@ src/matlab_simulink_mcp.egg-info/top_level.txt
16
18
  src/matlab_simulink_mcp/data/__init__.py
17
19
  src/matlab_simulink_mcp/data/blacklist.txt
18
20
  src/matlab_simulink_mcp/data/simlib_db.json
21
+ src/matlab_simulink_mcp/data/helpers/describe_system.m
22
+ src/matlab_simulink_mcp/data/helpers/format_system.m
23
+ src/matlab_simulink_mcp/data/helpers/get_images.m
24
+ src/matlab_simulink_mcp/data/helpers/get_ports_connections.m
25
+ src/matlab_simulink_mcp/data/helpers/snapshot_system.m
26
+ src/matlab_simulink_mcp/data/helpers/validate_code.m
19
27
  src/matlab_simulink_mcp/installer/__init__.py
20
28
  src/matlab_simulink_mcp/installer/installer.py
21
29
  src/matlab_simulink_mcp/installer/launcher.py
@@ -1,169 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: matlab-simulink-mcp
3
- Version: 0.1.0
4
- Summary: An MCP server for allowing LLMs to interact with MATLAB and Simulink
5
- Author: Rohail
6
- License: MIT
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Requires-Python: <3.13,>=3.10
11
- Description-Content-Type: text/markdown
12
- Requires-Dist: fastmcp>=2.12.2
13
- Requires-Dist: platformdirs>=4.4.0
14
-
15
- # MATLAB Simulink MCP Server
16
-
17
- [![PyPI version](https://img.shields.io/pypi/v/matlab-simulink-mcp.svg)](https://pypi.org/project/matlab-simulink-mcp/)
18
- [![Python versions](https://img.shields.io/pypi/pyversions/matlab-simulink-mcp.svg)](https://pypi.org/project/matlab-simulink-mcp/)
19
-
20
- This [Model Context Protocol (MCP)](https://github.com/modelcontextprotocol) server allows MCP clients (such as Claude Desktop or other LLM-based agents) to interact with **MATLAB** and **Simulink** in real time. It runs locally and is built on top of the [FastMCP 2.0](https://gofastmcp.com/getting-started/welcome) library.
21
-
22
- ## Features
23
-
24
- - Read, write, and run MATLAB code and scripts
25
- - Parse and interact with Simulink files
26
- - Access MATLAB workspace variables and outputs (including visualizations)
27
- - Basic safety layer to prevent execution of unsafe commands (configurable)
28
- - Non-blocking execution (async MATLAB engine calls)
29
- - Automatic installation of MATLAB Engine package if unavailable
30
-
31
- ## Requirements
32
-
33
- - **MATLAB** R2022b or later
34
- - **Python** 3.10–3.12 (check MATLAB's [supported versions](https://www.mathworks.com/support/requirements/python-compatibility.html))
35
-
36
- ## Installation
37
-
38
- ### Option 1 — Download Binary (MATLAB R2025a only)
39
-
40
- If you don’t want to interact with Python at all, you can download a prebuilt **exe/app** from the [Releases](../../releases) page and run it directly. In that case you can skip the steps below.
41
-
42
- ### Option 2 — From Source
43
-
44
- 1. Clone the repository:
45
-
46
- ```bash
47
- git clone https://github.com/rohailamalik/matlab-simulink-mcp
48
- cd matlab-simulink-mcp
49
-
50
- 2. Create a Python virtual environment (recommended: [uv](https://pypi.org/project/uv/0.1.32/)):
51
-
52
- ```bash
53
- uv venv --python 3.12 # match Python to your MATLAB-supported version
54
- source .venv/Scripts/activate # on macOS/Linux: source .venv/bin/activate
55
- uv sync
56
- ```
57
-
58
- Without uv, first download a Python version manually:
59
-
60
- ```bash
61
- python3.12 -m venv .venv
62
- source .venv/bin/activate
63
- pip install -r requirements.txt
64
- pip install .
65
- ```
66
-
67
- 3. Alternatively, skip step 1, create virtual environment and install directly via PyPI:
68
-
69
- ```bash
70
- uv pip install matlab-simulink-mcp
71
- # or
72
- pip install matlab-simulink-mcp
73
- ```
74
-
75
- 4. On first run, if the MATLAB Engine is not installed, the server will open a console window and guide you through installation.
76
-
77
- - This requires admin permission and the server will request for it.
78
- - If you prefer to install manually, install a [matching PyPi version](https://pypi.org/project/matlabengine/#history) or from your [MATLAB installation](https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html).
79
-
80
- ## Configuration (Claude Desktop)
81
-
82
- 1. Install [Claude Desktop](https://claude.ai/download).
83
-
84
- 2. Open Settings → Developer → Edit Config.
85
-
86
- 3. In the `claude_desktop_config.json`, add or update:
87
-
88
- ```json
89
- {
90
- "mcpServers": {
91
- "MATLAB_Simulink_MCP": {
92
- "command": "C:/Data/Research/Doctoral/src/matlab-simulink-mcp/.venv/Scripts/python.exe",
93
- "args": ["-m", "matlab_simulink_mcp"]
94
- }
95
- }
96
- }
97
- ```
98
-
99
- On macOS/Linux, use `absolute-path-to/.venv/bin/python` in `command`.
100
-
101
- If using the standalone exe/app, just put absolute path to it in `command` and omit args.
102
-
103
- **Note**: Only use `/` or `\\` in the paths, not `\`.
104
-
105
- 4. Save and restart Claude Desktop. (Ensure it is fully closed in Task Manager/Activity Monitor.)
106
-
107
- 5. On first launch, the server may open multiple consoles to install MATLAB Engine. Interact with one, complete installation, then restart Claude if needed.
108
-
109
- 6. Check running status in Settings → Developer, or click the equalizer button in the chat box.
110
-
111
- 7. The server logs outputs and errors to both Claude's and its own log file. To keep a log file tracking console open, add `--console` in Claude config args.
112
-
113
- - Claude MCP logs (Windows): `%APPDATA%\Claude\logs\mcp-server-MatlabMCP.log`
114
- - Claude MCP logs (macOS): `~/Library/Logs/Claude/mcp-server-MatlabMCP.log`
115
- - Server logs: written to your user log directory (or configured via `.env`).
116
-
117
- ## Debugging
118
-
119
- FastMCP 2.0 includes an MCP Inspector for manual testing without an LLM client. This launches a UI to send dummy requests directly to the server.
120
-
121
- ```bash
122
- cd scripts
123
- fastmcp dev debugger.py
124
- ```
125
-
126
- ## Repository Structure
127
-
128
- ```txt
129
-
130
- matlab-simulink-mcp/
131
- ├─ scripts
132
- │ ├─ debugger.py # Entry point for MCP inspector
133
- ├─ src/matlab_simulink_mcp/
134
- │ ├─ data/ # Data files and resources
135
- │ ├─ installer/ # MATLAB Engine installer
136
- │ │ ├─ installer.py
137
- │ │ ├─ launcher.py
138
- │ │ └─ win_elevate.py
139
- │ ├─ functions.py # Baseline MCP tool functions
140
- │ ├─ log_utils.py # Logging utilities
141
- │ ├─ security.py # Safety layer for code execution
142
- │ ├─ server.py # Main server script
143
- │ ├─ state.py # Server lifespan objects (logger, engine)
144
- │ ├─ __main__.py # Main entry point
145
- ├─ .env # Optional config (e.g. LOG_DIR)
146
- ├─ pyproject.toml # Project metadata and dependencies
147
- ├─ requirements.txt # Package dependencies for pip
148
- ├─ uv.lock # Package dependencies for uv
149
- └─ README.md # This file
150
-
151
- ```
152
-
153
- ## FAQ
154
-
155
- Q: Which Python version should I install?
156
-
157
- A: Match it to the highest Python version supported by your MATLAB release (see MathWorks docs).
158
-
159
- Q: The console disappears too quickly!
160
-
161
- A: Add `--console` in your Claude config args to keep the server console open.
162
-
163
- Q: Multiple installer consoles opened on first run.
164
-
165
- A: This is expected if Claude sends multiple startup requests. Complete one installation, then restart Claude Desktop.
166
-
167
- ## Contributing
168
-
169
- Pull requests are welcome! Feel free to submit one or open an issue.
@@ -1,33 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=61.0", "wheel"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "matlab-simulink-mcp"
7
- version = "0.1.0"
8
- description = "An MCP server for allowing LLMs to interact with MATLAB and Simulink"
9
- authors = [
10
- { name = "Rohail"}
11
- ]
12
- license = { text = "MIT" }
13
- classifiers = [
14
- "Programming Language :: Python :: 3",
15
- "License :: OSI Approved :: MIT License",
16
- "Operating System :: OS Independent"
17
- ]
18
-
19
- readme = { file = "README.md", content-type = "text/markdown" }
20
- requires-python = ">=3.10,<3.13"
21
- dependencies = [
22
- "fastmcp>=2.12.2",
23
- "platformdirs>=4.4.0",
24
- ]
25
-
26
- [tool.setuptools.packages.find]
27
- where = ["src"]
28
-
29
- [tool.setuptools.package-data]
30
- "matlab_simulink_mcp" = ["data/*.txt", "data/*.json", "data/helpers/*.py"]
31
-
32
- [project.scripts]
33
- matlab_simulink_mcp = "matlab_simulink_mcp.__main__:main"
@@ -1,169 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: matlab-simulink-mcp
3
- Version: 0.1.0
4
- Summary: An MCP server for allowing LLMs to interact with MATLAB and Simulink
5
- Author: Rohail
6
- License: MIT
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Requires-Python: <3.13,>=3.10
11
- Description-Content-Type: text/markdown
12
- Requires-Dist: fastmcp>=2.12.2
13
- Requires-Dist: platformdirs>=4.4.0
14
-
15
- # MATLAB Simulink MCP Server
16
-
17
- [![PyPI version](https://img.shields.io/pypi/v/matlab-simulink-mcp.svg)](https://pypi.org/project/matlab-simulink-mcp/)
18
- [![Python versions](https://img.shields.io/pypi/pyversions/matlab-simulink-mcp.svg)](https://pypi.org/project/matlab-simulink-mcp/)
19
-
20
- This [Model Context Protocol (MCP)](https://github.com/modelcontextprotocol) server allows MCP clients (such as Claude Desktop or other LLM-based agents) to interact with **MATLAB** and **Simulink** in real time. It runs locally and is built on top of the [FastMCP 2.0](https://gofastmcp.com/getting-started/welcome) library.
21
-
22
- ## Features
23
-
24
- - Read, write, and run MATLAB code and scripts
25
- - Parse and interact with Simulink files
26
- - Access MATLAB workspace variables and outputs (including visualizations)
27
- - Basic safety layer to prevent execution of unsafe commands (configurable)
28
- - Non-blocking execution (async MATLAB engine calls)
29
- - Automatic installation of MATLAB Engine package if unavailable
30
-
31
- ## Requirements
32
-
33
- - **MATLAB** R2022b or later
34
- - **Python** 3.10–3.12 (check MATLAB's [supported versions](https://www.mathworks.com/support/requirements/python-compatibility.html))
35
-
36
- ## Installation
37
-
38
- ### Option 1 — Download Binary (MATLAB R2025a only)
39
-
40
- If you don’t want to interact with Python at all, you can download a prebuilt **exe/app** from the [Releases](../../releases) page and run it directly. In that case you can skip the steps below.
41
-
42
- ### Option 2 — From Source
43
-
44
- 1. Clone the repository:
45
-
46
- ```bash
47
- git clone https://github.com/rohailamalik/matlab-simulink-mcp
48
- cd matlab-simulink-mcp
49
-
50
- 2. Create a Python virtual environment (recommended: [uv](https://pypi.org/project/uv/0.1.32/)):
51
-
52
- ```bash
53
- uv venv --python 3.12 # match Python to your MATLAB-supported version
54
- source .venv/Scripts/activate # on macOS/Linux: source .venv/bin/activate
55
- uv sync
56
- ```
57
-
58
- Without uv, first download a Python version manually:
59
-
60
- ```bash
61
- python3.12 -m venv .venv
62
- source .venv/bin/activate
63
- pip install -r requirements.txt
64
- pip install .
65
- ```
66
-
67
- 3. Alternatively, skip step 1, create virtual environment and install directly via PyPI:
68
-
69
- ```bash
70
- uv pip install matlab-simulink-mcp
71
- # or
72
- pip install matlab-simulink-mcp
73
- ```
74
-
75
- 4. On first run, if the MATLAB Engine is not installed, the server will open a console window and guide you through installation.
76
-
77
- - This requires admin permission and the server will request for it.
78
- - If you prefer to install manually, install a [matching PyPi version](https://pypi.org/project/matlabengine/#history) or from your [MATLAB installation](https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html).
79
-
80
- ## Configuration (Claude Desktop)
81
-
82
- 1. Install [Claude Desktop](https://claude.ai/download).
83
-
84
- 2. Open Settings → Developer → Edit Config.
85
-
86
- 3. In the `claude_desktop_config.json`, add or update:
87
-
88
- ```json
89
- {
90
- "mcpServers": {
91
- "MATLAB_Simulink_MCP": {
92
- "command": "C:/Data/Research/Doctoral/src/matlab-simulink-mcp/.venv/Scripts/python.exe",
93
- "args": ["-m", "matlab_simulink_mcp"]
94
- }
95
- }
96
- }
97
- ```
98
-
99
- On macOS/Linux, use `absolute-path-to/.venv/bin/python` in `command`.
100
-
101
- If using the standalone exe/app, just put absolute path to it in `command` and omit args.
102
-
103
- **Note**: Only use `/` or `\\` in the paths, not `\`.
104
-
105
- 4. Save and restart Claude Desktop. (Ensure it is fully closed in Task Manager/Activity Monitor.)
106
-
107
- 5. On first launch, the server may open multiple consoles to install MATLAB Engine. Interact with one, complete installation, then restart Claude if needed.
108
-
109
- 6. Check running status in Settings → Developer, or click the equalizer button in the chat box.
110
-
111
- 7. The server logs outputs and errors to both Claude's and its own log file. To keep a log file tracking console open, add `--console` in Claude config args.
112
-
113
- - Claude MCP logs (Windows): `%APPDATA%\Claude\logs\mcp-server-MatlabMCP.log`
114
- - Claude MCP logs (macOS): `~/Library/Logs/Claude/mcp-server-MatlabMCP.log`
115
- - Server logs: written to your user log directory (or configured via `.env`).
116
-
117
- ## Debugging
118
-
119
- FastMCP 2.0 includes an MCP Inspector for manual testing without an LLM client. This launches a UI to send dummy requests directly to the server.
120
-
121
- ```bash
122
- cd scripts
123
- fastmcp dev debugger.py
124
- ```
125
-
126
- ## Repository Structure
127
-
128
- ```txt
129
-
130
- matlab-simulink-mcp/
131
- ├─ scripts
132
- │ ├─ debugger.py # Entry point for MCP inspector
133
- ├─ src/matlab_simulink_mcp/
134
- │ ├─ data/ # Data files and resources
135
- │ ├─ installer/ # MATLAB Engine installer
136
- │ │ ├─ installer.py
137
- │ │ ├─ launcher.py
138
- │ │ └─ win_elevate.py
139
- │ ├─ functions.py # Baseline MCP tool functions
140
- │ ├─ log_utils.py # Logging utilities
141
- │ ├─ security.py # Safety layer for code execution
142
- │ ├─ server.py # Main server script
143
- │ ├─ state.py # Server lifespan objects (logger, engine)
144
- │ ├─ __main__.py # Main entry point
145
- ├─ .env # Optional config (e.g. LOG_DIR)
146
- ├─ pyproject.toml # Project metadata and dependencies
147
- ├─ requirements.txt # Package dependencies for pip
148
- ├─ uv.lock # Package dependencies for uv
149
- └─ README.md # This file
150
-
151
- ```
152
-
153
- ## FAQ
154
-
155
- Q: Which Python version should I install?
156
-
157
- A: Match it to the highest Python version supported by your MATLAB release (see MathWorks docs).
158
-
159
- Q: The console disappears too quickly!
160
-
161
- A: Add `--console` in your Claude config args to keep the server console open.
162
-
163
- Q: Multiple installer consoles opened on first run.
164
-
165
- A: This is expected if Claude sends multiple startup requests. Complete one installation, then restart Claude Desktop.
166
-
167
- ## Contributing
168
-
169
- Pull requests are welcome! Feel free to submit one or open an issue.