# MCP tools

Choose a tool, understand its file effects, and find the current protocol contract.

- ID: tools/mcp
- Type: tool
- Canonical: /reference/tools/mcp
- Version: 2.1.8
- Source revision: 09fc2350ea80ed137ba7ca62c8e5926744b5a5dc (revision)
- Source: packages/mcp/src/server.ts
- Content digest: 507a2938f2d89f976342c00dd826ed996d434964bbd6ce89d64ed03f6c01ad0c
- Semantic digest: 83962260d6d56817dd052d2beebf7999a75804215dac050c47b26353145c099a
- Language: en

Use the [MCP setup guide](/guide/ai-coding#connect-the-mcp-server) to connect a client to your project. Ask the connected server for `tools/list` to read its current input and output schemas. This catalog helps you choose a tool; complete registrations and schemas live in the [server source](https://github.com/master-co/css/blob/rc/packages/mcp/src/server.ts).

The server uses the workspace passed to `--root`. Start with `mastercss_workspace_info` to verify the root and stylesheet entries. A connected server does not by itself establish that the intended project manifest is loaded.

<a id="choose-a-tool"></a>

## Choose a tool

| Question | Tools |
| --- | --- |
| Is this the intended project and setup? | [`workspace_info`](#mastercss_workspace_info), [`setup_audit`](#mastercss_setup_audit) |
| Which definitions are available? | [`manifest_query`](#mastercss_manifest_query), [`inspect_directives`](#mastercss_inspect_directives) |
| What does a class mean, and was it found? | [`inspect_class`](#mastercss_inspect_class), [`extract_classes`](#mastercss_extract_classes), [`trace_class`](#mastercss_trace_class), [`scan_project`](#mastercss_scan_project) |
| What CSS or class syntax should I use? | [`render_css`](#mastercss_render_css), [`suggest_classes`](#mastercss_suggest_classes), [`suggest_syntax`](#mastercss_suggest_syntax) |
| What changed or needs repair? | [`css_compare`](#mastercss_css_compare), [`lint_project`](#mastercss_lint_project), [`lint_content`](#mastercss_lint_content) |
| What does a design-system component require? | [`contract_list`](#mastercss_contract_list), [`contract_get`](#mastercss_contract_get), [`contract_check`](#mastercss_contract_check) |
| How do I review and apply edits? | [`preview_fixes`](#mastercss_preview_fixes), [`preview_directive_format`](#mastercss_preview_directive_format), [`apply_preview`](#mastercss_apply_preview) |

The table abbreviates tool names; every protocol name below starts with `mastercss_`. Request examples show the arguments object passed to `tools/call`, not a complete JSON-RPC envelope.

<a id="preview-lifetime"></a>

## Preview lifetime

**A preview applies only to the file version it recorded**

Both cases start from the same class-order preview. Applying it requires an unexpired token in the same server and matching original files. A changed file is rejected before any proposed file is written.

- A class-order preview records the original p-md flex and proposes flex p-md. Previewing leaves the source file unchanged.
- If every affected file still matches its recorded hash, applying the valid token writes the proposed contents and consumes the token.
- If a file now contains p-md flex gap-sm, its hash no longer matches. Apply rejects the preview before writing any proposed file, preserving the newer content.
- This comparison isolates file identity. Token expiry, server restarts and invalid workspace paths can also prevent application. Sequential writes are not a transactional rollback mechanism.

A preview records the original file identities and proposed contents in one server process. It does not reserve a file or follow subsequent edits. A nonempty file preview returns `confirmToken` and `expiresAt`; unchanged results and in-memory formatting do not. Apply validates token lifetime, workspace containment and every original file before writing. Successful application consumes the token. Writes are sequential, so this is not a transactional rollback guarantee.

Use the [AI coding workflow](/guide/ai-coding#safe-write-previews) to review a concrete change and verify the rendered result. The contract here defines what the tool accepts and writes.

<a id="contracts-of-a-design-system"></a>

## Contracts of a design system

A design system built on Master CSS can describe each component in a contract: its classes and where they go, its states, public properties and smallest correct markup. A library declares its contracts in its own `package.json`:

```json
{
  "name": "your-design-system",
  "masterCSS": {
    "contracts": "./dist/contracts.json",
    "check": "./check/index.js"
  }
}
```

`contracts` is a path inside the package to a JSON file holding `{ "contracts": [...] }`. A contract is an object with a string `name` and a `classes` array; every other field belongs to the library. The optional `check` is a path inside the package to an ES module that exports `check(source, contracts, { knows, strict })` and returns diagnostics with `code`, `severity`, `message`, `line`, `column` and, when they apply, `className` and `contract`. [`@master/ui`](https://ui.master.co) is the first library that ships its contracts this way.

The server reads `dependencies`, `devDependencies` and `peerDependencies` from the `package.json` in the workspace root, resolves each package from that root and keeps those that declare `masterCSS.contracts`. When none does, it reads the same fields of the monorepo root above: the nearest directory whose `package.json` lists `workspaces` or that holds a `pnpm-workspace.yaml`, without leaving the repository. A project adds contracts of its own with globs in the same field of its root `package.json`, such as `"masterCSS": { "contracts": "contracts/*.json" }`. A library in its own repository can also declare `masterCSS.check` there to check those contracts with its own checker. A project with a `master-ui.json` also contributes the JSON files of its `directory` (`ui` by default) and its `contracts` globs. A project contract replaces a library contract of the same `name`. Every contract in a result carries its `source`: the package and version, or the project file and the library contract it replaces.

Only the checker that a declared dependency or the workspace's own `package.json` names is imported, and only from a path that stays inside that package; a project contract file is read as data and never executed. A checker is code from that package. The server runs it in a worker thread and stops it with `CONTRACT_CHECKER_FAILED` when one file takes longer than 10 seconds or the checker exceeds its memory limit. Each check loads the checker again, so an upgraded library takes effect without a restart. The checker receives `knows(className)`, which answers from the project manifest whether a class is a valid Master CSS class or a native class of the project's stylesheets, and `strict: true` only when that manifest loaded. Otherwise `knows` is omitted and `strict` is false. A checker reads markup as written; it does not establish run-time classes or browser behavior.

<a id="mastercss_suggest_classes"></a>

## mastercss_suggest_classes

Suggest classes for an isolated CSS declaration block using the active manifest. Read `remainingCss` and `validation` separately; declaration correspondence does not prove surrounding cascade or browser behavior.

```json
{
  "declarations": "display:flex; padding:16px; gap:1rem;"
}
```

This operation does not write files. Uncertain blocks are preserved in full as native CSS.

<a id="mastercss_workspace_info"></a>

## mastercss_workspace_info

Start here to confirm the server root, package resolution, and discovered CSS entries before interpreting project-dependent results.

```json
{}
```

This operation does not write workspace files.

<a id="mastercss_setup_audit"></a>

## mastercss_setup_audit

Investigate missing packages, undiscovered CSS entries, and integration configuration after checking the workspace root.

```json
{}
```

This operation does not write workspace files.

<a id="mastercss_inspect_class"></a>

## mastercss_inspect_class

Check how one class is interpreted by the active manifest. Use `mastercss_trace_class` when the question is whether project scanning actually finds it.

```json
{
  "className": "p-md"
}
```

This operation does not write workspace files.

<a id="mastercss_trace_class"></a>

## mastercss_trace_class

Trace a class through source discovery, scanner state, and generated CSS to explain why it is present or missing.

```json
{
  "className": "p-md",
  "patterns": [
    "src/button.html"
  ],
  "includeCss": true
}
```

This operation does not write workspace files.

<a id="mastercss_extract_classes"></a>

## mastercss_extract_classes

Find exact class tokens and source positions in a buffer, or inspect extraction across selected project files.

```json
{
  "content": "<button class=\"flex gap-sm p-md\">Save</button>",
  "filePath": "src/button.html",
  "includeRules": true
}
```

This operation does not write workspace files.

<a id="mastercss_inspect_directives"></a>

## mastercss_inspect_directives

Inspect directive structure and compilation effects from an entry stylesheet or a CSS buffer. Provide `entryPath` or `content`; an empty arguments object cannot be compiled.

```json
{
  "content": "@theme { --color-brand: blue;  }",
  "filePath": "app.css"
}
```

This operation does not write workspace files.

<a id="mastercss_render_css"></a>

## mastercss_render_css

Generate CSS for a small literal class list or HTML fragment using the connected project context.

```json
{
  "classList": "flex gap-sm"
}
```

This operation does not write workspace files.

<a id="mastercss_scan_project"></a>

## mastercss_scan_project

Inspect scanned files, stylesheet entries, generated CSS, and optional missing-class checks for a chosen source scope. Add design-system inspection to check token references and policies in managed project CSS.

```json
{
  "patterns": [
    "src/button.html"
  ],
  "classes": [
    "p-md"
  ],
  "includeCss": true
}
```

This operation does not write workspace files.

<a id="mastercss_manifest_query"></a>

## mastercss_manifest_query

Look up tokens, utilities, native mixins, custom media and canonical token families in the active manifest.

```json
{
  "kind": "token",
  "namespace": "color",
  "query": "brand",
  "limit": 10
}
```

This operation does not write workspace files.

<a id="mastercss_css_compare"></a>

## mastercss_css_compare

Supply both project snapshots to compare independent definitions and known consumers, including edits with unchanged markup. Otherwise, compare two class selections using the same active manifest. The result explains generated CSS differences; it does not establish visual equivalence.

```json
{
  "beforeClassList": "p-sm",
  "afterClassList": "p-md"
}
```

This operation does not write workspace files.

<a id="mastercss_lint_project"></a>

## mastercss_lint_project

Run native class diagnostics over selected files. In lint payload v5, `coverage.checkedFiles` lists checked inputs, `summary.checkedFiles` counts them, and `summary.filesWithDiagnostics` counts files with diagnostics. `files` contains diagnostic results only. `coverage.status` is `complete` or `no-inputs`; zero diagnostics with no inputs does not verify source. `coverage.description` explains these fields: manifest stylesheet entries are not linted source inputs. Manifest failures remain MCP error results. Use the project’s ESLint command separately for its parser, plugin settings, and team rules.

```json
{
  "patterns": [
    "src/button.html"
  ],
  "rules": "sort-classes"
}
```

This operation does not write workspace files.

<a id="mastercss_lint_content"></a>

## mastercss_lint_content

Check an unsaved source buffer with the native class diagnostics and the connected workspace’s manifest. Lint payload v5 reports its virtual path in `coverage.checkedFiles` and `summary.checkedFiles: 1`, even when clean. `summary.filesWithDiagnostics` is zero for a clean buffer, and `files` is then empty. Coverage describes this buffer and the enabled lint rules, not browser behavior or the whole project.

```json
{
  "content": "<button class=\"p-md flex\">Save</button>",
  "filePath": "src/button.html",
  "rules": "sort-classes"
}
```

This operation does not write workspace files.

<a id="mastercss_suggest_syntax"></a>

## mastercss_suggest_syntax

Request language-service completion candidates and hover information at a position in an unsaved document.

```json
{
  "content": "<div class=\"(padding:\"></div>",
  "filePath": "src/card.html",
  "position": {
    "line": 0,
    "character": 20
  },
  "limit": 5
}
```

This operation does not write workspace files.

<a id="mastercss_contract_list"></a>

## mastercss_contract_list

Find the component contracts of the design systems this workspace depends on, merged with the project's own. Filter with `query`, `tier` or `category`; every entry names its `source`. An empty list with a `note` means nothing declares contracts, not a failure.

```json
{
  "query": "button"
}
```

This operation does not write workspace files or run package code.

<a id="mastercss_contract_get"></a>

## mastercss_contract_get

Read one full contract before writing that component's markup: its classes and where they go, its states, public properties and smallest correct example. `name` is a contract name or any class a contract defines, so `btn-primary` returns the button contract. An unknown name is an error result that lists the closest contract and class names.

```json
{
  "name": "btn-primary"
}
```

This operation does not write workspace files or run package code.

<a id="mastercss_contract_check"></a>

## mastercss_contract_check

Check an unsaved buffer (`content`, with an optional `filePath` for messages) or project files (`patterns`) against the merged contracts. The diagnostics come from the checker a design-system dependency declares; `checkers` names each one that ran. `classValidation` and `strict` report whether the project manifest told the checker which other classes exist. `coverage.status` is `no-checker` or `no-contracts` when nothing ran, and zero diagnostics then verifies nothing.

```json
{
  "content": "<button class=\"btn-primary\">Save</button>",
  "filePath": "src/button.html"
}
```

This operation does not write workspace files. It runs code from the package that declares the checker, in a worker thread with a time and memory limit.

<a id="mastercss_preview_fixes"></a>

## mastercss_preview_fixes

Prepare a reviewable diff for native lint fixes or generated CSS output. This request does not apply its changes.

```json
{
  "mode": "lint-fixes",
  "patterns": [
    "src/button.html"
  ],
  "rules": "sort-classes"
}
```

Workspace files stay unchanged until `mastercss_apply_preview`. A nonempty preview stores a token in this server process; expiry, restart, or successful application requires a new preview. An unchanged result has no confirmation token.

<a id="mastercss_preview_directive_format"></a>

## mastercss_preview_directive_format

Format directives in a source buffer or create a file-formatting preview. Content mode returns formatted text directly and does not create an apply token.

```json
{
  "content": "@safelist \"(background-color:transparent) !\";",
  "filePath": "card.css"
}
```

Content mode does not write files or store a token. In file mode, workspace files stay unchanged until `mastercss_apply_preview`. A nonempty preview stores a token in this server process; expiry, restart, or successful application requires a new preview. An unchanged result has no confirmation token.

<a id="mastercss_apply_preview"></a>

## mastercss_apply_preview

Apply the exact changes from a reviewed preview in the same running server session. This tool writes workspace files.

```json
{
  "confirmToken": "<token-from-reviewed-preview>"
}
```

The server validates all original file hashes and writable paths before writing the proposed contents. Successful application consumes the token. File writes are sequential; this is not a transactional multi-file rollback mechanism. Run project checks and inspect the changed UI afterward.

<a id="prompts"></a>

## Prompts

Request a prompt through `prompts/get` in a connected client.

| Prompt | Use |
| --- | --- |
| `debug-missing-css` | Inspect scanner coverage, manifest loading, syntax, native CSS pruning and stylesheet entry configuration when classes do not produce CSS. |
| `review-mastercss-classes` | Run class diagnostics and propose only safe, scoped write previews. |
| `migrate-to-mastercss` | Audit an external styling system and plan incremental batches with a rendering mode, validation commands and visual risks; it does not edit files. |

<a id="results"></a>

## Results

Every tool returns a version 3 object with `metadata`, `diagnostics` and a required `result`. Success has `result: { status: 'success', data }`; failure has `result: { status: 'error', error: { code, message } }` and also sets MCP `isError`. JSON text and `structuredContent` contain the same object; validate both branches with the tool's `outputSchema`.

`metadata` reports package, language and binding versions, the context actually used, the manifest fingerprint, entries and dependencies; unavailable values are null or empty arrays. Project context is the default: a missing entry or failed compilation is an error, never a silent switch to the preset. Pass `context: 'preset'` explicitly for preset-only queries.

Class inspection reports `matchStatus`, `cssSyntaxStatus`, `cssValueStatus` and `browserSupport` separately, and each check record names its version, phase and scope. A CSS grammar error differs from an unknown future capability, `var()` does not establish a computed value, and `browserSupport` stays `not-checked` unless a browser check ran. Known CSS math types are checked without computing lengths or converting units; distinct token definitions stay ambiguous even when their values are equal.

Markdown and MDX extraction separates live markup and code from display text and returns original UTF-16 ranges with inclusion or exclusion reasons; the CLI, editor and MCP share the same Rust extraction and matching. CLI report versions are independent of this envelope. In MCP payloads `root` is the configured workspace root; in CLI reports `cwd` is the command root.

Project comparison: call `mastercss_scan_project` with `includeSnapshot: true` before and after editing, then pass both `result.data.snapshot` objects to `mastercss_css_compare` as `beforeSnapshot` and `afterSnapshot`; they cannot be mixed with class, content, `filePath` or `context` inputs. The result is `{ version: 3, mode: 'project', comparison }`, where `comparison.version` is 1 and lists changed definitions, known consumers and files, before/after rules, native references, output assets, delivery order and `coverage`. Native consumers are conservative at stylesheet granularity.

Design-system inspection: `mastercss_scan_project.designSystem` takes the [design-system options](/reference/tools/cli#design-system-options) object and cannot be combined with `context: 'preset'`. The version 1 report in `result.data.designSystem` lists authored `var()` references with source ranges, selector and at-rule ancestry, importers, token-family collisions, component attribute vocabulary (`components`) and policy diagnostics; add `routeStylesheets` globs for stylesheets imported from JavaScript; read `project.routeStylesheets`, `project.excluded` and `coverage`. An unregistered custom property can still resolve through native CSS and is not automatically an error.

<a id="read-the-full-contract"></a>

## Read the full contract

Use `tools/list` in the same connected server session for accepted arguments. On GitHub, read the [tool registrations](https://github.com/master-co/css/blob/rc/packages/mcp/src/server.ts), [output schemas](https://github.com/master-co/css/blob/rc/packages/mcp/src/output-schema.ts), and [result envelope](https://github.com/master-co/css/blob/rc/packages/mcp/src/result.ts). The [workflow guide](/guide/ai-coding#safe-write-previews) shows a complete preview and apply sequence. Source links follow the `rc` branch; the connected server describes your installed version.

## Related reference

- [packages](/reference/packages.md)
- [rules/extraction](/reference/rules/extraction.md)
