$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-create-projectCreates a MATLAB project for an existing folder of MATLAB files using the matlab.project.* APIs via MCP. Adds all existing files, configures the project path, generates a project name/description, and creates a README.md with a function table. Prompts the user before creating any
| 1 | # MATLAB Project Creation |
| 2 | |
| 3 | Creates a fully configured MATLAB project from an existing folder of MATLAB code using `matlab.project.*` APIs via the MATLAB MCP server. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - User says "create a project", "set up a MATLAB project", or "initialize project" |
| 8 | - User has a folder of MATLAB files that needs project infrastructure |
| 9 | - Before `matlab-create-buildfile` — a project must exist first |
| 10 | |
| 11 | ## When NOT to Use |
| 12 | |
| 13 | - A MATLAB project already exists (`.prj` file with `resources/project/` folder) — use `openProject` instead |
| 14 | - User wants to create a toolbox spec — use `matlab-define-toolbox-api` |
| 15 | - User wants build automation — use `matlab-create-buildfile` (after the project exists) |
| 16 | |
| 17 | ## Key Functions |
| 18 | |
| 19 | | Function | Purpose | |
| 20 | |----------|---------| |
| 21 | | `matlab.project.createProject` | Create a new project with specified definition type | |
| 22 | | `openProject` | Open an existing project (fallback if one already exists) | |
| 23 | | `addFile` | Add files to the project | |
| 24 | | `addPath` | Add folders to the project path | |
| 25 | | `genpath` | Generate path string for folder tree (excludes +pkg, @class, private) | |
| 26 | |
| 27 | ## Critical Rules |
| 28 | |
| 29 | 1. **NEVER overwrite existing files.** Before creating any file (README.md, etc.), check if it already exists. If it does, skip or ask the user. |
| 30 | 2. **ALWAYS prompt the user before creating new folders.** Present recommended folders in a table with their purpose and wait for confirmation before `mkdir`. |
| 31 | 3. **Do NOT move or rename any existing files.** |
| 32 | |
| 33 | ## Inputs |
| 34 | |
| 35 | | Input | Required | Description | |
| 36 | |-------|----------|-------------| |
| 37 | | Project path | Yes | Absolute path to the folder to make into a project | |
| 38 | | Project name | No | Override auto-detected name (default: inferred from code) | |
| 39 | |
| 40 | ## Workflow |
| 41 | |
| 42 | ### 1. Discover Existing Content |
| 43 | |
| 44 | - List all files in the project folder (recursively) |
| 45 | - If a `.prj` file exists, ask the user — it could be a MATLAB project or a legacy deploytool file: |
| 46 | > A) **This is a MATLAB project** — open it with `openProject` instead of creating a new one |
| 47 | > B) **This is a legacy deploytool file** — proceed with creating a new MATLAB project |
| 48 | - Read `Contents.m` if present — it provides authoritative function descriptions and categorization |
| 49 | - If no `Contents.m`, read the H1 line (first `%` comment) of each `.m` file to understand purpose |
| 50 | - Identify file types: `.m` (functions/scripts), data (`.mat`, `.dat`, `.csv`), text (`.txt`), images (`.png`, `.jpg`), other |
| 51 | - Identify any existing subfolders |
| 52 | |
| 53 | ### 2. Determine Project Identity |
| 54 | |
| 55 | Based on the code analysis: |
| 56 | - **Name**: Derive from `Contents.m` title line, folder name, or dominant theme of functions |
| 57 | - **Description**: 1–3 sentence summary covering the scope, domain, and purpose of the code |
| 58 | |
| 59 | ### 3. Create the MATLAB Project |
| 60 | |
| 61 | Use MATLAB MCP (`mcp__matlab__evaluate_matlab_code`) to execute: |
| 62 | |
| 63 | ```matlab |
| 64 | proj = matlab.project.createProject("Folder", '<projectFolder>', ... |
| 65 | "Name", "<inferred name>", ... |
| 66 | "DefinitionType", "FixedPathMultiFile"); |
| 67 | proj.Description = "<generated description>"; |
| 68 | ``` |
| 69 | |
| 70 | **Why FixedPathMultiFile:** Produces a `.prj` + `resources/project/` structure that is SCM-friendly (isolated XML files, no merge conflicts). This is the target format for toolbox projects. |
| 71 | |
| 72 | ### 4. Add All Existing Files |
| 73 | |
| 74 | Add every file in the project folder to the project. Process by extension category: |
| 75 | |
| 76 | ```matlab |
| 77 | % Add .m files |
| 78 | mFiles = dir(fullfile(proj.RootFolder, '*.m')); |
| 79 | for i = 1:numel(mFiles) |
| 80 | addFile(proj, fullfile(mFiles(i).folder, mFiles(i).name)); |
| 81 | end |
| 82 | |
| 83 | % Repeat for data/text/image/other file extensions found |
| 84 | % Also recursively add files from any existing subfolders |
| 85 | ``` |
| 86 | |
| 87 | **Important:** Use `dir(..., '**', '*.<ext>')` for recursive discovery in subfolders. |
| 88 | |
| 89 | ### 5. Configure Project Path |
| 90 | |
| 91 | Add folders to the project path based on layout: |
| 92 | |
| 93 | ```matlab |
| 94 | % Determine path root based on project layout |
| 95 | if isfolder(fullfile(proj.RootFolder, "toolbox")) |
| 96 | % toolbox/ layout — only toolbox content goes on path |
| 97 | % (project root, tests/, buildUtilities/ stay OFF the path) |
| 98 | pathRoot = fullfile(proj.RootFolder, "toolbox"); |
| 99 | else |
| 100 | % Flat layout — all subfolders go on path |
| 101 | pathRoot = proj.RootFolder; |
| 102 | end |
| 103 | |
| 104 | allFolders = strsplit(genpath(pathRoot), pathsep); |
| 105 | for i = 1:numel(allFolders) |
| 106 | if ~isempty(allFolders{i}) && ~contains(allFolders{i}, filesep + "internal") |
| 107 | addPath(proj, allFolders{i}); |
| 108 | end |
| 109 | end |
| 110 | ``` |
| 111 | |
| 112 | **Why this logic:** `genpath` alr |