
MCP服务器通过Matlab Engine API从LLM运行MATLAB代码。
概览
这是 MATLAB 模型上下文协议(MCP)服务器的实现。它允许 MCP 客户端(如 LLM 代理或 Claude Desktop)通过 Python 的 MATLAB Engine API 与共享的 MATLAB 会话交互。 * 通过runMatlabCode工具运行任意MATLAB代码片段。* 使用getVariable工具从MATLAB工作区获取变量的值。* 工具以结构化JSON形式返回结果和错误,方便客户端编程使用。* MATLAB引擎调用异步运行,使用asyncio.to_thread以防止服务器阻塞。* 使用Python的标准日志模块,输出为stderr以便客户端日志可见。* 连接现有的共享MATLAB会话。 DEVIN 提供的 MatlabMCP 维基百科。访问 DeepWiki 获取更详细且具说明性的建筑信息。 * Python 3.12 或更高版本 * MATLAB(- 查看 MATLAB Engine API 以获取 Python 兼容性),并安装了 Python 的 MATLAB Engine API。* numpy Python 包。 2.
概述(AI 翻译)
这是 MATLAB 模型上下文协议(MCP)服务器的实现。它允许 MCP 客户端(如 LLM 代理或 Claude Desktop)通过 Python 的 MATLAB Engine API 与共享的 MATLAB 会话交互。
特色
- 执行MATLAB代码: 通过
runMatlabCode工具运行任意MATLAB代码片段。 - 检索变量: 使用
getVariable工具从 MATLAB 工作区获取变量的值。 - 结构化通信: 工具以结构化JSON形式返回结果和错误,方便客户端编程使用。
- 非阻塞执行: MATLAB 引擎调用通过
asyncio.to_thread异步运行,以防止服务器阻塞。 - 标准日志: 使用 Python 的标准
logging模块,输出到stderr以显示客户端日志。 - 共享会话: 连接已有的共享MATLAB会话。
[!提示] MatlabMCP 维基百科,作者 DEVIN。 可以查看DeepWiki,获取更详细且具说明性的建筑信息。
要求
- Python 3.12 或更高版本
- MATLAB(建议使用R2023a或更高版本**——请查看MATLAB引擎API以获得Python兼容性),并安装了MATLAB Python引擎API。
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
MATLAB MCP Integration
This is an implementation of a Model Context Protocol (MCP) server for MATLAB. It allows MCP clients (like LLM agents or Claude Desktop) to interact with a shared MATLAB session using the MATLAB Engine API for Python.
Features
- Execute MATLAB Code: Run arbitrary MATLAB code snippets via the
runMatlabCodetool. - Retrieve Variables: Get the value of variables from the MATLAB workspace using the
getVariabletool. - Structured Communication: Tools return results and errors as structured JSON for easier programmatic use by clients.
- Non-Blocking Execution: MATLAB engine calls are run asynchronously using
asyncio.to_threadto prevent blocking the server. - Standard Logging: Uses Python’s standard
loggingmodule, outputting tostderrfor visibility in client logs. - Shared Session: Connects to an existing shared MATLAB session.
[!TIP] MatlabMCP wikipedia by DEVIN. Checkout DeepWiki for more detailed and illustrative information about architecture.
Requirements
- Python 3.12 or higher
- MATLAB (R2023a or higher recommended - check MATLAB Engine API for Python compatibility) with the MATLAB Engine API for Python installed.
numpyPython package.
Installation
-
Clone this repository:
git clone https://github.com/jigarbhoye04/MatlabMCP.git cd MatlabMCP -
Set up a Python virtual environment (recommended):
# 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 -
Install dependencies:
uv pip sync -
Ensure MATLAB is installed and the MATLAB Engine API for Python is configured for your Python environment. See MATLAB Documentation.
-
Start MATLAB and share its engine: Run the following command in the MATLAB Command Window:
matlab.engine.shareEngineYou can verify it’s shared by running
matlab.engine.isEngineSharedin MATLAB (it should returntrueor1). The MCP server needs this shared engine to connect.
Configuration (for Claude Desktop)
To use this server with Claude Desktop:
-
Go to Claude Desktop -> Settings -> Developer -> Edit Config.
-
This will open
claude_desktop_config.json. Add or modify themcpServerssection to include theMatlabMCPconfiguration:{ "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" ]
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"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
}
}