astralis-mcp 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +28 -12
- package/package.json +13 -10
- package/server.mjs +314 -84
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `astralis-mcp`. Under 0.x, a minor version may contain
|
|
4
|
+
breaking changes; a patch never does.
|
|
5
|
+
|
|
6
|
+
## 0.4.0 (2026-10-01)
|
|
7
|
+
|
|
8
|
+
Requires Node `^22.18` or `>=24.11`.
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`validate_code`** checks Astralis code an agent wrote against the design
|
|
13
|
+
system and returns machine-readable errors with valid alternatives, so the
|
|
14
|
+
agent can fix its code and check again. It uses the project's installed
|
|
15
|
+
astralis-ui, or the docs site's `system-spec.json` when there is no
|
|
16
|
+
project. Validation runs locally; the server never calls a model.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- When the docs site cannot be reached, tools return an error, never
|
|
21
|
+
"unknown" or an empty success.
|
|
22
|
+
- Responses are capped in size, `search_docs` searches one fetched corpus,
|
|
23
|
+
and the remote spec is refreshed instead of cached forever.
|
|
24
|
+
- Tools are registered with read-only hints.
|
|
25
|
+
|
|
26
|
+
## 0.3.0 (2026-08-08)
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- **`list_blocks`** and **`get_block`**, so an agent asked for a pricing
|
|
31
|
+
section can use the block that exists. `get_block` returns the block's
|
|
32
|
+
source as fenced code, ready to write to disk.
|
|
33
|
+
|
|
34
|
+
## 0.2.0 (2026-07-24)
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- The server reports one version, from its package.
|
|
39
|
+
- Tool descriptions cannot drift from the docs they describe.
|
|
40
|
+
- Fetched pages are cached with a time limit, and requests time out.
|
|
41
|
+
|
|
42
|
+
## 0.1.0 (2026-07-14)
|
|
43
|
+
|
|
44
|
+
The first release: an MCP server over stdio with `list_components`,
|
|
45
|
+
`get_component`, `get_guide`, `get_theming` and `search_docs`, reading the
|
|
46
|
+
live docs site. Set `ASTRALIS_DOCS_URL` to point it at a local docs server.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Paul Andrew
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
# astralis-mcp
|
|
2
2
|
|
|
3
|
-
MCP server for [Astralis UI](https://astralis-
|
|
3
|
+
MCP server for [Astralis UI](https://astralis-ui.com) — lets AI
|
|
4
4
|
coding agents (Claude Code, Cursor, …) look up the library's **current**
|
|
5
|
-
component APIs, full props tables, runnable demo source
|
|
6
|
-
instead of guessing from training data
|
|
5
|
+
component APIs, full props tables, runnable demo source, theming guides and
|
|
6
|
+
block sources instead of guessing from training data, and check the code they
|
|
7
|
+
write against the design system.
|
|
7
8
|
|
|
8
|
-
Reads the docs site's machine-readable endpoints
|
|
9
|
-
from what the documentation actually
|
|
9
|
+
Reads the docs site's machine-readable endpoints and its block registry, so
|
|
10
|
+
answers can never drift from what the documentation actually ships.
|
|
10
11
|
|
|
11
12
|
## Setup
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
The quickest way is `npx astralis-cli connect-mcp`, which configures Claude
|
|
15
|
+
Code, Codex, Cursor, Claude Desktop or Antigravity for you.
|
|
16
|
+
|
|
17
|
+
**Claude Code** by hand:
|
|
14
18
|
|
|
15
19
|
```bash
|
|
16
20
|
claude mcp add astralis -- npx -y astralis-mcp
|
|
21
|
+
# Windows: claude mcp add astralis -- cmd /c npx -y astralis-mcp
|
|
17
22
|
```
|
|
18
23
|
|
|
19
|
-
**Any MCP client**, in its config:
|
|
24
|
+
**Any MCP client**, in its config (on Windows use `"command": "cmd"` and
|
|
25
|
+
`"args": ["/c", "npx", "-y", "astralis-mcp"]`):
|
|
20
26
|
|
|
21
27
|
```json
|
|
22
28
|
{
|
|
@@ -26,23 +32,33 @@ claude mcp add astralis -- npx -y astralis-mcp
|
|
|
26
32
|
}
|
|
27
33
|
```
|
|
28
34
|
|
|
29
|
-
No install step — `npx` fetches and runs it on demand.
|
|
35
|
+
No install step — `npx` fetches and runs it on demand. Needs Node `^22.18` or
|
|
36
|
+
`>=24.11`.
|
|
30
37
|
|
|
31
38
|
## Tools
|
|
32
39
|
|
|
40
|
+
All eight are read-only.
|
|
41
|
+
|
|
33
42
|
| Tool | What it returns |
|
|
34
43
|
| --- | --- |
|
|
35
|
-
| `list_components` | Every docs page
|
|
44
|
+
| `list_components` | Every docs page, components and guides, with slug, title, description, section and kind |
|
|
36
45
|
| `get_component` | One component's full docs: props table, keyboard map, a11y notes, demo source |
|
|
37
|
-
| `get_guide` | A guide page
|
|
38
|
-
| `search_docs` | Full-text search across everything, with
|
|
46
|
+
| `get_guide` | A guide page, such as `installation`, `quick-start`, `theming` or `tokens` |
|
|
47
|
+
| `search_docs` | Full-text search across everything, with a snippet around each hit |
|
|
39
48
|
| `get_theming` | The complete theming + design-token reference in one call |
|
|
49
|
+
| `list_blocks` | Every block — prebuilt page sections — with id, description, category and the components it composes. Filterable by category |
|
|
50
|
+
| `get_block` | One block's metadata plus the complete source of its files, ready to write into a project |
|
|
51
|
+
| `validate_code` | Verdict on Astralis TSX against the design system's machine-readable spec — unknown components/parts, off-token values, dead `astralis:*` classes, anatomy and a11y mistakes, with actionable reasons. Prefers the spec of the astralis-ui installed in your project; no model involved |
|
|
52
|
+
|
|
53
|
+
When the docs site can't be reached, or answers with an error, every tool
|
|
54
|
+
returns an error result that says so — never "unknown component" or an empty
|
|
55
|
+
answer. Responses over 5 MB are refused.
|
|
40
56
|
|
|
41
57
|
## Options
|
|
42
58
|
|
|
43
59
|
| Env var | Default | Purpose |
|
|
44
60
|
| --- | --- | --- |
|
|
45
|
-
| `ASTRALIS_DOCS_URL` | `https://astralis-
|
|
61
|
+
| `ASTRALIS_DOCS_URL` | `https://astralis-ui.com` | Point at a local docs dev server (`http://localhost:3000`) when working on unpublished docs |
|
|
46
62
|
|
|
47
63
|
## License
|
|
48
64
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astralis-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MCP server exposing Astralis UI docs to AI coding agents — current component APIs, props tables, demo sources,
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "MCP server exposing Astralis UI docs to AI coding agents — current component APIs, props tables, demo sources, theming guides, and a validate_code tool that checks generated TSX against the design system's machine-readable spec.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Paul Andrew",
|
|
8
|
-
"homepage": "https://astralis-
|
|
8
|
+
"homepage": "https://astralis-ui.com",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
11
|
+
"url": "git+https://github.com/sekiro-9/astralis-ui.git",
|
|
12
12
|
"directory": "packages/astralis-mcp"
|
|
13
13
|
},
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/
|
|
15
|
+
"url": "https://github.com/sekiro-9/astralis-ui/issues"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [
|
|
18
18
|
"mcp",
|
|
@@ -28,16 +28,19 @@
|
|
|
28
28
|
"astralis-mcp": "server.mjs"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
|
-
"server.mjs"
|
|
31
|
+
"server.mjs",
|
|
32
|
+
"CHANGELOG.md"
|
|
32
33
|
],
|
|
33
34
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
35
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
38
|
-
"zod": "^3.
|
|
38
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
39
|
+
"zod": "^3.25.0",
|
|
40
|
+
"astralis-cli": "^0.5.0"
|
|
39
41
|
},
|
|
40
42
|
"scripts": {
|
|
41
|
-
"start": "node server.mjs"
|
|
43
|
+
"start": "node server.mjs",
|
|
44
|
+
"test": "node --test \"test/*.test.mjs\""
|
|
42
45
|
}
|
|
43
46
|
}
|
package/server.mjs
CHANGED
|
@@ -1,60 +1,104 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* Astralis UI MCP server — gives AI coding agents current component APIs
|
|
4
|
-
* instead of hallucinated ones
|
|
4
|
+
* instead of hallucinated ones, and a validator to judge what they write:
|
|
5
|
+
* retrieval AND verification (validate_code), so an agent can close its own
|
|
6
|
+
* write -> validate -> fix loop against the design system's ground truth.
|
|
5
7
|
*
|
|
6
8
|
* Data source: the deployed docs site's machine-readable endpoints
|
|
7
|
-
* (/llms.txt, /docs/components/*.md, /docs/*.md
|
|
8
|
-
*
|
|
9
|
-
* Point ASTRALIS_DOCS_URL at a
|
|
10
|
-
* when working on unpublished docs.
|
|
9
|
+
* (/llms.txt, /llms-full.txt, /docs/components/*.md, /docs/*.md,
|
|
10
|
+
* /system-spec.json) and its block registry (/r/index.json, /r/{id}.json),
|
|
11
|
+
* the same pipeline that renders the human docs. Point ASTRALIS_DOCS_URL at a
|
|
12
|
+
* local dev server (http://localhost:3000) when working on unpublished docs.
|
|
11
13
|
*
|
|
12
14
|
* Register in an MCP client:
|
|
13
15
|
* { "command": "npx", "args": ["-y", "astralis-mcp"] }
|
|
14
16
|
*/
|
|
15
|
-
import { readFileSync } from "node:fs";
|
|
17
|
+
import { readFileSync, statSync } from "node:fs";
|
|
16
18
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
17
19
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
18
20
|
import { z } from "zod";
|
|
21
|
+
import { prepareSpec, validateSource, findInstalledSpec } from "astralis-cli/validate";
|
|
19
22
|
|
|
20
23
|
/** Single source of truth for the version — the handshake can't drift from what npm publishes. */
|
|
21
24
|
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
|
|
22
25
|
|
|
23
|
-
const SITE = (process.env.ASTRALIS_DOCS_URL ?? "https://astralis-
|
|
26
|
+
const SITE = (process.env.ASTRALIS_DOCS_URL ?? "https://astralis-ui.com").replace(/\/$/, "");
|
|
24
27
|
|
|
25
28
|
/*
|
|
26
|
-
* A localhost docs URL means someone is editing docs live
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
+
* A localhost docs URL means someone is editing docs live, so nothing is
|
|
30
|
+
* cached. A deployed site is cached briefly, so a long-lived server still
|
|
31
|
+
* picks up doc updates without a restart.
|
|
29
32
|
*/
|
|
30
33
|
const isLocal = /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(?::|\/|$)/.test(SITE);
|
|
31
34
|
const TTL_MS = 5 * 60_000;
|
|
32
35
|
const FETCH_TIMEOUT_MS = 10_000;
|
|
36
|
+
/** Remote text goes straight into an agent's context: anything bigger than this is refused. */
|
|
37
|
+
const MAX_RESPONSE_BYTES = 5_000_000;
|
|
33
38
|
|
|
34
39
|
/* ---------- data: fetched on demand, cached with a short TTL ---------- */
|
|
35
40
|
|
|
41
|
+
/** The site answered, but not with the page: `status` tells a missing page (404) from a broken one. */
|
|
42
|
+
class HttpError extends Error {
|
|
43
|
+
constructor(status, url) {
|
|
44
|
+
super(`${status} for ${url}`);
|
|
45
|
+
this.status = status;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class TooLargeError extends Error {}
|
|
50
|
+
|
|
36
51
|
const cache = new Map(); // path -> { text, at }
|
|
37
52
|
|
|
53
|
+
async function readCapped(response, url) {
|
|
54
|
+
const declared = Number(response.headers.get("content-length"));
|
|
55
|
+
if (declared > MAX_RESPONSE_BYTES) {
|
|
56
|
+
await response.body?.cancel();
|
|
57
|
+
throw new TooLargeError(`${url} is larger than ${MAX_RESPONSE_BYTES} bytes`);
|
|
58
|
+
}
|
|
59
|
+
const chunks = [];
|
|
60
|
+
let size = 0;
|
|
61
|
+
for await (const chunk of response.body) {
|
|
62
|
+
size += chunk.byteLength;
|
|
63
|
+
if (size > MAX_RESPONSE_BYTES) throw new TooLargeError(`${url} is larger than ${MAX_RESPONSE_BYTES} bytes`);
|
|
64
|
+
chunks.push(chunk);
|
|
65
|
+
}
|
|
66
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
67
|
+
}
|
|
68
|
+
|
|
38
69
|
async function fetchText(path) {
|
|
39
70
|
const hit = cache.get(path);
|
|
40
71
|
if (hit && !isLocal && Date.now() - hit.at < TTL_MS) return hit.text;
|
|
41
72
|
|
|
42
|
-
const
|
|
43
|
-
const
|
|
73
|
+
const url = `${SITE}${path}`;
|
|
74
|
+
const signal = AbortSignal.timeout(FETCH_TIMEOUT_MS);
|
|
44
75
|
try {
|
|
45
|
-
const res = await fetch(
|
|
46
|
-
if (!res.ok)
|
|
47
|
-
|
|
76
|
+
const res = await fetch(url, { signal });
|
|
77
|
+
if (!res.ok) {
|
|
78
|
+
await res.body?.cancel();
|
|
79
|
+
throw new HttpError(res.status, url);
|
|
80
|
+
}
|
|
81
|
+
const text = await readCapped(res, url);
|
|
48
82
|
cache.set(path, { text, at: Date.now() });
|
|
49
83
|
return text;
|
|
50
84
|
} catch (err) {
|
|
51
|
-
if (
|
|
85
|
+
if (signal.aborted) throw new Error(`timed out after ${FETCH_TIMEOUT_MS}ms for ${url}`);
|
|
52
86
|
throw err;
|
|
53
|
-
} finally {
|
|
54
|
-
clearTimeout(timer);
|
|
55
87
|
}
|
|
56
88
|
}
|
|
57
89
|
|
|
90
|
+
/** A page's text, or null when the site says it doesn't exist. Any other failure throws. */
|
|
91
|
+
async function fetchOptional(path) {
|
|
92
|
+
try {
|
|
93
|
+
return await fetchText(path);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (err instanceof HttpError && err.status === 404) return null;
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const SLUG = /^[a-z0-9-]+$/;
|
|
101
|
+
|
|
58
102
|
/** Parse llms.txt into [{slug, title, description, section, kind}]. */
|
|
59
103
|
async function listPages() {
|
|
60
104
|
const index = await fetchText("/llms.txt");
|
|
@@ -76,106 +120,292 @@ async function listPages() {
|
|
|
76
120
|
return pages;
|
|
77
121
|
}
|
|
78
122
|
|
|
123
|
+
/**
|
|
124
|
+
* llms-full.txt split back into pages. Each page opens with a marker
|
|
125
|
+
* `<!-- Section / Title — /docs/[components/]slug -->` (astralis-docs
|
|
126
|
+
* src/app/llms-full.txt/route.ts).
|
|
127
|
+
*/
|
|
128
|
+
async function corpusPages() {
|
|
129
|
+
const corpus = await fetchText("/llms-full.txt");
|
|
130
|
+
const marker = /^<!-- .+ — \/docs\/(?:(components)\/)?([a-z0-9-]+) -->$/gm;
|
|
131
|
+
const found = [...corpus.matchAll(marker)];
|
|
132
|
+
return found.map((m, i) => ({
|
|
133
|
+
slug: m[2],
|
|
134
|
+
kind: m[1] ? "component" : "guide",
|
|
135
|
+
body: corpus.slice(m.index + m[0].length, found[i + 1]?.index ?? corpus.length),
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
|
|
79
139
|
async function pageMarkdown(slug, kind) {
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
140
|
+
if (!SLUG.test(slug)) return null;
|
|
141
|
+
return fetchOptional(kind === "guide" ? `/docs/${slug}.md` : `/docs/components/${slug}.md`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function fetchJson(path) {
|
|
145
|
+
return JSON.parse(await fetchText(path));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function blockCatalogue() {
|
|
149
|
+
return (await fetchJson("/r/index.json")).blocks;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** One registry item, source included. Null when the id is unknown. */
|
|
153
|
+
async function blockItem(id) {
|
|
154
|
+
if (!SLUG.test(id)) return null;
|
|
155
|
+
const text = await fetchOptional(`/r/${id}.json`);
|
|
156
|
+
return text === null ? null : JSON.parse(text);
|
|
86
157
|
}
|
|
87
158
|
|
|
88
159
|
const asText = (text) => ({ content: [{ type: "text", text }] });
|
|
89
160
|
const asError = (text) => ({ content: [{ type: "text", text }], isError: true });
|
|
161
|
+
/** A fetch that failed, as an error result: never mistaken for "unknown" or an empty answer. */
|
|
90
162
|
const offline = (err) =>
|
|
91
|
-
|
|
163
|
+
err instanceof HttpError
|
|
164
|
+
? asError(`The Astralis docs at ${SITE} answered ${err.message}. Try again later, or set ASTRALIS_DOCS_URL.`)
|
|
165
|
+
: err instanceof TooLargeError
|
|
166
|
+
? asError(`Refused a response from the Astralis docs: ${err.message}.`)
|
|
167
|
+
: asError(`Could not reach the Astralis docs at ${SITE} (${err.message}). Check your connection, or set ASTRALIS_DOCS_URL.`);
|
|
92
168
|
|
|
93
169
|
/* ---------- server ---------- */
|
|
94
170
|
|
|
95
171
|
const server = new McpServer({ name: "astralis-ui", version: pkg.version });
|
|
96
172
|
|
|
97
|
-
|
|
173
|
+
/** Every tool only reads; the docs ones read from the web. A failed fetch is always an error result. */
|
|
174
|
+
function tool(name, { title, description, inputSchema = {} }, handler) {
|
|
175
|
+
server.registerTool(
|
|
176
|
+
name,
|
|
177
|
+
{
|
|
178
|
+
title,
|
|
179
|
+
description,
|
|
180
|
+
inputSchema,
|
|
181
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
|
|
182
|
+
},
|
|
183
|
+
async (args) => {
|
|
184
|
+
try {
|
|
185
|
+
return await handler(args);
|
|
186
|
+
} catch (err) {
|
|
187
|
+
return offline(err);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
tool(
|
|
98
194
|
"list_components",
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return asText(JSON.stringify(await listPages(), null, 2));
|
|
104
|
-
} catch (err) {
|
|
105
|
-
return offline(err);
|
|
106
|
-
}
|
|
195
|
+
{
|
|
196
|
+
title: "List docs pages",
|
|
197
|
+
description:
|
|
198
|
+
"List every Astralis UI docs page — all components plus every guide — each with slug, title, one-line description, section, and kind (component | guide). Call this first to discover valid slugs.",
|
|
107
199
|
},
|
|
200
|
+
async () => asText(JSON.stringify(await listPages(), null, 2)),
|
|
108
201
|
);
|
|
109
202
|
|
|
110
|
-
|
|
203
|
+
tool(
|
|
111
204
|
"get_component",
|
|
112
|
-
|
|
113
|
-
|
|
205
|
+
{
|
|
206
|
+
title: "Get component docs",
|
|
207
|
+
description:
|
|
208
|
+
"Full documentation for one component as markdown: usage, complete props table, keyboard/accessibility notes, and runnable demo source code. Use the slug from list_components.",
|
|
209
|
+
inputSchema: { slug: z.string().describe("Component docs slug, e.g. 'button', 'number-input'") },
|
|
210
|
+
},
|
|
114
211
|
async ({ slug }) => {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return md
|
|
118
|
-
? asText(md)
|
|
119
|
-
: asError(`Unknown component "${slug}". Call list_components for valid slugs.`);
|
|
120
|
-
} catch (err) {
|
|
121
|
-
return offline(err);
|
|
122
|
-
}
|
|
212
|
+
const md = await pageMarkdown(slug, "component");
|
|
213
|
+
return md ? asText(md) : asError(`Unknown component "${slug}". Call list_components for valid slugs.`);
|
|
123
214
|
},
|
|
124
215
|
);
|
|
125
216
|
|
|
126
|
-
|
|
217
|
+
tool(
|
|
127
218
|
"get_guide",
|
|
128
|
-
|
|
129
|
-
|
|
219
|
+
{
|
|
220
|
+
title: "Get a guide",
|
|
221
|
+
description:
|
|
222
|
+
"One Astralis guide page as markdown — e.g. installation, theming, tokens. Use a guide slug from list_components for the full set.",
|
|
223
|
+
inputSchema: { slug: z.string().describe("Guide slug, e.g. 'installation', 'theming', 'tokens'") },
|
|
224
|
+
},
|
|
130
225
|
async ({ slug }) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return asError(`Unknown guide "${slug}". Valid guides: ${guides.join(", ")}.`);
|
|
136
|
-
} catch (err) {
|
|
137
|
-
return offline(err);
|
|
138
|
-
}
|
|
226
|
+
const md = await pageMarkdown(slug, "guide");
|
|
227
|
+
if (md) return asText(md);
|
|
228
|
+
const guides = (await listPages()).filter((p) => p.kind === "guide").map((p) => p.slug);
|
|
229
|
+
return asError(`Unknown guide "${slug}". Valid guides: ${guides.join(", ")}.`);
|
|
139
230
|
},
|
|
140
231
|
);
|
|
141
232
|
|
|
142
|
-
|
|
233
|
+
tool(
|
|
143
234
|
"search_docs",
|
|
144
|
-
|
|
145
|
-
|
|
235
|
+
{
|
|
236
|
+
title: "Search the docs",
|
|
237
|
+
description:
|
|
238
|
+
"Full-text search across all Astralis documentation (guides + components). Returns matching pages with a snippet around the first hit.",
|
|
239
|
+
inputSchema: { query: z.string().describe("Search text, e.g. 'focus trap' or 'aria-describedby'") },
|
|
240
|
+
},
|
|
146
241
|
async ({ query }) => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
} catch (err) {
|
|
158
|
-
return offline(err);
|
|
242
|
+
const q = query.toLowerCase();
|
|
243
|
+
const [pages, index] = await Promise.all([corpusPages(), listPages()]);
|
|
244
|
+
const meta = new Map(index.map((p) => [`${p.kind}:${p.slug}`, p]));
|
|
245
|
+
const hits = [];
|
|
246
|
+
for (const page of pages) {
|
|
247
|
+
const idx = page.body.toLowerCase().indexOf(q);
|
|
248
|
+
if (idx === -1) continue;
|
|
249
|
+
const { title = page.slug, description = "", section = "" } = meta.get(`${page.kind}:${page.slug}`) ?? {};
|
|
250
|
+
const snippet = page.body.slice(Math.max(0, idx - 80), idx + 120).replace(/\s+/g, " ").trim();
|
|
251
|
+
hits.push({ slug: page.slug, title, description, section, kind: page.kind, snippet });
|
|
159
252
|
}
|
|
253
|
+
return asText(hits.length ? JSON.stringify(hits, null, 2) : "No matches.");
|
|
160
254
|
},
|
|
161
255
|
);
|
|
162
256
|
|
|
163
|
-
|
|
257
|
+
tool(
|
|
164
258
|
"get_theming",
|
|
165
|
-
|
|
166
|
-
|
|
259
|
+
{
|
|
260
|
+
title: "Get the theming reference",
|
|
261
|
+
description:
|
|
262
|
+
"The complete Astralis theming reference: the token system, dark mode, runtime brand color, colorScheme/accent channel, plus every design-token scale (spacing, sizing, type, radius, shadows, motion).",
|
|
263
|
+
},
|
|
167
264
|
async () => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
265
|
+
const [theming, tokens] = await Promise.all([pageMarkdown("theming", "guide"), pageMarkdown("tokens", "guide")]);
|
|
266
|
+
const missing = [!theming && "theming", !tokens && "tokens"].filter(Boolean);
|
|
267
|
+
if (missing.length) return asError(`The docs site has no ${missing.join(" or ")} page, so the reference is incomplete.`);
|
|
268
|
+
return asText([theming, "\n---\n", tokens].join("\n"));
|
|
269
|
+
},
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
/* ---------- blocks ---------- */
|
|
273
|
+
|
|
274
|
+
tool(
|
|
275
|
+
"list_blocks",
|
|
276
|
+
{
|
|
277
|
+
title: "List blocks",
|
|
278
|
+
description:
|
|
279
|
+
"List every Astralis block — prebuilt page sections (hero, pricing, dashboard, login…) composed from Astralis UI components. Each entry has id, name, description, category and the components it composes. Call this first to discover valid block ids. Pass a category to narrow the list.",
|
|
280
|
+
inputSchema: {
|
|
281
|
+
category: z.string().optional().describe("Optional filter, e.g. 'hero', 'pricing', 'dashboard', 'login'"),
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
async ({ category }) => {
|
|
285
|
+
const blocks = await blockCatalogue();
|
|
286
|
+
if (!category) return asText(JSON.stringify(blocks, null, 2));
|
|
287
|
+
|
|
288
|
+
const filtered = blocks.filter((b) => b.category === category.toLowerCase());
|
|
289
|
+
if (filtered.length) return asText(JSON.stringify(filtered, null, 2));
|
|
290
|
+
|
|
291
|
+
const categories = [...new Set(blocks.map((b) => b.category))].sort();
|
|
292
|
+
return asError(`No blocks in category "${category}". Categories: ${categories.join(", ")}.`);
|
|
293
|
+
},
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
tool(
|
|
297
|
+
"get_block",
|
|
298
|
+
{
|
|
299
|
+
title: "Get a block's source",
|
|
300
|
+
description:
|
|
301
|
+
"One Astralis block: its metadata plus the complete source of every file it contains, ready to write into a project. A block depends only on astralis-ui — no other packages, no Tailwind config, no per-block setup. Use an id from list_blocks.",
|
|
302
|
+
inputSchema: { id: z.string().describe("Block id, e.g. 'hero-01', 'pricing-02', 'dashboard-03'") },
|
|
303
|
+
},
|
|
304
|
+
async ({ id }) => {
|
|
305
|
+
const block = await blockItem(id);
|
|
306
|
+
if (!block) {
|
|
307
|
+
const ids = (await blockCatalogue()).map((b) => b.id);
|
|
308
|
+
return asError(`Unknown block "${id}". Valid ids: ${ids.join(", ")}.`);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Markdown, not JSON: the payload is mostly source, and fenced blocks
|
|
312
|
+
// spare the agent unescaping a JSON string before writing the file.
|
|
313
|
+
const sections = [
|
|
314
|
+
`# ${block.name}`,
|
|
315
|
+
"",
|
|
316
|
+
block.description,
|
|
317
|
+
"",
|
|
318
|
+
`- **id** \`${block.id}\` · **category** \`${block.category}\``,
|
|
319
|
+
`- **exports** \`${block.component}\``,
|
|
320
|
+
`- **composes** ${block.uses.map((u) => `\`${u}\``).join(", ")}`,
|
|
321
|
+
`- **preview** ${SITE}/blocks/${block.id}`,
|
|
322
|
+
"",
|
|
323
|
+
`Install with \`npx astralis-cli add ${block.id}\`, or write the files below yourself —`,
|
|
324
|
+
`they belong to the project once copied. The only dependency is \`astralis-ui\`.`,
|
|
325
|
+
"",
|
|
326
|
+
];
|
|
327
|
+
for (const file of block.contents) {
|
|
328
|
+
const lang = file.path.endsWith(".tsx") || file.path.endsWith(".ts") ? "tsx" : "";
|
|
329
|
+
sections.push(`## ${file.path}`, "", `\`\`\`${lang}`, file.content.trimEnd(), "```", "");
|
|
330
|
+
}
|
|
331
|
+
return asText(sections.join("\n"));
|
|
332
|
+
},
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
/* ---------- validation ---------- */
|
|
336
|
+
|
|
337
|
+
/*
|
|
338
|
+
* The judge half of verified generation: pure local computation, no model.
|
|
339
|
+
* The spec comes from the project's own installed astralis-ui (the version
|
|
340
|
+
* the code must conform to); with none nearby (a desktop client spawned at
|
|
341
|
+
* $HOME) it falls back to the spec of the version the docs site documents.
|
|
342
|
+
*/
|
|
343
|
+
let specState = null; // { key, prepared, version, source }
|
|
344
|
+
|
|
345
|
+
async function resolveSpec() {
|
|
346
|
+
const localPath = findInstalledSpec(process.cwd());
|
|
347
|
+
if (localPath) {
|
|
348
|
+
const key = `${localPath}@${statSync(localPath).mtimeMs}`;
|
|
349
|
+
if (specState?.key !== key) {
|
|
350
|
+
const spec = JSON.parse(readFileSync(localPath, "utf8"));
|
|
351
|
+
specState = { key, prepared: prepareSpec(spec), version: spec.version, source: "installed astralis-ui" };
|
|
176
352
|
}
|
|
353
|
+
return specState;
|
|
354
|
+
}
|
|
355
|
+
// fetchText's TTL decides freshness; re-prepare only when the text changed.
|
|
356
|
+
const text = await fetchText("/system-spec.json");
|
|
357
|
+
if (specState?.key !== text) {
|
|
358
|
+
const spec = JSON.parse(text);
|
|
359
|
+
specState = {
|
|
360
|
+
key: text,
|
|
361
|
+
prepared: prepareSpec(spec),
|
|
362
|
+
version: spec.version,
|
|
363
|
+
source: `docs site (${SITE}) — no local astralis-ui found, validated against the latest published version`,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
return specState;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
tool(
|
|
370
|
+
"validate_code",
|
|
371
|
+
{
|
|
372
|
+
title: "Validate Astralis code",
|
|
373
|
+
description:
|
|
374
|
+
"Validate Astralis UI TSX/JSX against the design system's machine-readable spec. Catches what typechecking cannot: components and compound parts that don't exist, prop values outside their token sets, astralis:* classes missing from the compiled CSS (they render as nothing), undeclared token variables, illegal breakpoint/state keys, broken compound anatomy, Tabs trigger/panel mismatches, and a11y mistakes (typo'd aria-* attributes, invalid roles, missing alt). ALWAYS run this on Astralis code you generate or edit BEFORE presenting it; fix every error, then validate again until clean. Errors include the valid alternatives, so they are directly actionable.",
|
|
375
|
+
inputSchema: {
|
|
376
|
+
code: z
|
|
377
|
+
.string()
|
|
378
|
+
.describe("The complete TSX/JSX source to validate (a whole file or a self-contained snippet with its astralis-ui imports)"),
|
|
379
|
+
strict_tokens: z
|
|
380
|
+
.boolean()
|
|
381
|
+
.optional()
|
|
382
|
+
.describe("Also warn on valid-but-off-token colors (design-system drift check). Default false."),
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
async ({ code, strict_tokens }) => {
|
|
386
|
+
const spec = await resolveSpec();
|
|
387
|
+
const { errors, warnings } = validateSource(code, spec.prepared, "<code>", { strictTokens: strict_tokens ?? false });
|
|
388
|
+
const valid = errors.length === 0;
|
|
389
|
+
return {
|
|
390
|
+
content: [{
|
|
391
|
+
type: "text",
|
|
392
|
+
text: JSON.stringify(
|
|
393
|
+
{
|
|
394
|
+
valid,
|
|
395
|
+
spec: { version: spec.version, source: spec.source },
|
|
396
|
+
summary: valid
|
|
397
|
+
? `valid against astralis-ui@${spec.version}${warnings.length ? ` (${warnings.length} warning(s))` : ""}`
|
|
398
|
+
: `${errors.length} error(s), ${warnings.length} warning(s) — fix the errors and validate again`,
|
|
399
|
+
errors,
|
|
400
|
+
warnings,
|
|
401
|
+
},
|
|
402
|
+
null,
|
|
403
|
+
2,
|
|
404
|
+
),
|
|
405
|
+
}],
|
|
406
|
+
isError: false,
|
|
407
|
+
};
|
|
177
408
|
},
|
|
178
409
|
);
|
|
179
410
|
|
|
180
|
-
|
|
181
|
-
await server.connect(transport);
|
|
411
|
+
await server.connect(new StdioServerTransport());
|