matlab-define-toolbox-api

$npx mdskill add matlab/matlab-agentic-toolkit/matlab-define-toolbox-api

Scans a folder and generates a toolbox interface spec.

  • Turns loose code into a packaged toolbox.
  • Uses dir, which, exist, and requiredFilesAndProducts.
  • Triage files into include/exclude and identifies public API.
  • Produces a toolboxSpecification.m Interface Spec artifact.

SKILL.md

.github/skills/matlab-define-toolbox-apiView on GitHub ↗
---
name: matlab-define-toolbox-api
description: "Scan a folder, triage files into include/exclude, identify the public API, and produce a toolboxSpecification.m Interface Spec — all in one pass. Use when turning loose code into a toolbox."
license: MathWorks BSD-3-Clause
metadata:
  author: MathWorks
  version: "1.0"
---

# matlab-define-toolbox-api — Toolbox Scope & Spec Generator

You take a folder of code, figure out what belongs in the toolbox, identify the public API, and produce the Interface Spec — the contract defining what the toolbox exposes. One skill, one artifact.

## When to Use

- User wants to turn code into a toolbox
- User points at a folder and says "make this a toolbox" or "package this"
- User has a mix of scripts, functions, tests, data, and scratch files
- Starting the files-to-package pipeline from scratch

## When NOT to Use

- Adding files to an existing spec — edit `buildUtilities/toolboxSpecification.m` directly
- Analyzing dependencies — use `matlab-analyze-dependencies` after the spec is approved
- Building the .mltbx package — use `matlab-build-toolbox`
- Documenting the toolbox — use `matlab-document-toolbox`

## Key Functions

| Function | Purpose |
|----------|---------|
| `dir` | Recursive file listing for inventory |
| `which` | Resolve function locations on path |
| `exist` | Check whether a name resolves to a file, folder, or built-in |
| `matlab.codetools.requiredFilesAndProducts` | Trace caller/callee relationships for Support classification |

## Inputs

| Input | Required | Description |
|-------|----------|-------------|
| **path** | No | Folder or list of files to analyze. If not provided, prompt the user. |
| **purpose** | No | What the toolbox does and who uses it. If not provided, prompt the user. |

## Workflow

### Step 1 — Gather Inputs

If **path** is not provided:
> What folder or files would you like to package as a toolbox?

If **purpose** is not provided:
> In a sentence or two, what does this toolbox do? Who will use it?

Do not proceed until both are provided.

### Step 2 — Inventory the Folder

Scan the path recursively. Classify every file:

| Category | Detection Rule |
|----------|---------------|
| **Function** | `.m` file with `function` keyword on first non-comment line |
| **Class** | `.m` file with `classdef` keyword |
| **Script** | `.m` file with no `function`/`classdef` keyword |
| **Live Script** | `.mlx` file |
| **Test** | In `tests/`/`test/` folder, or name matches `*Test.m`, `*_test.m`, `test_*.m` |
| **Data** | `.mat`, `.csv`, `.xlsx`, `.json`, `.xml` (non-config) |
| **Config/Meta** | `buildfile.m`, `projectStartup.m`, `Contents.m`, `.prj`, `resources/` |
| **Scratch/Temp** | In `scratch/`, `tmp/`, or names like `untitled*.m`, `Copy_of_*` |
| **Other** | READMEs, images, licenses, etc. |

### Step 3 — Classify Relevance

Using the **purpose** as guide, classify each file:

- **Include** — directly serves the toolbox's stated purpose
- **Support** — needed by included files (helper/utility called internally)
- **Exclude** — not relevant (tests, scratch, unrelated code)
- **Uncertain** — needs user input

Heuristics:

| Signal | Disposition |
|--------|-------------|
| Function name aligns with purpose keywords | Include |
| H1 text mentions concepts from purpose | Include |
| Called by an included file | Support |
| In `private/` or `+internal` folder | Support |
| Test file for an included function | Exclude |
| Script with no connection to purpose | Exclude |
| Data file referenced by included code | Include |
| Scratch/temp naming pattern | Exclude |

### Step 4 — Identify Public API

From the **Include** set, determine visibility:

| Signal | Classification |
|--------|---------------|
| Has H1 help text | Likely public |
| Has `arguments` block or input validation | Likely public |
| Descriptive action-oriented name | Likely public |
| Classdef with public methods | Public |
| Called by others but not standalone | Internal |
| In `private/` or generic utility name | Internal |
| Script | Example/entry point |

### Step 5 — Present Report & Get Confirmation

Display a combined scope + API report:

```
## Toolbox Scope & API — [Name]

**Purpose:** [user's stated purpose]
**Source:** [path]
**Total files:** N

### Public API (N functions)
| Function | Signature | H1 | Category |
|----------|-----------|-----|----------|

### Internal Support (N files)
| File | Type | Reason |
|------|------|--------|

### Excluded (N files)
| File | Reason |
|------|--------|

### Uncertain — Need Your Input
| File | Why Uncertain |
|------|--------------|
```

Then ask:
> **Please review:**
> 1. Should any excluded files be included?
> 2. Should any included files be removed?
> 3. For uncertain files — include or exclude?
> 4. Is the public API surface correct?
> 5. What categories should functions be grouped into? (e.g., "Analysis", "I/O", "Visualization")

Incorporate feedback before proceeding.

### Step 6 — Generate Interface Spec

Produce `toolboxSpecification.m` using `scripts/toolboxSpecificationTemplate.m` as the structure. `spec.entries` is a **cell array** (not a struct array) because `classdef` entries have extra fields (`methods`, `properties`) that `function` entries lack — MATLAB cannot concatenate structs with mismatched fields. Access entries via `spec.entries{i}`. Each entry has a `"type"` field — either `"function"` or `"classdef"`. See the template for the full field conventions for both types.

Save to `buildUtilities/toolboxSpecification.m` in the project root (create the folder if needed). This folder is excluded from the toolbox package via `toolbox.ignore` or `package.ignore`.

## Output

- **Single artifact**: `buildUtilities/toolboxSpecification.m` — executable spec as a MATLAB struct
- **Display**: Markdown report shown during the session for review
- **Downstream**: Other skills (`matlab-assess-toolbox`, `matlab-build-toolbox`, `matlab-analyze-dependencies`) consume `toolboxSpecification.m`

## Checkpoint

**This skill always pauses for user approval at Step 5.** The user must confirm scope and public API before the spec is generated. Nothing is written until confirmation.

## Key Rules

- **Always prompt if inputs are missing.** Never guess the path or purpose.
- **Every file is accounted for.** Nothing is silently dropped — files are included, excluded (with reason), or flagged as uncertain.
- **Purpose drives classification.** The user's stated intent is the primary filter.
- **Uncertain is valid.** Surface ambiguity rather than guessing wrong.
- **Reasons are mandatory.** Every include/exclude decision has a stated reason.
- **Tests are excluded but acknowledged.** They're handled by `matlab-assess-toolbox` later.
- **Scripts become examples.** Files without `function` keyword are examples/entry points, not public API.
- **User decides visibility.** Heuristics suggest, user confirms.
- **One artifact, build utilities.** Only `toolboxSpecification.m` is written, to `buildUtilities/` — keeps source clean and is excluded from the packaged toolbox.

## Next Steps

- `/matlab-analyze-dependencies` — resolve external dependencies identified in the Interface Spec
- `/matlab-create-project` — organize files into a MATLAB project using the spec as a guide

----

Copyright 2026 The MathWorks, Inc.

----

More from matlab/matlab-agentic-toolkit

SkillDescription
matlab-access-datafeed>
matlab-add-awgnRead BEFORE writing any code that adds Additive White Gaussian Noise (AWGN) to signals and converts between SNR, Eb/No, Es/No, and per-subcarrier SNR for communications simulations, using awgn(), convertSNR(), berawgn(). The default MATLAB patterns for AWGN (e.g., 'measured' option, manual SNR formulas) produce subtly incorrect results. This skill specifies the correct calling conventions, required function usage, and critical anti-patterns that must be avoided.
matlab-analyze-ams-waveformAnalyze AMS waveform data using Mixed-Signal Blockset utilities: phase noise measurement, clock jitter, anti-aliased resampling, timing measurements, lock time, INL/DNL, ADC/DAC calibration, HSpice import. Use when analyzing time-domain voltage from PLL/VCO/clock simulations, measuring phase noise from variable-step solver output, computing jitter, or resampling non-uniform data.
matlab-analyze-dataAnalyze data using MATLAB. Use when the task involves tables, timetables, time-series data, numeric arrays, sensor matrices, or gridded data — including but not limited to exploring, filtering, sorting, cleaning, transforming, aggregating, smoothing, padding, trimming, and answering questions about data. MATLAB provides extensive, easy-to-use built-in functions for these workflows with no additional products required.
matlab-analyze-dependenciesAnalyze the effective toolbox file set to produce a Dependency Manifest — classify all transitive dependencies as included, product, add-on, or external-unresolved, then present resolution options with tradeoffs. Use after matlab-define-toolbox-api when the spec is approved.
matlab-analyze-emS-parameters, insertion loss, fields, currents, mesh control, and solver selection for RF PCB performance validation. TRIGGER: user asks to compute S-parameters, analyze insertion/return loss, extract fields or currents, compare MoM vs FEM, or control mesh for any RF PCB component. Invoke BEFORE writing sparameters() or solver code — API is non-obvious. SKIP: designing or creating components (use the specific matlab-design-pcb-* skill), material/stackup setup only (use matlab-manage-pcb-material), optimization sweeps (use matlab-optimize-pcb-design), PDN/IR-drop analysis (use matlab-analyze-pcb-pdn).
matlab-analyze-installed-antennaAnalyze antennas installed on electrically large conducting platforms using MATLAB Antenna Toolbox. Loads platform geometry from STL/STEP/IGES, installs antenna elements, selects electromagnetic solvers (MoM-PO, FMM, MoM), and computes patterns, impedance, coupling, and efficiency. Use when the user wants to model an antenna on a vehicle, aircraft, ship, satellite, or other large structure.
matlab-analyze-pcb-pdnPDN DC voltage/current analysis, IR drop, design rule checking, and multi-net batch analysis on imported PCB layouts. TRIGGER: user asks about power integrity, PDN analysis, IR drop, voltage distribution, current density, power nets, or design rule checking on a PCB. Invoke BEFORE writing code — the PDN API chain is specialized and non-obvious. SKIP: importing a PCB file (use matlab-read-pcb-layout), EM field/S-parameter extraction (use matlab-analyze-em), material/stackup setup only (use matlab-manage-pcb-material), transmission line design (use matlab-design-pcb-txline).
matlab-analyze-rcsCalculate and visualize monostatic and bistatic radar cross section (RCS) using MATLAB Antenna Toolbox. Computes RCS of platforms, antennas, and arrays with PO, MoM, and FMM solvers, supporting HH/VV/HV/VH polarization, GPU acceleration, and near-field observation. Use when the user wants to compute, plot, or analyze radar cross section.
matlab-analyze-rf-propagationAnalyze RF propagation and plan wireless sites using MATLAB Antenna Toolbox. Creates transmitter/receiver sites, computes signal strength, coverage maps, SINR, line-of-sight, and ray tracing in geographic or indoor environments. Supports multiple propagation models (free-space, close-in, Longley-Rice, ray tracing, rain/gas/fog), custom terrain, building data, and directional antennas. Use when the user wants to compute coverage, signal strength, path loss, SINR, ray tracing, or plan a wireless network.