Skip to content

Commit 01cfe3b

Browse files
committed
MATLAB MCP Core Server v0.1.0
1 parent 2b266b9 commit 01cfe3b

File tree

330 files changed

+38634
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

330 files changed

+38634
-0
lines changed

.copyright-ignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
internal/adaptors/application/config/assets/version
2+
internal/adaptors/mcp/server/assets/**
3+
internal/wire/wire_gen.go
4+
licenses/**
5+
mocks/**
6+
go.sum
7+
SECURITY.md
8+
*.pem

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
# Copyright 2025 The MathWorks, Inc.
12
# Auto detect text files and perform LF normalization
23
* text=auto

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.bin
2+
/cover.out
3+
/vendor

.golangci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright 2025 The MathWorks, Inc.
2+
version: "2"
3+
4+
linters:
5+
default: standard
6+
enable:
7+
- revive # Comprehensive Go linter with extensive rules
8+
- gosec # Security scanner for Go code
9+
- govet # Go static analyzer for common errors
10+
- usetesting # Static analysis for testing best practices
11+
- testifylint # Linter for testify assertions and mocking
12+
- unused
13+
- inamedparam
14+
- gochecknoglobals
15+
- misspell
16+
- tagalign
17+
- errcheck
18+
- bodyclose
19+
- staticcheck
20+
- nolintlint
21+
- iface
22+
- gomodguard
23+
- testableexamples
24+
disable:
25+
# Maybe enable
26+
- tagliatelle
27+
- thelper
28+
- ireturn
29+
- exhaustruct
30+
- lll
31+
# Actually disable these ones
32+
- depguard
33+
- wsl
34+
- wrapcheck
35+
- paralleltest
36+
- nlreturn
37+
- godot
38+
settings:
39+
gomodguard:
40+
allowed:
41+
domains:
42+
- golang.org
43+
- github.com/google/jsonschema-go
44+
- github.com/modelcontextprotocol
45+
- github.com/stretchr/testify
46+
- github.com/google/uuid
47+
- github.com/spf13/pflag
48+
nolintlint:
49+
require-explanation: true
50+
revive:
51+
rules:
52+
# Disable check which requires all packages exports to have documenting string
53+
- name: exported
54+
disabled: true
55+
usetesting:
56+
context-background: true
57+
os-temp-dir: true
58+
exclusions:
59+
generated: lax
60+
rules:
61+
# Allow underscores in test function names specifically
62+
- path: tests/
63+
linters:
64+
- revive
65+
text: "don't use underscores in Go names; method Test"
66+
67+
formatters:
68+
enable:
69+
- gofmt
70+
- goimports
71+
72+
issues:
73+
max-same-issues: 0
74+
max-issues-per-linter: 0
75+
76+
run:
77+
relative-path-mode: gomod

.mockery.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright 2025 The MathWorks, Inc.
2+
3+
all: true
4+
filename: '{{.InterfaceName}}.go'
5+
pkgname: 'mocks'
6+
packages:
7+
github.com/matlab/matlab-mcp-core-server/internal:
8+
config:
9+
dir: 'mocks/{{.InterfaceDirRelative | trimPrefix "internal" }}'
10+
recursive: true
11+
all: true

.vscode/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/*
2+
3+
!.gitignore
4+
!settings.json

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"gopls": {
3+
"build.buildFlags": [
4+
"-tags=wireinject"
5+
]
6+
}
7+
}

LICENSE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright 2025 The MathWorks, Inc.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
5+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
7+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8+
9+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10+
11+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Copyright 2025 The MathWorks, Inc.
2+
3+
# Set shell based on OS
4+
ifeq ($(OS),Windows_NT)
5+
SHELL = powershell.exe
6+
else
7+
SHELL = sh
8+
endif
9+
10+
SEMANTIC_VERSION=v0.1.0
11+
COMMIT_HASH := $(shell git rev-parse HEAD)
12+
13+
# Append Git commit hash to version unless building a release
14+
ifeq ($(RELEASE),true)
15+
VERSION := $(SEMANTIC_VERSION)
16+
else
17+
VERSION := $(SEMANTIC_VERSION).$(COMMIT_HASH)
18+
endif
19+
20+
ifeq ($(OS),Windows_NT)
21+
RM_DIR = if (Test-Path "$(1)") { Remove-Item -Recurse -Force "$(1)" }
22+
PATHSEP = ;
23+
BIN_PATH = $(CURDIR)/.bin/win64
24+
else
25+
RM_DIR = rm -rf $(1)
26+
PATHSEP = :
27+
BIN_PATH = $(CURDIR)/.bin/glnxa64
28+
endif
29+
30+
# Go build flags
31+
LDFLAGS := -ldflags "-X 'github.com/matlab/matlab-mcp-core-server/internal/adaptors/application/config.version=$(VERSION)'"
32+
33+
34+
all: install wire mockery lint unit-tests build
35+
36+
version:
37+
@echo $(VERSION)
38+
39+
mcp-inspector: build
40+
ifeq ($(OS),Windows_NT)
41+
$$env:HOST='localhost'; $$env:PATH='$(BIN_PATH)$(PATHSEP)$(PATH)'; npx @modelcontextprotocol/inspector matlab-mcp-core-server
42+
else
43+
HOST=localhost PATH="$(BIN_PATH)$(PATHSEP)$(PATH)" npx @modelcontextprotocol/inspector $(if $(DISPLAY),-e DISPLAY=$(DISPLAY)) matlab-mcp-core-server
44+
endif
45+
46+
47+
# File checks
48+
49+
install:
50+
go install github.com/google/wire/cmd/wire@latest
51+
go install github.com/vektra/mockery/v3@latest
52+
go install gotest.tools/gotestsum@latest
53+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2
54+
55+
wire:
56+
wire github.com/matlab/matlab-mcp-core-server/internal/wire
57+
58+
mockery:
59+
@$(call RM_DIR,./mocks)
60+
mockery
61+
62+
lint:
63+
golangci-lint run ./...
64+
65+
fix-lint:
66+
golangci-lint run ./... --fix
67+
68+
# Building
69+
70+
build: build-for-windows build-for-glnxa64 build-for-maci64 build-for-maca64
71+
72+
build-for-windows:
73+
ifeq ($(OS),Windows_NT)
74+
$$env:GOOS='windows'; $$env:GOARCH='amd64'; go build $(LDFLAGS) -o ./.bin/win64/matlab-mcp-core-server.exe ./cmd/matlab-mcp-core-server
75+
else
76+
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o ./.bin/win64/matlab-mcp-core-server.exe ./cmd/matlab-mcp-core-server
77+
endif
78+
79+
build-for-glnxa64:
80+
ifeq ($(OS),Windows_NT)
81+
$$env:GOOS='linux'; $$env:GOARCH='amd64'; go build $(LDFLAGS) -o ./.bin/glnxa64/matlab-mcp-core-server ./cmd/matlab-mcp-core-server
82+
else
83+
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o ./.bin/glnxa64/matlab-mcp-core-server ./cmd/matlab-mcp-core-server
84+
endif
85+
86+
build-for-maci64:
87+
ifeq ($(OS),Windows_NT)
88+
$$env:GOOS='darwin'; $$env:GOARCH='amd64'; go build $(LDFLAGS) -o ./.bin/maci64/matlab-mcp-core-server ./cmd/matlab-mcp-core-server
89+
else
90+
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o ./.bin/maci64/matlab-mcp-core-server ./cmd/matlab-mcp-core-server
91+
endif
92+
93+
build-for-maca64:
94+
ifeq ($(OS),Windows_NT)
95+
$$env:GOOS='darwin'; $$env:GOARCH='arm64'; go build $(LDFLAGS) -o ./.bin/maca64/matlab-mcp-core-server ./cmd/matlab-mcp-core-server
96+
else
97+
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o ./.bin/maca64/matlab-mcp-core-server ./cmd/matlab-mcp-core-server
98+
endif
99+
100+
# Testing
101+
102+
unit-tests:
103+
gotestsum --packages ./internal/... -- -race -coverprofile cover.out
104+
105+
ci-unit-tests:
106+
go test -race -json -count=1 -coverprofile cover.out ./internal/...
107+
108+
ci-system-tests:
109+
go test -race -timeout 120m -json -count=1 ./tests/system/

README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# MATLAB MCP Core Server
2+
3+
Run MATLAB® using AI applications. The MATLAB MCP Core Server allows your AI applications to:
4+
5+
- Start and quit MATLAB.
6+
- Write and run MATLAB code.
7+
- Assess your MATLAB code for style and correctness.
8+
9+
## Table of Contents
10+
- [Setup](#setup)
11+
- [Claude Code](#claude-code)
12+
- [Claude Desktop](#claude-desktop)
13+
- [GitHub Copilot in Visual Studio Code](#github-copilot-in-visual-studio-code)
14+
- [Arguments](#arguments)
15+
- [Tools](#tools)
16+
- [Data Collection](#data-collection)
17+
- [Disclaimer](#disclaimer)
18+
19+
## Setup
20+
21+
1. Install [MATLAB (MathWorks)](https://www.mathworks.com/help/install/ug/install-products-with-internet-connection.html) 2020b or later and add it to the system PATH.
22+
2. Download the [Latest Release](https://github.com/matlab/matlab-mcp-core-server/releases/latest) from GitHub®. Alternatively, you can install [Go](https://go.dev/doc/install) and build the binary from source using `go install github.com/matlab/matlab-mcp-core-server/cmd/matlab-mcp-core-server`.
23+
3. Add the MATLAB MCP Core Server to your AI application. You can find instructions for adding MCP servers in the documentation of your AI application. For example instructions on using Claude Code®, Claude Desktop®, and GitHub Copilot in Visual Studio® Code, see below. Note that you can customize the server by specifying optional [arguments](#arguments).
24+
25+
#### Claude Code
26+
27+
In your terminal, run the following, remembering to insert the full path to the server binary you acquired in the setup:
28+
```sh
29+
claude mcp add --transport stdio matlab /fullpath/to/matlab-mcp-core-server-binary [arguments...]
30+
```
31+
You can customize the server by specifying [arguments](#arguments):
32+
```sh
33+
claude mcp add --transport stdio matlab /fullpath/to/matlab-mcp-core-server-binary --initial-working-folder=/home/username/myproject
34+
```
35+
36+
For details on adding MCP servers in Claude Code, see [Add a local stdio server (Claude Code)](https://docs.claude.com/en/docs/claude-code/mcp#option-3%3A-add-a-local-stdio-server). To remove the server later, run:
37+
```sh
38+
claude mcp remove matlab
39+
```
40+
41+
#### Claude Desktop
42+
43+
Follow the instructions on the page [Connect to local MCP servers (MCP)](https://modelcontextprotocol.io/docs/develop/connect-local-servers) to install Node.js and the Filesystem Server. In your Claude Desktop configuration file, you need to add the configuration for the MATLAB MCP Core Server as well as the Filesystem Server. You can use the combined JSON below. In the Filesystem `args`, remember to specify which paths the server can access. In the MATLAB `args`, remember to insert the full path to the server binary you acquired, as well as any other arguments:
44+
45+
```json
46+
{
47+
"mcpServers": {
48+
"filesystem": {
49+
"command": "npx",
50+
"args": [
51+
"-y",
52+
"@modelcontextprotocol/server-filesystem",
53+
"C:\\Users\\username"
54+
]
55+
},
56+
"matlab": {
57+
"command": "fullpath\\to\\matlab-mcp-core-server-binary",
58+
"args": [
59+
"--initial-working-folder=C:\\Users\\username\\Documents"
60+
]
61+
}
62+
}
63+
}
64+
```
65+
After saving the configuration file, quit and restart Claude Desktop.
66+
67+
#### GitHub Copilot in Visual Studio Code
68+
69+
VS Code provides different methods to [Add an MCP Server (VS Code)](https://code.visualstudio.com/docs/copilot/customization/mcp-servers?wt.md_id=AZ-MVP-5004796#_add-an-mcp-server). MathWorks recommends you follow the steps in the section **"Add an MCP server to a workspace `mcp.json` file"**. In your `mcp.json` configuration file, add the following, remembering to insert the full path to the server binary you acquired in the setup, as well as any arguments:
70+
```json
71+
{
72+
"servers": {
73+
"matlab": {
74+
"type": "stdio",
75+
"command": "/fullpath/to/matlab-mcp-core-server-binary",
76+
"args": []
77+
}
78+
}
79+
}
80+
```
81+
82+
## Arguments
83+
84+
Customize the behavior of the server by providing arguments in the `args` array when configuring your AI application.
85+
86+
| Argument | Description | Example |
87+
| ------------- | ------------- | ------------- |
88+
| matlab-root | Full path specifying which MATLAB to start. Do not include `/bin` in the path. By default, the server tries to find the first MATLAB on the system PATH. | `"--matlab-root=/home/usr/MATLAB/R2025a"` |
89+
| initial-working-folder | Specify the folder where MATLAB starts and where the server generates any MATLAB scripts. If you do not provide the argument, MATLAB starts in the folder specified by the last entry in your list of [Roots (MCP)](https://modelcontextprotocol.io/specification/2025-06-18/client/roots). If you do not specify a root, MATLAB starts in these locations: <br><br> <ul><li>Linux: `/home/username` </li><li> Windows: `C:\Users\username\Documents`</li><li>Mac: `/Users/username/Documents`</li></ul> | `"--initial-working-folder=C:\\Users\\name\\MyProject"` |
90+
| disable-telemetry | To disable anonymized data collection, set this argument to `true`. For details, see [Data Collection](#data-collection). | `"--disable-telemetry=true"` |
91+
92+
## Tools
93+
94+
1. `detect_matlab_toolboxes`
95+
- Lists installed MATLAB toolboxes with version information.
96+
97+
2. `check_matlab_code`
98+
- Performs static code analysis on a MATLAB script. Returns warnings about coding style, potential errors, deprecated functions, performance issues, and best practice violations. This is a non-destructive, read-only operation that helps identify code quality issues without executing the script.
99+
- Inputs:
100+
- `script_path` (string): Absolute path to the MATLAB script file to analyze. Must be a `.m` file within an allowed directory. The file is not modified during analysis. Example: `C:\Users\username\matlab\myFunction.m` or `/home/user/scripts/analysis.m`.
101+
102+
3. `evaluate_matlab_code`
103+
- Evaluates a string of MATLAB code and returns the output.
104+
- Inputs:
105+
- `code` (string): MATLAB code to evaluate.
106+
- `project_path` (string): Absolute path to an allowed project directory. MATLAB sets this directory as the current working folder. Example: `C:\Users\username\matlab-project` or `/home/user/research`.
107+
108+
4. `run_matlab_file`
109+
- Executes a MATLAB script and returns the output. The script must be a valid `.m file`.
110+
- Inputs:
111+
- `script_path` (string): Absolute path to the MATLAB script file to execute. Must be a valid `.m` file within an allowed directory. Example: `C:\Users\username\projects\analysis.m` or `/home/user/matlab/simulation.m`.
112+
113+
5. `run_matlab_test_file`
114+
- Executes a MATLAB test script and returns comprehensive test results. Designed specifically for MATLAB unit test files that follow MATLAB testing framework conventions.
115+
- Inputs:
116+
- `script_path` (string): Absolute path to the MATLAB test script file. Must be a valid `.m` file containing MATLAB unit tests, within an allowed directory. Example: `C:\Users\username\tests\testMyFunction.m` or `/home/user/matlab/tests/test_analysis.m`.
117+
118+
## Data Collection
119+
120+
The MATLAB MCP Core Server may collect fully anonymized information about your usage of the server and send it to MathWorks. This data collection helps MathWorks improve products and is on by default. To opt out of data collection, set the argument `--disable-telemetry` to `true`.
121+
122+
## Disclaimer
123+
124+
The MATLAB MCP Core Server is provided "as is" without warranties of any kind, expressed or implied. By using this server, you acknowledge and accept that you are solely responsible for any actions taken and any consequences arising from its use. It is your responsibility to thoroughly review and validate all tool calls before execution. The developers and providers of this server disclaim any liability for loss, damage, or injury resulting from its use.
125+
126+
---
127+
128+
Copyright 2025 The MathWorks, Inc.
129+
130+
----

0 commit comments

Comments
 (0)