Purpose
MATLAB MCP Server is a Model Context Protocol (MCP) server implemented in Python, intended to connect any AI agent (Claude, Cursor, Copilot, custom agents) to a shared MATLAB installation environment, so that agents can directly write and execute MATLAB code, run asynchronous long-running jobs, obtain interactive charts, and expose custom MATLAB functions as AI tools.
Main Capabilities
- Execute MATLAB code: Agents call execute_code through MCP to run MATLAB code, with results returned inline.
- Asynchronous long-running jobs: Long-running jobs (up to several hours) execute asynchronously. The agent immediately receives a job ID, polls progress (for example "Trial 500000/1000000 — 50%"), and obtains results when complete.
- Interactive Plotly charts: Each MATLAB figure is automatically converted into an interactive Plotly chart, with no additional code required. The server extracts figure properties through mcp_extract_props.m (axes, line data, labels, colors, markers, legends, subplots), maps MATLAB styling to Plotly (line styles such as -- → dash, markers such as o → circle, legend position, axis ticks, color mapping), and returns renderable interactive JSON; it also generates static PNGs and thumbnails as a fallback for non-interactive clients. Supported chart types include line, scatter, bar, area, subplots (subplot / tiledlayout), multiple axes, and logarithmic/linear scales. Style fidelity covers line styles, marker shapes, colors (RGB), line width, font size, axis labels, titles, legends, grid lines, axis ranges, and background colors.
- Custom tools: Expose proprietary MATLAB functions as first-class AI tools through custom_tools.yaml, which agents can call directly (such as analyze_signal or train_model), with full parameter validation and help text.
- Elastic engine pool: Multiple users share one MATLAB server through an elastic engine pool.
- Monitoring and observability: Built-in web dashboard (7 real-time gauges, 6 Plotly.js time-series charts, filterable MATLAB execution logs, time range selector 1h/6h/24h/7d, automatic refresh every 10 seconds), JSON health/metrics endpoints, and MCP tools for AI agent self-monitoring.
Usage
Requirements: MATLAB R2022b+, with the MATLAB Engine API for Python installed.
Installation:
- Pixi (recommended, no administrator privileges required): pixi.lock is committed, and pixi run ... can reproduce the exact resolved environment (Python 3.10–3.12, fastmcp==3.4.4) on any machine, with no separate pip install step. matlabengine is not a static dependency; the install-engine task installs it on demand, matching the detected MATLAB version.
- Windows one-click installation (no administrator privileges required): The installer automatically detects MATLAB, creates a virtual environment, and performs a fully offline installation from bundled wheels. Supports Windows 10/11 with Python 3.10, 3.11, or 3.12.
- When using Pixi, the corresponding tasks are pixi run start (stdio), pixi run http (streamablehttp, preferred), and pixi run sse (legacy alias). streamablehttp is the recommended transport for new setups; sse continues to work.
Connection methods: Supports Claude Desktop (configuration at ~/Library/Application Support/Claude/claude_desktop_config.json), Claude Code, Cursor (project .cursor/mcp.json), and Docker (the image does not include MATLAB; you must mount your own MATLAB installation).
Upgrade: If previously installed as matlab-mcp-server, uninstall first: pip uninstall matlab-mcp-server && pip install matlab-mcp-python.
Configuration: All settings are located in config.yaml, with sensible defaults, overridable via environment variables. Monitoring-related environment variable overrides such as MATLAB_MCP_MONITORING_ENABLED, MATLAB_MCP_MONITORING_SAMPLE_INTERVAL, etc.
Usage examples:
- Basic: Ask the AI agent to "compute the eigenvalues of a 3x3 magic square in MATLAB"; the agent calls execute_code, and the result is returned inline.
- Signal processing: "Generate a 1kHz sine wave, add noise, then filter it with a low-pass Butterworth filter and plot both"; returns an interactive Plotly chart + static PNG + thumbnail.
- Long-running simulation: "Run a Monte Carlo simulation with 1 million trials"; the agent immediately gets a job ID, polls progress, and retrieves results when complete.
Monitoring access: The dashboard is located at http://localhost:8766/dashboard(stdio)或 http://localhost:8765/dashboard(SSE)。健康端点状态码:200 indicates healthy/degraded, 503 indicates unhealthy. Available metrics include pool.utilization_pct, pool.total_engines, pool.busy_engines, jobs.completed_total, jobs.failed_total, jobs.avg_execution_ms, jobs.p95_execution_ms, sessions.active_count, system.memory_mb, system.cpu_percent, errors.total.
Workflow
The AI agent sends execute_code via the MCP protocol → SecurityValidator checks the code against the function blacklist → JobExecutor creates a job and acquires an engine from the pool → the code runs in MATLAB, with stdout/stderr captured via StringIO → if it completes within sync_timeout (30 seconds), the result is returned inline; if it times out, it is escalated to asynchronous, and the agent gets a job_id for polling → MetricsCollector.record_event() records the code + output + duration → the engine is released back to the pool and the workspace is reset.
Applicable scenarios
- Scenarios that require letting an AI agent directly call MATLAB for numerical computation, signal processing, simulation, and data analysis.
- Scenarios where multiple users share a single MATLAB installation and long-running asynchronous computation with progress feedback is needed.
- Teams that want to expose their own MATLAB function libraries to an AI agent without code changes.
- Operations scenarios that require visual monitoring of MATLAB job execution and resource utilization.
Limitations and information not provided
- Requires MATLAB R2022b+ and the MATLAB Engine API for Python; the Docker image does not include MATLAB and must be mounted separately.
- matlabengine is not a static dependency; it must be installed on demand via the install-engine task, and must be built on a machine with a matching MATLAB version.
- The materials do not provide specific license agreements, fees, or pricing information.
- The materials do not provide performance benchmarksdata, maximum concurrency, or specific scale limits for the engine pool.
- The materials do not provide detailed system compatibility information beyond the listed platforms (Windows, macOS, Linux via Pixi; Windows offline installation).