TM

tsuchijo/matlab-mcp

开发工具

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

40 stars 4 forks 质量 56 趋势 12

建模上下文协议服务器,允许大型语言模型编写和执行 matlab 脚本

概览

该模型上下文协议(MCP)服务器支持与MATLAB集成,允许您通过Claude或其他MCP客户端创建和执行MATLAB脚本和函数。 - Python 3.11(Python 3.13 和 3.12 目前不被 MATLAB Engine 支持 )- MATLAB R2024a(或兼容版本)- uv 包管理器 1. 创建并搭建Python环境: 2. 安装MATLAB引擎 MATLAB引擎将在服务器首次运行时自动安装,使用MATLAB_PATH环境变量中指定的MATLAB安装。 - matlab_server.py:主MCP服务器实现 - matlab_scripts/: 目录,所有MATLAB脚本和函数自动保存(创建)- pyproject.toml:Python项目配置- .python-version:指定uv的Python版本 1.

概述(AI 翻译)

该模型上下文协议(MCP)服务器支持与MATLAB集成,允许您通过Claude或其他MCP客户端创建和执行MATLAB脚本和函数。

设置要求

  • Python 3.11(Python 3.13 和 3.12 目前不被 MATLAB Engine 支持 Python 3.13)
  • MATLAB R2024a(或兼容版本)
  • UV包管理器

安装

  1. 创建并搭建Python环境:

  2. 安装MATLAB引擎 MATLAB 引擎将在服务器首次运行时自动安装,使用环境变量 MATLAB_PATH 中指定的 MATLAB 安装。

目录结构

  • matlab_server.py:主要MCP服务器实现
  • matlab_scripts/:所有MATLAB脚本和函数保存(自动创建)的目录
  • pyproject.toml:Python 项目配置
  • .python-version:指定 Python 版本的 uv

Claude桌面集成

  1. 打开您的Claude桌面配置:

  2. 添加MATLAB服务器配置:

务必:

  • 将/absolute/path/to/matlab-mcp替换为你项目目录的实际路径
  • 验证MATLAB_PATH指向您的MATLAB安装
  • 使用绝对路径(非相对路径)

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

README

以下为原文 README 节选,完整内容请查看原文。

MATLAB MCP Server

This Model Context Protocol (MCP) server provides integration with MATLAB, allowing you to create and execute MATLAB scripts and functions through Claude or other MCP clients.

Setup Requirements

  • Python 3.11 (Python 3.13 and 3.12 are not currently supported by MATLAB Engine)
  • MATLAB R2024a (or compatible version)
  • uv package manager

Installation

  1. Create and set up the Python environment:
# Pin Python version
uv python pin 3.11

# Create virtual environment
uv venv

# Activate virtual environment
source .venv/bin/activate

# Install MCP
uv add "mcp[cli]"
  1. Install MATLAB Engine The MATLAB Engine will be installed automatically when the server first runs, using the MATLAB installation specified in the MATLAB_PATH environment variable.

Directory Structure

  • matlab_server.py: The main MCP server implementation
  • matlab_scripts/: Directory where all MATLAB scripts and functions are saved (created automatically)
  • pyproject.toml: Python project configuration
  • .python-version: Specifies Python version for uv

Claude Desktop Integration

  1. Open your Claude Desktop configuration:
# On macOS
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
  1. Add the MATLAB server configuration:
{
    "mcpServers": {
        "matlab": {
            "command": "uv",
            "args": [
                "--directory",
                "/absolute/path/to/matlab-mcp",
                "run",
                "matlab_server.py"
            ],
            "env": {
                "MATLAB_PATH": "/Applications/MATLAB_R2024a.app"
            }
        }
    }
}

Make sure to:

  • Replace /absolute/path/to/matlab-mcp with the actual path to your project directory
  • Verify the MATLAB_PATH points to your MATLAB installation
  • Use absolute paths (not relative)

Features

The server provides several tools:

  1. create_matlab_script: Create a new MATLAB script file

    • Scripts are saved in the matlab_scripts directory
    • File names must be valid MATLAB identifiers
  2. create_matlab_function: Create a new MATLAB function file

    • Functions are saved in the matlab_scripts directory
    • Must include valid function definition
  3. execute_matlab_script: Run a MATLAB script and get results

    • Returns output text, generated figures, and workspace variables
    • Can pass arguments to scripts
  4. call_matlab_function: Call a MATLAB function with arguments

    • Returns function output and any generated figures

Testing

You can test the server using the MCP Inspector:

# Make sure you're in your virtual environment
source .venv/bin/activate

# Run the inspector
MATLAB_PATH=/Applications/MATLAB_R2024a.app mcp dev matlab_server.py

Example test script:

t = 0:0.01:2*pi;
y = sin(t);
plot(t, y);
title('Test Plot');
xlabel('Time');
ylabel('Amplitude');

Script Storage

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "matlab": { "command": "uv", "args": [ "--directory", "/absolute/path/to/matlab-mcp", "run", "matlab_server.py" ], "env": { "MATLAB_PATH": "/Applications/MATLAB_R2024a.app" } } } }