matlab-simulink-mcp 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl

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.
@@ -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};
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matlab-simulink-mcp
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: An MCP server for allowing LLMs to interact with MATLAB and Simulink
5
5
  Author: Rohail
6
6
  License: MIT
@@ -8,13 +8,19 @@ matlab_simulink_mcp/state.py,sha256=bT8Ud2E3W2eWxcqgSuRcuvj43O9BYERWciBYh82ey24,
8
8
  matlab_simulink_mcp/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  matlab_simulink_mcp/data/blacklist.txt,sha256=YXWTjcjFM-uTb3gD_pblEpPPGoIKjSHMFgZJdWfmuMw,656
10
10
  matlab_simulink_mcp/data/simlib_db.json,sha256=bni7DcGG6SofIcCMX5KSlaHOHOYsELT833reNhz4S5Q,538658
11
+ matlab_simulink_mcp/data/helpers/describe_system.m,sha256=H80_L2YQ189_TI8qDWFA3xdvtPIHqhCm4llNoGQBeDw,2004
12
+ matlab_simulink_mcp/data/helpers/format_system.m,sha256=f0TynV7VxZPDYHjXe0t56ZnFQoVb6NXvuriJHqFcWtM,576
13
+ matlab_simulink_mcp/data/helpers/get_images.m,sha256=5n_gkJqDYxhLLje6V0sRT3U-zjoO4D-ub3k6EbAKRjE,376
14
+ matlab_simulink_mcp/data/helpers/get_ports_connections.m,sha256=nw4iiW_jKg9R9cvZXCbPMoKOO-Ha0rbas_5we266nfA,4653
15
+ matlab_simulink_mcp/data/helpers/snapshot_system.m,sha256=bitsd65cnPecIJpfe-OFH1Ia2oWTYFrWVMvVB3ZJN0I,316
16
+ matlab_simulink_mcp/data/helpers/validate_code.m,sha256=cIKh1Fnl486UOPGUc4QYYWOn1MOkWcZNXuPclSkPg64,86
11
17
  matlab_simulink_mcp/installer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
18
  matlab_simulink_mcp/installer/installer.py,sha256=0SHMTaqZjSvb9zKx4in67bS5xT4JcnsO2U2vYvmb968,5949
13
19
  matlab_simulink_mcp/installer/launcher.py,sha256=aGuxkXnLcb1OZ4P6rHvXFi8KZsDUZVQlo0rNvjdmFqA,1438
14
20
  matlab_simulink_mcp/installer/win_elevate.py,sha256=LyHHUh4vWmIlIXxrM9tOhQUvVeMxcVdXMzkC3vbGm3A,514
15
- matlab_simulink_mcp-0.1.1.dist-info/licenses/LICENSE,sha256=qxK38PIeAkpnIu0mX7Re5nGKlHEx1Ez4p_4Yg4-3-Hw,1090
16
- matlab_simulink_mcp-0.1.1.dist-info/METADATA,sha256=fA8SHhzZyrCMsgm86TKMcHtMSezn14B9DP-IduVpaUc,4125
17
- matlab_simulink_mcp-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
- matlab_simulink_mcp-0.1.1.dist-info/entry_points.txt,sha256=0ba8PFlQcaWyAqKXRIVDfDvrifeD5LY60lV7i6ak9oE,74
19
- matlab_simulink_mcp-0.1.1.dist-info/top_level.txt,sha256=90gv-RNCWWS7E-JMiqwUf2TjB_B8Zb2B-crAeXaABqU,20
20
- matlab_simulink_mcp-0.1.1.dist-info/RECORD,,
21
+ matlab_simulink_mcp-0.1.2.dist-info/licenses/LICENSE,sha256=qxK38PIeAkpnIu0mX7Re5nGKlHEx1Ez4p_4Yg4-3-Hw,1090
22
+ matlab_simulink_mcp-0.1.2.dist-info/METADATA,sha256=0dgAZ1Gw7NGleIOELyYHcDAdYhkaH2dRjzIGZhZwiJU,4125
23
+ matlab_simulink_mcp-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
24
+ matlab_simulink_mcp-0.1.2.dist-info/entry_points.txt,sha256=0ba8PFlQcaWyAqKXRIVDfDvrifeD5LY60lV7i6ak9oE,74
25
+ matlab_simulink_mcp-0.1.2.dist-info/top_level.txt,sha256=90gv-RNCWWS7E-JMiqwUf2TjB_B8Zb2B-crAeXaABqU,20
26
+ matlab_simulink_mcp-0.1.2.dist-info/RECORD,,