-
Notifications
You must be signed in to change notification settings - Fork 0
FAQ
The MATLAB MCP Server is a Python-based bridge that connects any MCP-compatible AI coding agent (Claude, Cursor, Copilot, etc.) to MATLAB for code execution. It exposes 20+ built-in tools for running MATLAB code, discovering toolboxes, managing async jobs, handling file operations, and monitoring server health.
See the Home page for a complete feature overview.
MATLAB R2022b and later. The MATLAB Engine API for Python must be installed separately from your MATLAB installation. See Installation for setup instructions.
The project is open-source under the MIT License. See the repository for details.
Any agent supporting the Model Context Protocol (MCP):
- Claude Desktop
- Claude Code
- Cursor
- GitHub Copilot (with MCP support)
- Custom agents built with MCP SDKs
See Agent-Onboarding for connection examples for each agent.
No. The server requires a local MATLAB installation with the Engine API. It bridges to real MATLAB engines, not a simulator.
Yes, but MATLAB is not included in the Docker image. You must mount your own MATLAB installation as a volume. See Installation for Docker setup.
The process varies by operating system:
macOS (Intel or Apple Silicon):
cd /Applications/MATLAB_R2024a.app/extern/engines/python
pip install .Windows:
cd "C:\Program Files\MATLAB\R2024a\extern\engines\python"
pip install .Linux:
cd /usr/local/MATLAB/R2024a/extern/engines/python
pip install .Replace R2024a with your installed MATLAB version. See Installation for full instructions.
| Transport | Use Case | Setup | Sessions |
|---|---|---|---|
| stdio (default) | Single agent, local | Simple; no network | 1 default session |
| SSE (deprecated) | Multiple agents, remote | HTTP server behind proxy | Per-session isolation |
| Streamable HTTP | Multiple agents, remote | HTTP server (recommended) | Per-session isolation |
Recommendation: Use stdio for development/local testing. For production deployments with multiple agents, use streamable HTTP transport behind a reverse proxy with authentication.
See Configuration for transport setup details.
- Generate a token:
matlab-mcp --generate-token- Set the environment variable:
export MATLAB_MCP_AUTH_TOKEN=<generated_token>- When connecting agents, use the token in the
Authorizationheader:
Authorization: Bearer <token>
The --generate-token flag prints shell-specific snippets for POSIX, Windows cmd, and PowerShell. No token configuration belongs in config.yaml — always use environment variables.
Yes. The server binds to 127.0.0.1 by default (localhost only), which does not require Windows Firewall elevation. See Windows-Deployment for a complete no-admin setup guide.
See Windows-Deployment (for Windows 10 shared machines) and Agent-Onboarding (for connecting multiple agents). For production deployments, Security documents reverse-proxy and authentication best practices.
Each MATLAB engine process consumes 500 MB–2 GB depending on loaded toolboxes. A pool of 4 engines typically uses 2–8 GB. Configure pool.min_engines and pool.max_engines based on available memory and concurrent user load.
- Personal use: 1–2 engines
- Small team (2–5 concurrent users): 2–4 engines
- Larger team: Scale based on concurrent usage and license limits
macOS: MATLAB limits you to approximately 4 concurrent engines due to OS constraints.
Yes. Set stateless_http: true in the server config. This disables session state so each request is self-contained — load balancers can route requests to any server instance without sticky sessions.
server:
transport: streamablehttp
stateless_http: trueRequests queue up (configurable sessions.queue_max_size, default 50). If the pool hasn't reached max_engines, a new engine starts automatically. Requests are served FIFO as engines become available.
Code exceeding execution.sync_timeout (30s default) automatically promotes to async execution. For code that typically takes 1–2 minutes:
execution:
sync_timeout: 120 # Increase to 2 minutesUse the mcp_progress() helper to report progress from long jobs:
mcp_progress(__mcp_job_id__, 50, 'Processing step 2 of 4');See Async-Jobs for details.
See the "Claude Code" section in Agent-Onboarding. In brief:
- Ensure the server is running with
--transport streamablehttp - In Claude Code settings, add the MCP server configuration:
{
"name": "matlab-mcp",
"url": "http://localhost:8765/mcp",
"auth": {
"type": "bearer",
"token": "${MATLAB_MCP_AUTH_TOKEN}"
}
}- Set the environment variable:
export MATLAB_MCP_AUTH_TOKEN=<your_token>See the "Cursor" section in Agent-Onboarding. Cursor supports both stdio (local) and HTTP (remote) configurations in .cursor/mcp_config.json:
{
"mcpServers": {
"matlab": {
"command": "python",
"args": ["-m", "matlab_mcp", "--transport", "stdio"],
"env": {
"MATLAB_MCP_AUTH_TOKEN": "<token>"
}
}
}
}See the "Codex CLI" section in Agent-Onboarding. Codex CLI connects via HTTP with bearer token auth:
export MCP_SERVER_URL=http://localhost:8765/mcp
export MCP_AUTH_TOKEN=<your_token>
codex-cli --mcp-server $MCP_SERVER_URL --mcp-auth-header "Authorization: Bearer $MCP_AUTH_TOKEN"The server supports environment variable overrides for all config values. Example GitHub Actions workflow:
- name: Run MATLAB via MCP
env:
MATLAB_MCP_AUTH_TOKEN: ${{ secrets.MATLAB_MCP_TOKEN }}
run: |
python -m matlab_mcp --transport stdio &
# Agent connects and runs MATLAB codeYes. Define them in a custom_tools.yaml file:
custom_tools:
- name: signal_filter
function: "signal_processing.filter_signal"
parameters:
input_file: {type: "string", description: "Input .wav file"}
cutoff_hz: {type: "float", description: "Cutoff frequency"}
returns: "Filtered signal and spectogram"See Custom-Tools for full syntax and examples.
Monitoring is enabled by default. Access the dashboard at:
http://localhost:8766/dashboard (stdio transport)
http://localhost:8765/dashboard (HTTP transport)
Customize with:
monitoring:
enabled: true
sample_interval: 10 # Seconds between samples
retention_days: 7 # Keep 7 days of history
dashboard_enabled: trueThe dashboard shows real-time engine pool utilization, job throughput, execution time percentiles, error rates, and event logs. See Architecture for the monitoring stack.
By default, code runs synchronously and returns immediately. If execution exceeds execution.sync_timeout (30s default), the server automatically:
- Returns a
job_idto the agent - Continues running the code in the background
- Allows the agent to poll
get_job_status(job_id)for progress - Returns the full result via
get_job_result(job_id)when complete
See Async-Jobs for examples and configuration.
When execution.workspace_isolation: true (default), each session has a dedicated temp directory and workspace:
clear all
clear global
clear functions
fclose all
restoredefaultpathThis prevents state from leaking between users or agents.
The server enforces:
-
Function blocklist: Blocks
system(),eval(),unix(),dos(),!and 7 other dangerous functions by default - Filename sanitization: Prevents path traversal in upload paths
- Upload size limits: Configurable per-file size cap (default 100 MB)
- Bearer token auth: On HTTP transports (stdio has no auth)
- Session isolation: Workspaces cleared between sessions
See Security for the full security architecture.
The server uses a three-stage pipeline:
-
MATLAB-side (
mcp_extract_props.m): Extracts figure properties (lines, surfaces, axes labels, colors) -
Python-side (
plotly_style_mapper.py): Converts MATLAB styles to Plotly equivalents (line styles, markers, colormaps) -
Python-side (
formatter.py): Builds a Plotly JSON response + static PNG
Agents receive interactive JSON suitable for web display + a PNG fallback.
See Architecture for the full data flow.
This often happens on network-mapped drives. Add a timeout:
timeout 10 matlab-mcp --transport stdioOr move the config and temp directories to a local drive.
- Verify the auth token is set:
echo $MATLAB_MCP_AUTH_TOKEN-
For HTTP transports, ensure the
Authorization: Bearer <token>header is present in agent config -
Check the server log:
matlab-mcp --log-level debugThis usually means the MATLAB figure conversion failed. Check:
- Is the code creating a figure without calling
clforclose? - Are all plot types supported? (Lines, scatter, bar, histogram, surface, image are fully supported; custom graphics may fall back to PNG)
- Check the server log for conversion errors
The security validator strips string literals and comments before scanning. If a false positive occurs:
- List currently blocked functions:
security:
blocked_functions_enabled: true-
To disable a specific function from the blocklist, edit
security.blocked_functionsin config -
To disable all blocking temporarily:
export MATLAB_MCP_SECURITY_BLOCKED_FUNCTIONS_ENABLED=falseThis usually indicates the MATLAB engine crashed. Check:
- The server log for engine startup errors
- MATLAB for errors in the code itself
- Call
cancel_job(job_id)to clean up stale jobs - Restart the server to reset the engine pool
The default limit is 10 concurrent sessions. Adjust in config:
sessions:
max_sessions: 50 # Increase limitSee Configuration for other session tuning options.
pip install -e ".[dev]"
pytest tests/ -vTests use a mock MATLAB engine — no real MATLAB installation required for testing.
- Create the implementation in
src/matlab_mcp/tools/ - Register it in
server.pywith the@mcp.tool()decorator - Write tests in
tests/test_tools_*.py - Document it in MCP-Tools-Reference
- Fork the GitHub repository
- Create a feature branch
- Commit with conventional commit messages (
feat:,fix:,docs:) - Open a pull request
See CONTRIBUTING.md in the repository for detailed guidelines.