JM

jigarbhoye04/matlabmcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

20 stars 5 forks 质量 58 趋势 0MIT

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 runMatlabCode tool.
  • Retrieve Variables: Get the value of variables from the MATLAB workspace using the getVariable tool.
  • 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_thread to prevent blocking the server.
  • Standard Logging: Uses Python’s standard logging module, outputting to stderr for 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.
  • numpy Python package.

Installation

  1. Clone this repository:

    git clone https://github.com/jigarbhoye04/MatlabMCP.git
    cd MatlabMCP
    
  2. 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
    
  3. Install dependencies:

    uv pip sync
    
  4. Ensure MATLAB is installed and the MATLAB Engine API for Python is configured for your Python environment. See MATLAB Documentation.

  5. Start MATLAB and share its engine: Run the following command in the MATLAB Command Window:

    matlab.engine.shareEngine
    

    You can verify it’s shared by running matlab.engine.isEngineShared in MATLAB (it should return true or 1). The MCP server needs this shared engine to connect.

Configuration (for Claude Desktop)

To use this server with Claude Desktop:

  1. Go to Claude Desktop -> Settings -> Developer -> Edit Config.

  2. This will open claude_desktop_config.json. Add or modify the mcpServers section to include the MatlabMCP configuration:

    {
      "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"
          ]
在 GitHub 查看完整 README

安装

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 } }