Skip to main content
Glama

MATLAB MCP Server

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文件。
  • 添加工作区管理工具(例如clearWorkspacegetWorkspaceVariables )。
  • 扩展matlab_to_python助手来处理更复杂的数据类型(结构、单元格数组、对象)。
  • 添加与 Simulink 模型交互的支持。

要求

  • Python 3.12 或更高版本
  • 安装了 MATLAB Engine API for Python 的 MATLAB(建议使用 R2023a 或更高版本- 检查 MATLAB Engine API for Python 兼容性)。
  • numpy Python 包。

安装

  1. 克隆此存储库:
    git clone https://github.com/jigarbhoye04/MatlabMCP.git cd MatlabMCP
  2. 设置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
  3. 安装依赖项:
    uv pip sync
  4. 确保已安装 MATLAB,并已为您的 Python 环境配置适用于 Python 的 MATLAB 引擎 API。请参阅MATLAB 文档
  5. **启动 MATLAB 并共享其引擎:**在 MATLAB 命令窗口中运行以下命令:
    matlab.engine.shareEngine
    您可以通过在 MATLAB 中运行matlab.engine.isEngineShared来验证它是否已共享(它应该返回true1 )。MCP 服务器需要此共享引擎才能连接。

配置(适用于 Claude Desktop)

要将此服务器与 Claude Desktop 一起使用:

  1. 转到 Claude Desktop -> 设置 -> 开发人员 -> 编辑配置。
  2. 这将打开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 } }
  3. 重要提示:C:\\Users\\username\\...路径替换为系统的正确绝对路径
  4. 保存文件并重新启动 Claude Desktop
  5. **日志记录:**服务器日志(来自 Python 的logging模块)将出现在 Claude Desktop 的 MCP 日志文件中(可通过 macOS 上的tail -f ~/Library/Logs/Claude/mcp-server-MatlabMCP.log访问或在 Windows 上检查%APPDATA%\Claude\logs\访问)。

发展

项目结构:

MatlabMCP/ ├── .venv/ # Virtual environment created by uv ├── Docs/ │ └── Images/ │ └── Updates.md # Documentation for updates and changes ├── main.py # The MCP server script ├── pyproject.toml # Project metadata and dependencies ├── README.md # This file └── uv.lock # Lock file for dependencies

文档

查看更新以获取有关服务器功能、使用和开发说明的详细文档。

贡献

欢迎贡献代码!如果您有任何建议或改进,欢迎随时创建 issue 或提交 Pull 请求。

让我们一起让它变得更好!

-
security - not tested
A
license - permissive license
-
quality - not tested

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 无缝集成。

  1. 特征
    1. 待办事项:
  2. 要求
    1. 安装
      1. 配置(适用于 Claude Desktop)
        1. 发展
          1. 文档
            1. 贡献

              Related MCP Servers

              • -
                security
                F
                license
                -
                quality
                Allows 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 -
                10
                Python
                • Apple
              • -
                security
                A
                license
                -
                quality
                The server facilitates access to Julia documentation and source code through Claude Desktop, allowing users to retrieve information on Julia packages, modules, types, functions, and methods.
                Last updated -
                4
                0
                2
                JavaScript
                MIT License
              • A
                security
                A
                license
                A
                quality
                Integrates MATLAB with AI to execute code, generate scripts from natural language, and access MATLAB documentation seamlessly.
                Last updated -
                2
                29
                JavaScript
                Apache 2.0
                • Apple
                • Linux
              • A
                security
                F
                license
                A
                quality
                A server that enables Claude Desktop users to access the Claude API directly, allowing them to bypass Professional Plan limitations and use advanced features like custom system prompts and conversation management.
                Last updated -
                1
                5
                Python
                • Apple

              View all related MCP servers

              MCP directory API

              We provide all the information about MCP servers via our MCP API.

              curl -X GET 'https://glama.ai/api/mcp/v1/servers/jigarbhoye04/MatlabMCP'

              If you have feedback or need assistance with the MCP directory API, please join our Discord server