MATLAB MCP 服务器
该模型上下文协议 (MCP) 服务器提供与 MATLAB 的集成,允许您通过 Claude 或其他 MCP 客户端创建和执行 MATLAB 脚本和函数。
设置要求
Python 3.11(MATLAB Engine 目前不支持 Python 3.13 和 3.12)
MATLAB R2024a(或兼容版本)
uv 包管理器
安装
创建并设置 Python 环境:
安装 MATLAB 引擎 服务器首次运行时将使用
MATLAB_PATH环境变量中指定的 MATLAB 安装自动安装 MATLAB 引擎。
目录结构
matlab_server.py:主要的 MCP 服务器实现matlab_scripts/:保存所有 MATLAB 脚本和函数的目录(自动创建)pyproject.toml:Python 项目配置.python-version:指定 uv 的 Python 版本
Claude 桌面集成
打开您的 Claude Desktop 配置:
添加 MATLAB 服务器配置:
请确保:
将
/absolute/path/to/matlab-mcp替换为项目目录的实际路径验证
MATLAB_PATH指向您的 MATLAB 安装使用绝对路径(非相对路径)
特征
该服务器提供了几种工具:
create_matlab_script:创建一个新的 MATLAB 脚本文件脚本保存在
matlab_scripts目录中文件名必须是有效的 MATLAB 标识符
create_matlab_function:创建一个新的 MATLAB 函数文件函数保存在
matlab_scripts目录中必须包含有效的函数定义
execute_matlab_script:运行 MATLAB 脚本并获取结果返回输出文本、生成的图形和工作区变量
可以向脚本传递参数
call_matlab_function:使用参数调用 MATLAB 函数返回函数输出和任何生成的图形
测试
您可以使用 MCP 检查器测试服务器:
测试脚本示例:
脚本存储
所有 MATLAB 脚本和函数都保存在
matlab_scripts目录中该目录在服务器启动时自动创建
文件名为
<script_name>.m或<function_name>.m该目录与
matlab_server.py位于同一位置
环境变量
MATLAB_PATH:MATLAB 安装路径默认值:
/Applications/MATLAB_R2024a.app在 Claude Desktop 配置中设置或直接运行时
故障排除
MATLAB 引擎安装失败
验证 MATLAB_PATH 是否正确
尝试手动安装引擎:
cd $MATLAB_PATH/extern/engines/python python setup.py install
Python 版本问题
确保你使用的是 Python 3.11
检查:
python --version如果需要,请使用
uv python pin 3.11
脚本执行错误
检查
matlab_scripts目录是否存在验证脚本语法是否有效
在 MATLAB 输出中查找错误消息
更新和维护
保持 MATLAB 安装更新
根据需要更新 Python 包:
uv pip install --upgrade mcp[cli]更新 Python 时检查 MATLAB 引擎兼容性
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
允许通过 Claude 或其他 MCP 客户端创建和执行脚本和函数与 MATLAB 进行交互,支持脚本管理和执行结果检索以及环境配置功能。
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityAllows Claude desktop app to execute terminal commands and edit files on your computer through MCP, with features including command execution, process management, and diff-based file editing.Last updated -2123,2604,878MIT License
Fused MCP Agentsofficial
-security-license-qualityA Python-based MCP server that allows Claude and other LLMs to execute arbitrary Python code directly through your desktop Claude app, enabling data scientists to connect LLMs to APIs and executable code.Last updated -26MIT License- Asecurity-licenseAqualityA utility tool that enables Claude Desktop to interact with external tools via the Model Context Protocol, providing features like email sending and simple calculations while simplifying the MCP setup process.Last updated -2913MIT License
- -security-license-qualityAllows execution of MATLAB code from Python using the MATLAB Engine API, enabling a shared MATLAB session across multiple requests for seamless integration with Claude Desktop.Last updated -20MIT License