MATLAB MCP 集成
这是 MATLAB 模型上下文协议 (MCP) 服务器的实现。它允许 MCP 客户端(例如 LLM 代理或 Claude Desktop)使用 Python 版 MATLAB 引擎 API 与共享的 MATLAB 会话进行交互。
特征
**执行 MATLAB 代码:**通过
runMatlabCode工具运行任意 MATLAB 代码片段。**检索变量:**使用
getVariable工具从 MATLAB 工作区获取变量的值。**结构化通信:**工具以结构化 JSON 的形式返回结果和错误,以便客户端更轻松地以编程方式使用。
非阻塞执行: MATLAB 引擎调用使用
asyncio.to_thread异步运行,以防止阻塞服务器。**标准日志记录:**使用 Python 的标准
logging模块,输出到stderr以便在客户端日志中可见。**共享会话:**连接到现有的共享 MATLAB 会话。
待办事项:
添加
setVariable工具以将数据写入 MATLAB 工作区。添加
runScript工具直接执行.m文件。添加工作区管理工具(例如
clearWorkspace、getWorkspaceVariables)。扩展
matlab_to_python助手来处理更复杂的数据类型(结构、单元格数组、对象)。添加与 Simulink 模型交互的支持。
要求
Python 3.12 或更高版本
安装了 MATLAB Engine API for Python 的 MATLAB(建议使用 R2023a 或更高版本- 检查 MATLAB Engine API for Python 兼容性)。
numpyPython 包。
安装
克隆此存储库:
git clone https://github.com/jigarbhoye04/MatlabMCP.git cd MatlabMCP设置Python虚拟环境(推荐):
# Install uv if you haven't already: https://github.com/astral-sh/uv uv init uv venv source .venv/bin/activate # On Windows use: .venv\Scripts\activate安装依赖项:
uv pip sync确保已安装 MATLAB,并已为您的 Python 环境配置适用于 Python 的 MATLAB 引擎 API。请参阅MATLAB 文档。
**启动 MATLAB 并共享其引擎:**在 MATLAB 命令窗口中运行以下命令:
matlab.engine.shareEngine您可以通过在 MATLAB 中运行
matlab.engine.isEngineShared来验证它是否已共享(它应该返回true或1)。MCP 服务器需要此共享引擎才能连接。
配置(适用于 Claude Desktop)
要将此服务器与 Claude Desktop 一起使用:
转到 Claude Desktop -> 设置 -> 开发人员 -> 编辑配置。
这将打开
claude_desktop_config.json。添加或修改mcpServers部分以包含MatlabMCP配置:{ "mcpServers": { "MatlabMCP": { "command": "C:\\Users\\username\\.local\\bin\\uv.exe", // Path to your uv executable "args": [ "--directory", "C:\\Users\\username\\Desktop\\MatlabMCP\\", // ABSOLUTE path to the cloned repository directory "run", "main.py" ] // Optional: Add environment variables if needed // "env": { // "MY_VAR": "value" // } } // Add other MCP servers here if you have them } }重要提示:。
保存文件并重新启动 Claude Desktop 。
**日志记录:**服务器日志(来自 Python 的
logging模块)将出现在 Claude Desktop 的 MCP 日志文件中(可通过 macOS 上的tail -f ~/Library/Logs/Claude/mcp-server-MatlabMCP.log访问或在 Windows 上检查%APPDATA%\Claude\logs\访问)。
发展
项目结构:
文档
查看更新以获取有关服务器功能、使用和开发说明的详细文档。
贡献
欢迎贡献代码!如果您有任何建议或改进,欢迎随时创建 issue 或提交 Pull 请求。
让我们一起让它变得更好!
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.
允许使用 MATLAB 引擎 API 从 Python 执行 MATLAB 代码,从而实现跨多个请求的共享 MATLAB 会话,从而与 Claude Desktop 无缝集成。
Related MCP Servers
- -security-license-qualityAllows interaction with MATLAB by creating and executing scripts and functions through Claude or other MCP clients, supporting script management and execution result retrieval with environment configuration capabilities.Last updated -32
- Asecurity-licenseAqualityFacilitates running Python code in a sandbox and generating images using the FLUX model via an MCP server compatible with clients like Goose and the Claude Desktop App.Last updated -222MIT License
- Asecurity-licenseAqualityIntegrates MATLAB with AI to execute code, generate scripts from natural language, and access MATLAB documentation seamlessly.Last updated -246Apache 2.0
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