Skip to content

Commit f4ad75d

Browse files
update README with more infomration
1 parent 7737985 commit f4ad75d

File tree

2 files changed

+120
-25
lines changed

2 files changed

+120
-25
lines changed

README.md

Lines changed: 119 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# MATLAB MCP Tool
22

3-
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.
3+
A Model Context Protocol (MCP) server that provides tools for developing and running MATLAB files. This tool integrates with Cline and other MCP-compatible clients to provide interactive MATLAB development capabilities.
44

55
## Prerequisites
66

77
- Python 3.8+
88
- MATLAB with Python Engine installed
9-
- MCP SDK for Python (`pip install modelcontextprotocol`)
10-
- MATLAB Engine for Python (`pip install matlabengine`)
119

1210
## Features
1311

@@ -17,12 +15,7 @@ A Model Context Protocol (MCP) server that provides tools for developing, runnin
1715
- Maintain workspace context between executions
1816
- Capture and display plots
1917

20-
2. **Interactive Debugging**
21-
- Set breakpoints in MATLAB scripts
22-
- Debug script execution
23-
- Inspect workspace variables
24-
25-
3. **Section-based Execution**
18+
2. **Section-based Execution**
2619
- Execute specific sections of MATLAB files
2720
- Support for cell mode (%% delimited sections)
2821
- Maintain workspace context between sections
@@ -32,7 +25,7 @@ A Model Context Protocol (MCP) server that provides tools for developing, runnin
3225
1. Clone this repository:
3326
```bash
3427
git clone [repository-url]
35-
cd matlab-mcp-tool
28+
cd matlab-mcp-tools
3629
```
3730

3831
2. Create and activate a conda environment:
@@ -41,16 +34,30 @@ conda create -n matlab-mcp python=3.8
4134
conda activate matlab-mcp
4235
```
4336

44-
3. Install dependencies:
37+
3. Install the package and its dependencies:
38+
```bash
39+
pip install -e .
40+
```
41+
42+
4. Install MATLAB Engine for Python:
4543
```bash
46-
pip install modelcontextprotocol matlabengine
44+
# Navigate to MATLAB engine directory
45+
cd /Applications/MATLAB_R2024b.app/extern/engines/python
46+
47+
# Install MATLAB engine
48+
python setup.py install
49+
```
50+
51+
5. Add MATLAB to system PATH:
52+
```bash
53+
export PATH="/Applications/MATLAB_R2024b.app/:$PATH"
4754
```
4855

4956
## Usage
5057

5158
1. Start the MCP server:
5259
```bash
53-
python src/matlab_bridge.py
60+
python -m matlab_mcp.server
5461
```
5562

5663
2. Configure Cline to use the MATLAB MCP server by adding to your Cline configuration:
@@ -59,7 +66,7 @@ python src/matlab_bridge.py
5966
"mcpServers": {
6067
"matlab": {
6168
"command": "python",
62-
"args": ["/path/to/matlab-mcp-tool/src/matlab_bridge.py"],
69+
"args": ["-m", "matlab_mcp.server"],
6370
"env": {
6471
"PYTHONPATH": "/path/to/matlab/engine/installation"
6572
}
@@ -87,26 +94,114 @@ python src/matlab_bridge.py
8794
}
8895
```
8996

90-
- **debug_matlab_script**
91-
```json
92-
{
93-
"script": "debug_script.m",
94-
"breakpoints": [5, 10, 15]
95-
}
96-
```
97+
## Examples
98+
99+
### 1. Simple Script Execution with Plot
100+
101+
This example demonstrates running a complete MATLAB script that generates a plot:
102+
103+
```matlab
104+
% test_plot.m
105+
x = linspace(0, 2*pi, 100);
106+
y = sin(x);
107+
108+
% Create a figure with some styling
109+
figure;
110+
plot(x, y, 'LineWidth', 2);
111+
title('Sine Wave');
112+
xlabel('x');
113+
ylabel('sin(x)');
114+
grid on;
115+
116+
% Add some annotations
117+
text(pi, 0, '\leftarrow \pi', 'FontSize', 12);
118+
```
119+
120+
To execute this script using the MCP tool:
121+
```json
122+
{
123+
"script": "test_plot.m",
124+
"isFile": true
125+
}
126+
```
127+
128+
The tool will execute the script and capture the generated plot, saving it to the output directory.
129+
130+
### 2. Section-Based Execution
131+
132+
This example shows how to execute specific sections of a MATLAB script:
133+
134+
```matlab
135+
%% Section 1: Data Generation
136+
% Generate sample data
137+
x = linspace(0, 10, 100);
138+
y = sin(x);
139+
140+
fprintf('Generated %d data points\n', length(x));
141+
142+
%% Section 2: Basic Statistics
143+
% Calculate basic statistics
144+
mean_y = mean(y);
145+
std_y = std(y);
146+
max_y = max(y);
147+
min_y = min(y);
148+
149+
fprintf('Statistics:\n');
150+
fprintf('Mean: %.4f\n', mean_y);
151+
fprintf('Std Dev: %.4f\n', std_y);
152+
fprintf('Max: %.4f\n', max_y);
153+
fprintf('Min: %.4f\n', min_y);
154+
155+
%% Section 3: Plotting
156+
% Create visualization
157+
figure('Position', [100, 100, 800, 400]);
158+
159+
subplot(1, 2, 1);
160+
plot(x, y, 'b-', 'LineWidth', 2);
161+
title('Signal');
162+
xlabel('x');
163+
ylabel('y');
164+
grid on;
165+
166+
subplot(1, 2, 2);
167+
histogram(y, 20);
168+
title('Distribution');
169+
xlabel('Value');
170+
ylabel('Count');
171+
grid on;
172+
173+
sgtitle('Signal Analysis');
174+
```
175+
176+
To execute specific sections:
177+
```json
178+
{
179+
"filePath": "section_test.m",
180+
"sectionStart": 1,
181+
"sectionEnd": 2
182+
}
183+
```
184+
185+
This will run sections 1 and 2, generating the data and calculating statistics. The output will include:
186+
```
187+
Generated 100 data points
188+
Statistics:
189+
Mean: 0.0000
190+
Std Dev: 0.7071
191+
Max: 1.0000
192+
Min: -1.0000
193+
```
97194

98195
## Output Directory
99196

100-
The tool creates an `output` directory in the current working directory to store:
197+
The tool creates `matlab_output` and `test_output` directories to store:
101198
- Plot images generated during script execution
102-
- Debug output files
103199
- Other temporary files
104200

105201
## Error Handling
106202

107203
- Script execution errors are captured and returned with detailed error messages
108204
- Workspace state is preserved even after errors
109-
- Debug sessions are properly cleaned up
110205

111206
## Contributing
112207

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "matlab-mcp-tools"
33
version = "0.1.0"
44
description = "MCP server for MATLAB integration with Cline"
55
authors = [
6-
{ name = "Yahya" }
6+
{ name = "Seyed Yahya Shirazi", email = "[email protected]" }
77
]
88
dependencies = [
99
"mcp[cli]>=0.1.0",

0 commit comments

Comments
 (0)