Skip to content

Commit e7ca43c

Browse files
Make a installer with correct MCP settings.
1 parent 0d391de commit e7ca43c

File tree

5 files changed

+225
-5
lines changed

5 files changed

+225
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ octave-workspace
4646
matlab_output/
4747
test_output/
4848
*.code-workspace
49+
mcp-pip.json
4950

5051
# Jupyter
5152
.ipynb_checkpoints/

README.md

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ A Model Context Protocol (MCP) server that provides tools for developing and run
66

77
- Python 3.8+
88
- MATLAB with Python Engine installed
9+
- uv package manager (recommended)
910

1011
## Features
1112

@@ -22,6 +23,50 @@ A Model Context Protocol (MCP) server that provides tools for developing and run
2223

2324
## Installation
2425

26+
### Using pip (Recommended)
27+
28+
1. Clone this repository:
29+
```bash
30+
git clone [repository-url]
31+
cd matlab-mcp-tools
32+
```
33+
34+
2. Set the MATLAB path environment variable if your MATLAB is not in the default location:
35+
```bash
36+
# For macOS (default is /Applications/MATLAB_R2024b.app)
37+
export MATLAB_PATH=/path/to/your/matlab/installation
38+
39+
# For Windows (default might be C:\Program Files\MATLAB\R2024b)
40+
# set MATLAB_PATH=C:\path\to\your\matlab\installation
41+
```
42+
43+
3. Run the setup script to install the package with pip:
44+
```bash
45+
./setup-pip-matlab-mcp.sh
46+
```
47+
48+
4. Configure Cline/Cursor by copying the provided MCP configuration:
49+
```bash
50+
# For macOS/Linux
51+
cp mcp-pip.json ~/.cursor/mcp.json
52+
53+
# For Windows
54+
# copy mcp-pip.json %USERPROFILE%\.cursor\mcp.json
55+
```
56+
57+
5. Test the installation:
58+
```bash
59+
./test-pip-matlab-mcp.sh
60+
```
61+
62+
After setup, you can run the MATLAB MCP server using:
63+
```bash
64+
matlab-mcp-server
65+
```
66+
67+
68+
### Using Conda (Alternative)
69+
2570
1. Clone this repository:
2671

2772
```bash
@@ -40,18 +85,61 @@ conda activate matlab-mcp
4085
pip install -e .
4186
```
4287

43-
4. Install MATLAB Engine for Python:
88+
4. Set the MATLAB path environment variable:
89+
```bash
90+
# For macOS (default is /Applications/MATLAB_R2024b.app)
91+
export MATLAB_PATH=/path/to/your/matlab/installation
92+
93+
# For Windows (default might be C:\Program Files\MATLAB\R2024b)
94+
# set MATLAB_PATH=C:\path\to\your\matlab\installation
95+
```
96+
97+
5. Install MATLAB Engine for Python:
4498
```bash
4599
# Navigate to MATLAB engine directory
46-
cd /Applications/MATLAB_R2024b.app/extern/engines/python
100+
cd $MATLAB_PATH/extern/engines/python
47101

48102
# Install MATLAB engine
49103
python setup.py install
50104
```
51105

52-
5. Add MATLAB to system PATH:
106+
6. Add MATLAB to system PATH:
53107
```bash
54-
export PATH="/Applications/MATLAB_R2024b.app/:$PATH"
108+
# For macOS/Linux
109+
export PATH="$MATLAB_PATH/bin:$PATH"
110+
111+
# For Windows
112+
# set PATH=%MATLAB_PATH%\bin;%PATH%
113+
```
114+
115+
7. Create a configuration file for Cline/Cursor:
116+
```bash
117+
cat > mcp-conda.json << EOF
118+
{
119+
"mcpServers": {
120+
"matlab": {
121+
"command": "matlab-mcp-server",
122+
"args": [],
123+
"env": {
124+
"MATLAB_PATH": "\${MATLAB_PATH}",
125+
"PATH": "\${MATLAB_PATH}/bin:\${PATH}"
126+
},
127+
"disabled": false,
128+
"autoApprove": [
129+
"list_tools",
130+
"get_script_sections"
131+
]
132+
}
133+
}
134+
}
135+
EOF
136+
137+
# Copy to Cline/Cursor configuration
138+
# For macOS/Linux
139+
cp mcp-conda.json ~/.cursor/mcp.json
140+
141+
# For Windows
142+
# copy mcp-conda.json %USERPROFILE%\.cursor\mcp.json
55143
```
56144

57145
## Usage

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ readme = "README.md"
1515
license = { file = "LICENSE" }
1616

1717
[project.scripts]
18-
matlab-mcp = "matlab_mcp.server:main"
18+
matlab-mcp-server = "matlab_mcp.server:main"
1919

2020
[build-system]
2121
requires = ["setuptools>=61.0"]

setup-pip-matlab-mcp.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Define variables
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
MATLAB_PATH=${MATLAB_PATH}
7+
8+
# Print header
9+
echo "Setting up matlab-mcp-server with pip"
10+
echo "MATLAB path: $MATLAB_PATH"
11+
echo "Project dir: $SCRIPT_DIR"
12+
13+
# Check if MATLAB exists
14+
if [ ! -d "$MATLAB_PATH" ]; then
15+
echo "Error: MATLAB not found at $MATLAB_PATH"
16+
echo "Please set the MATLAB_PATH environment variable to the correct location"
17+
exit 1
18+
fi
19+
20+
# Install matlabengine first from MATLAB installation
21+
echo -e "\nInstalling MATLAB engine"
22+
cd "$MATLAB_PATH/extern/engines/python"
23+
python -m pip install .
24+
cd "$SCRIPT_DIR"
25+
26+
# Build and install the package with pip
27+
echo -e "\nBuilding and installing matlab-mcp-server with pip"
28+
pip install -e .
29+
30+
# Test if the installation was successful
31+
echo -e "\nTesting installation"
32+
if command -v matlab-mcp-server &> /dev/null; then
33+
echo "Installation successful! matlab-mcp-server is available in PATH"
34+
else
35+
echo "Warning: matlab-mcp-server not found in PATH"
36+
echo "Please check the logs for more information"
37+
exit 1
38+
fi
39+
40+
# Update the MCP configuration
41+
echo -e "\nUpdating MCP configuration"
42+
cat > mcp-pip.json << EOF
43+
{
44+
"mcpServers": {
45+
"matlab": {
46+
"command": "matlab-mcp-server",
47+
"args": [],
48+
"env": {
49+
"MATLAB_PATH": "${MATLAB_PATH}",
50+
"PATH": "${MATLAB_PATH}/bin:${PATH}"
51+
},
52+
"disabled": false,
53+
"autoApprove": [
54+
"list_tools",
55+
"get_script_sections"
56+
]
57+
}
58+
}
59+
}
60+
EOF
61+
62+
echo -e "\nSetup complete!"
63+
echo "To use the MATLAB MCP server with Cursor/Cline, copy the provided configuration:"
64+
echo "cp mcp-pip.json ~/.cursor/mcp.json"
65+
echo ""
66+
echo "To manually start the server, run:"
67+
echo "matlab-mcp-server"

test-pip-matlab-mcp.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Test if matlab-mcp-server is available
5+
echo -e "\n=== Testing Installation ==="
6+
if command -v matlab-mcp-server &> /dev/null; then
7+
echo "matlab-mcp-server is available in PATH"
8+
else
9+
echo "Error: matlab-mcp-server not found in PATH"
10+
echo "Please run ./setup-pip-matlab-mcp.sh first"
11+
exit 1
12+
fi
13+
14+
# Create a test MATLAB script
15+
echo -e "\n=== Setting up Test Files ==="
16+
echo "Creating a simple test script..."
17+
18+
# Create a test MATLAB script if it doesn't exist
19+
EXAMPLE_DIR="examples/matlab_scripts"
20+
mkdir -p "$EXAMPLE_DIR"
21+
22+
TEST_SCRIPT="$EXAMPLE_DIR/test_plot.m"
23+
if [ ! -f "$TEST_SCRIPT" ]; then
24+
cat > "$TEST_SCRIPT" << 'EOF'
25+
% Simple test script for MATLAB MCP
26+
x = linspace(0, 2*pi, 100);
27+
y = sin(x);
28+
29+
% Create a figure with some styling
30+
figure;
31+
plot(x, y, 'LineWidth', 2);
32+
title('Sine Wave');
33+
xlabel('x');
34+
ylabel('sin(x)');
35+
grid on;
36+
37+
% Add some annotations
38+
text(pi, 0, '\leftarrow \pi', 'FontSize', 12);
39+
40+
disp('Script executed successfully!')
41+
EOF
42+
fi
43+
44+
# Test if matlabengine is installed
45+
echo -e "\n=== Testing MATLAB Engine Installation ==="
46+
MATLAB_PATH=${MATLAB_PATH:-"/Applications/MATLAB_R2024b.app"}
47+
export PATH="$MATLAB_PATH/bin:$PATH"
48+
python -c "import matlab.engine; print('MATLAB engine is properly installed')" || echo "Warning: MATLAB engine not properly installed"
49+
50+
# Test starting the server
51+
echo -e "\n=== Testing Server Startup ==="
52+
echo "Starting the server in the background (will terminate after 5 seconds)..."
53+
matlab-mcp-server &
54+
SERVER_PID=$!
55+
sleep 5
56+
kill $SERVER_PID 2>/dev/null || true
57+
58+
echo -e "\n=== Test Complete ==="
59+
echo "The installation has been tested successfully."
60+
echo "To use the MATLAB MCP server with Cursor/Cline, copy the provided configuration:"
61+
echo "cp mcp-pip.json ~/.cursor/mcp.json"
62+
echo ""
63+
echo "To manually start the server, run:"
64+
echo "matlab-mcp-server"

0 commit comments

Comments
 (0)