建模上下文协议服务器,允许大型语言模型编写和执行 matlab 脚本
概览
该模型上下文协议(MCP)服务器支持与MATLAB集成,允许您通过Claude或其他MCP客户端创建和执行MATLAB脚本和函数。 - Python 3.11(Python 3.13 和 3.12 目前不被 MATLAB Engine 支持 )- MATLAB R2024a(或兼容版本)- uv 包管理器 1. 创建并搭建Python环境: 2. 安装MATLAB引擎 MATLAB引擎将在服务器首次运行时自动安装,使用MATLAB_PATH环境变量中指定的MATLAB安装。 - matlab_server.py:主MCP服务器实现 - matlab_scripts/: 目录,所有MATLAB脚本和函数自动保存(创建)- pyproject.toml:Python项目配置- .python-version:指定uv的Python版本 1.
概述(AI 翻译)
该模型上下文协议(MCP)服务器支持与MATLAB集成,允许您通过Claude或其他MCP客户端创建和执行MATLAB脚本和函数。
设置要求
- Python 3.11(Python 3.13 和 3.12 目前不被 MATLAB Engine 支持 Python 3.13)
- MATLAB R2024a(或兼容版本)
- UV包管理器
安装
-
创建并搭建Python环境:
-
安装MATLAB引擎 MATLAB 引擎将在服务器首次运行时自动安装,使用环境变量
MATLAB_PATH中指定的 MATLAB 安装。
目录结构
matlab_server.py:主要MCP服务器实现matlab_scripts/:所有MATLAB脚本和函数保存(自动创建)的目录pyproject.toml:Python 项目配置.python-version:指定 Python 版本的 uv
Claude桌面集成
-
打开您的Claude桌面配置:
-
添加MATLAB服务器配置:
务必:
- 将
/absolute/path/to/matlab-mcp替换为你项目目录的实际路径 - 验证
MATLAB_PATH指向您的MATLAB安装 - 使用绝对路径(非相对路径)
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
MATLAB MCP Server
This Model Context Protocol (MCP) server provides integration with MATLAB, allowing you to create and execute MATLAB scripts and functions through Claude or other MCP clients.
Setup Requirements
- Python 3.11 (Python 3.13 and 3.12 are not currently supported by MATLAB Engine)
- MATLAB R2024a (or compatible version)
- uv package manager
Installation
- Create and set up the Python environment:
# Pin Python version
uv python pin 3.11
# Create virtual environment
uv venv
# Activate virtual environment
source .venv/bin/activate
# Install MCP
uv add "mcp[cli]"
- Install MATLAB Engine
The MATLAB Engine will be installed automatically when the server first runs, using the MATLAB installation specified in the
MATLAB_PATHenvironment variable.
Directory Structure
matlab_server.py: The main MCP server implementationmatlab_scripts/: Directory where all MATLAB scripts and functions are saved (created automatically)pyproject.toml: Python project configuration.python-version: Specifies Python version for uv
Claude Desktop Integration
- Open your Claude Desktop configuration:
# On macOS
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
- Add the MATLAB server configuration:
{
"mcpServers": {
"matlab": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/matlab-mcp",
"run",
"matlab_server.py"
],
"env": {
"MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
}
}
}
}
Make sure to:
- Replace
/absolute/path/to/matlab-mcpwith the actual path to your project directory - Verify the
MATLAB_PATHpoints to your MATLAB installation - Use absolute paths (not relative)
Features
The server provides several tools:
-
create_matlab_script: Create a new MATLAB script file- Scripts are saved in the
matlab_scriptsdirectory - File names must be valid MATLAB identifiers
- Scripts are saved in the
-
create_matlab_function: Create a new MATLAB function file- Functions are saved in the
matlab_scriptsdirectory - Must include valid function definition
- Functions are saved in the
-
execute_matlab_script: Run a MATLAB script and get results- Returns output text, generated figures, and workspace variables
- Can pass arguments to scripts
-
call_matlab_function: Call a MATLAB function with arguments- Returns function output and any generated figures
Testing
You can test the server using the MCP Inspector:
# Make sure you're in your virtual environment
source .venv/bin/activate
# Run the inspector
MATLAB_PATH=/Applications/MATLAB_R2024a.app mcp dev matlab_server.py
Example test script:
t = 0:0.01:2*pi;
y = sin(t);
plot(t, y);
title('Test Plot');
xlabel('Time');
ylabel('Amplitude');
Script Storage
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"matlab": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/matlab-mcp",
"run",
"matlab_server.py"
],
"env": {
"MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
}
}
}
}