-
Notifications
You must be signed in to change notification settings - Fork 0
FAQ
# FAQ
## General / Overview
### What is the MATLAB MCP Server?
The MATLAB MCP Server is a Python-based MCP (Model Context Protocol) bridge that connects AI coding agents (Claude, Cursor, Copilot, etc.) to MATLAB. It enables agents to execute MATLAB code, discover toolboxes, manage files, inspect workspaces, and view interactive Plotly plots — all through a standard MCP interface.
**Architecture:** The server manages an elastic pool of MATLAB engines, routes requests per-session with workspace isolation, enforces security policies (blocked functions, file upload limits), collects metrics, and supports both local (stdio) and remote (HTTP/streamable) transports.
See [[Architecture]] for a detailed system overview.
### What MATLAB versions are supported?
**MATLAB R2022b and later.** The MATLAB Engine API for Python must be installed separately from your MATLAB installation.
```bash
# Example: macOS
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .
# Example: Windows
cd "C:\Program Files\MATLAB\R2024a\extern\engines\python"
pip install .Python 3.10, 3.11, or 3.12. The project uses modern async/await patterns and requires pydantic>=2.0 for configuration validation.
MIT License. See LICENSE in the repository.
Any agent that implements the Model Context Protocol:
-
Claude Desktop — via MCP configuration in
claude_desktop_config.json -
Claude Code — native MCP integration with
claude mcp add -
Cursor — MCP settings in
.cursor/settings.json - Codex CLI — supports both stdio and streamable HTTP transports
- Custom agents built with MCP SDKs (Python, JavaScript, Rust, Go)
See Agent-Onboarding for connection examples for each agent.
Option 1: PyPI (recommended)
pip install matlab-mcp-python
matlab-mcp # Run itOption 2: Windows one-click installer (no admin rights)
git clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-python
install.batOption 3: Source installation
git clone https://github.com/HanSur94/matlab-mcp-server-python.git
cd matlab-mcp-server-python
pip install -e ".[dev]"
matlab-mcpOption 4: Conda
conda env create -f environment.yml
conda activate matlab-mcp
matlab-mcpSee Installation for detailed platform-specific instructions.
- Install MATLAB R2022b+ with Engine API
pip install matlab-mcp-python-
matlab-mcp(stdio transport, single user, no auth)
That's it. No config files required for basic use.
Add this to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"matlab": {
"command": "matlab-mcp"
}
}
}Restart Claude Desktop. The MATLAB tools appear in the "Composer" panel.
-
Generate a token:
matlab-mcp --generate-token
-
Export the environment variable (shown by the command):
export MATLAB_MCP_AUTH_TOKEN=<64-char-hex-token>
-
Start the server with HTTP transport:
matlab-mcp --transport http
-
Configure your agent to send the bearer token (see Agent-Onboarding).
See Configuration for advanced auth setup.
Yes. The repository includes docker-compose.test.yml (for remote integration testing). For production, create a docker-compose.yml that mounts your MATLAB installation:
version: '3.8'
services:
matlab-mcp:
build: .
ports:
- "8765:8765"
environment:
- MATLAB_MCP_AUTH_TOKEN=${AUTH_TOKEN}
volumes:
- /opt/matlab:/opt/matlab # Mount your MATLAB installationSee Installation for Docker setup.
graph TD
A["Transport Choice"]
A -->|Single user, local| B["stdio"]
A -->|Multi-user, remote| C["HTTP/Streamable"]
A -->|Deprecated| D["SSE"]
B --> B1["No auth, no config, simplest"]
C --> C1["Bearer token auth, configurable"]
D --> D1["Legacy, use streamable instead"]
| Transport | Single/Multi-User | Auth | Config | When to Use |
|---|---|---|---|---|
| stdio | Single | None | No | Local development, Claude Desktop |
| streamable HTTP | Multi | Bearer token | Yes | Remote agents, Codex CLI, production |
| SSE | Multi | Proxy auth only | Yes | Deprecated (use streamable instead) |
See Configuration for transport setup.
The pool auto-scales between min_engines (default: 2) and max_engines (default: 10).
| Scenario | Recommended |
|---|---|
| Personal use, one agent | 1-2 |
| Small team (2-5 concurrent users) | 2-4 |
| Medium team (5-10 concurrent users) | 4-8 |
| Large team or long simulations | 8-16 |
Check your MATLAB license limits. On macOS, MATLAB limits you to ~4 concurrent engines regardless of configuration.
Configure via config.yaml:
pool:
min_engines: 2
max_engines: 16Or environment variable:
export MATLAB_MCP_POOL_MAX_ENGINES=16
matlab-mcpTypically 500MB to 2GB per engine, depending on:
- MATLAB version
- Loaded toolboxes
- Workspace variables
- Active jobs
For a team of 5 with 4 engines, budget 2-8GB of RAM.
graph TD
A["Code Submitted"]
A --> B{Finishes within<br/>sync_timeout?}
B -->|Yes (< 30s)| C["Return result immediately"]
B -->|No (> 30s)| D["Create job, return job_id"]
D --> E["Agent polls progress<br/>via get_job_status"]
E --> F["Eventually get result<br/>via get_job_result"]
- Sync: Fast commands (< 30 seconds) return immediately with results
-
Async: Slow jobs return a
job_idand run in the background; agent polls for progress
Default sync_timeout: 30 seconds. Configure in config.yaml or via MATLAB_MCP_EXECUTION_SYNC_TIMEOUT_SECONDS.
See Async-Jobs for examples.
-
Increase
sync_timeoutfor long-running code:export MATLAB_MCP_EXECUTION_SYNC_TIMEOUT_SECONDS=300 -
Add progress reporting via
mcp_progress()in your MATLAB code:for i = 1:1000 % ... computation ... if mod(i, 100) == 0 mcp_progress(__mcp_job_id__, i/10, sprintf('Iteration %d', i)); end end
-
Increase engine pool to handle multiple concurrent simulations:
export MATLAB_MCP_POOL_MAX_ENGINES=16
See Async-Jobs and Examples for code patterns.
Requests queue up (configurable queue_max_size, default: 50). If the pool hasn't reached max_engines, a new engine is started automatically. Requests are served FIFO as engines become available.
Queue status is visible in the monitoring dashboard (/dashboard).
Example: Run MATLAB code as part of your CI pipeline
name: MATLAB Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install MATLAB Engine API
run: |
cd /opt/matlab/extern/engines/python
pip install .
- name: Install MCP server
run: pip install matlab-mcp-python
- name: Run MATLAB tests
run: |
matlab-mcp --inspect &
sleep 2
python -c "from matlab_mcp.tools.core import execute_code_impl; ..."See tests/test_mcp_integration.py in the repo for an end-to-end CI example.
Do not expose the raw HTTP endpoint directly. Always use a reverse proxy with authentication:
upstream matlab_mcp {
server 127.0.0.1:8765;
}
server {
listen 443 ssl;
server_name matlab-mcp.example.com;
location /mcp {
auth_basic "MATLAB MCP Server";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://matlab_mcp;
proxy_read_timeout 60s;
}
}Configure the server to accept proxy auth:
security:
require_proxy_auth: trueSee Security for detailed hardening guidance.
Define them in a custom_tools.yaml file:
custom_tools:
- name: signal_analysis
description: Analyze frequency content of a signal
function: my_toolbox.signal_analysis
parameters:
signal:
type: ndarray
description: Input signal vector
fs:
type: number
description: Sampling frequency
returns:
freqs: Frequency vector
magnitudes: FFT magnitudesLoad it with:
export MATLAB_MCP_CUSTOM_TOOLS_FILE=/path/to/custom_tools.yaml
matlab-mcpSee Custom-Tools for detailed examples.
Use the --inspect flag to run without MATLAB (dry-run mode):
matlab-mcp --inspect --transport http --port 8765 &Then connect a real MCP client to http://127.0.0.1:8765/mcp to verify the server starts and tools are registered. See tests/test_mcp_integration.py for a real example.
Docker: Yes, with mounted MATLAB installation (see Installation).
Kubernetes: Possible but complex — MATLAB licensing is per-machine, not per-container. Consider:
- StatefulSet with a persistent MATLAB license
- Host mount of MATLAB installation
- Session affinity to ensure requests return to the same pod
- Monitoring to detect dead pods
See Windows-Deployment for a Windows container example.
The server exposes a monitoring dashboard at /dashboard (when monitoring is enabled):
matlab-mcp --monitoring-enabled &
# Open http://127.0.0.1:8766/dashboardOr query metrics programmatically:
curl http://127.0.0.1:8766/metrics
# Returns JSON with pool utilization, active jobs, error rates, etc.Enable metrics persistence:
monitoring:
enabled: true
metrics_store_path: /var/log/matlab_mcp/metrics.db
sampling_interval_seconds: 10See Configuration for monitoring options.
Cause: MATLAB Engine API not installed or Python version mismatch.
Fix:
# Reinstall Engine API for your Python version
cd /Applications/MATLAB_R2024a.app/extern/engines/python # macOS
python --version # Verify Python 3.10-3.12
pip install .Cause: Server bound to 127.0.0.1 (loopback only) but accessed from another machine.
Fix: Bind to 0.0.0.0:
matlab-mcp --host 0.0.0.0Warning (Windows): Binding to 0.0.0.0 triggers Windows Firewall, which may prompt for admin rights. Use a reverse proxy on the same machine instead.
See Windows-Deployment for details.
Cause: Mismatch between server token and agent token.
Fix:
# 1. Generate a new token
matlab-mcp --generate-token
# Output: MATLAB_MCP_AUTH_TOKEN=abc123def456...
# 2. Set it and restart the server
export MATLAB_MCP_AUTH_TOKEN=abc123def456...
matlab-mcp --transport http
# 3. Configure agent with exact same tokenSee Agent-Onboarding for agent-specific examples.
Cause: Security validator blocked a potentially dangerous function.
Fix: Either use a MATLAB alternative or customize the blocklist:
security:
blocked_functions:
- system
- unix
# Remove entries to allow themSee Security for the default blocklist and safe alternatives.
Cause: Complex custom graphics or unsupported plot type.
Fix: The server automatically generates a static PNG fallback. For interactive plots, stick to standard MATLAB plot types (line, scatter, bar, surface, histogram).
See Examples for supported plot examples.
Cause: Job tracker not pruned, metrics store growing unbounded.
Fix:
jobs:
retention_hours: 24 # Prune jobs older than 24 hours
monitoring:
metrics_retention_hours: 168 # Prune metrics older than 7 daysOr restart the server periodically in production (e.g., via systemd timer).
Open an issue on GitHub with:
- MATLAB version (
versioncommand) - Python version (
python --version) - Transport used (stdio/HTTP/SSE)
- Full error message and stack trace
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Write tests (
pytest) - Submit a pull request
See Architecture and Testing in the wiki for development guidelines.
SSE (Server-Sent Events) is a one-way streaming protocol. It requires a persistent connection and doesn't handle errors gracefully. Streamable HTTP (MCP's HTTP transport in FastMCP 3.0+) is:
- Bidirectional (requests/responses)
- Stateless (better for load-balancing)
- Standard HTTP (proxy-compatible)
- Officially recommended by MCP spec
All production deployments should use streamablehttp transport.
Yes, but each MATLAB engine is a separate process. If your code uses parpool() inside one engine, that's within that engine's workspace — it doesn't distribute across the engine pool. For cluster computing, consider:
- Running long jobs async (
sync_timeoutsetting) - Using
parpoolwithin a single large engine - Custom tools that batch jobs across multiple independent MATLAB calls
graph TD
A["MATLAB Code Execution"]
A -->|matlab -batch| B["Single process, slow startup, no connection pooling"]
A -->|MATLAB Engine API| C["This server: persistent engines, instant execution, session isolation"]
This server:
- Keeps MATLAB engines warm (no 5-10s startup per command)
- Shares a pool across multiple agents
- Maintains per-session workspaces
- Supports async jobs, progress reporting, interactive plots
- Provides HTTP access for remote agents
- Installation — Platform-specific setup (Windows, macOS, Linux, Docker)
- Configuration — All config.yaml options with examples
- Architecture — System design and data flows
- Security — Security layers and hardening guidance
- Agent-Onboarding — Connection examples for Claude Code, Cursor, Codex CLI
- MCP-Tools-Reference — Complete tool reference with parameters and examples
- Custom-Tools — How to expose your own MATLAB functions as tools
- Async-Jobs — Async execution, progress reporting, job management
- Examples — Ready-to-run MATLAB code examples
- Troubleshooting — Common issues and fixes